I have some unit tests running through Ant, and I would like to be able to run some cleanup code if unit tests fail. I was looking for some kind of "final" block, but I was not lucky to find it. I tried using the errorproperty and if property for tasks, but ant only accepts true values, "on" and "yes" as true properties. A successfully completed task (at least for unix) returns 0, so I had to build an absurdly complex device:
<project name="TestBuild" default="build" basedir=".">
<target name="build" depends="truth,checkresult,cleanup" />
<target name="truth">
<echo message="Running Truth" />
<exec executable="false" errorproperty="testfailure"/>
</target>
<target name="checkresult">
<condition property="testfailed">
<not>
<equals arg1="${testfailure}" arg2="0" />
</not>
</condition>
</target>
<target name="cleanup" if="testfailed">
<echo message="cleanup" />
<fail />
</target>
? -, , . , , , , failonerror, . , , , , - .