How can I have my ant task pass or fail based on the results of a jar it runs?

被刻印的时光 ゝ 提交于 2019-12-12 16:18:44

问题


I'm running CrossCheck (browserless js unit testing) as part of an ant script. I'd like ant to report failure if the CrossCheck tests fail. Here's the relevant bit from the build.xml

<target name="test" depends="concat">
    <java jar="src/test/lib/crosscheck.jar" fork="true">
        <arg value="src/test/webapp/js/"/>
    </java>

And an example of CrossCheck's failure messaging:

 [java] Running tests in environment: Mozilla 1.7 (Firefox 1.0)
 [java] org.mozilla.javascript.EcmaError: ReferenceError: "clusterNode" is not defined. (ResultXMLWrapperTest.js#22)
 [java]     at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3229)
 [java]     at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3219)
 [java]     at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3292)
 [java]     at org.mozilla.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:1636)
 [java]     at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1575)
 [java]     at org.mozilla.javascript.gen.c1._c1(ResultXMLWrapperTest.js:22)
 [java]     at org.mozilla.javascript.gen.c1.call(ResultXMLWrapperTest.js)
 [java]     at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:340)
 [java]     at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2758)
 [java]     at org.mozilla.javascript.gen.c1.call(ResultXMLWrapperTest.js)
 [java]     at net.thefrontside.crosscheck.framework.AbstractScopeFactory$1.run(AbstractScopeFactory.java:108)
 [java]     at org.mozilla.javascript.Context.call(Context.java:515)
 [java]     at org.mozilla.javascript.Context.call(Context.java:450)
 [java]     at net.thefrontside.crosscheck.framework.AbstractScopeFactory.initTestScope(AbstractScopeFactory.java:94)
 [java]     at net.thefrontside.crosscheck.framework.DefaultScopeFactory.getTestScope(DefaultScopeFactory.java:68)
 [java]     at net.thefrontside.crosscheck.framework.TestCase$1.run(TestCase.java:119)
 [java]     at org.mozilla.javascript.Context.call(Context.java:528)
 [java]     at org.mozilla.javascript.Context.call(Context.java:450)
 [java]     at net.thefrontside.crosscheck.framework.TestCase.run(TestCase.java:117)
 [java]     at net.thefrontside.crosscheck.framework.TestSuite.run(TestSuite.java:95)
 [java]     at net.thefrontside.crosscheck.framework.Crosscheck.runAll(Crosscheck.java:116)
 [java]     at net.thefrontside.crosscheck.framework.ConsoleRunner.run(ConsoleRunner.java:140)
 [java]     at net.thefrontside.crosscheck.framework.ConsoleRunner.main(ConsoleRunner.java:300)
 [java] ReferenceError: "clusterNode" is not defined. (ResultXMLWrapperTest.js#22)
 [java] Java Result: 1

Can ant get at the results of the CrossCheck test (perhaps Java Result: 1 gets passed back to ant?) and succeed or fail based on that?


回答1:


Assuming that CrossCheck returns a non-zero return code on a error you could add the failonerror attribute to the java task:

<target name="test" depends="concat">
    <java jar="src/test/lib/crosscheck.jar" fork="true" failonerror="true">
        <arg value="src/test/webapp/js/"/>
    </java>

See the documentation on the Ant java task.




回答2:


You can use the 'failonerror' attribute of the 'java' task.

failonerror Stop the buildprocess if the command exits with a returncode other than 0. Default is "false" (see note)

Check the Ant manual here.



来源:https://stackoverflow.com/questions/907364/how-can-i-have-my-ant-task-pass-or-fail-based-on-the-results-of-a-jar-it-runs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!