Author: bodewig Date: Fri Oct 9 03:56:28 2009 New Revision: 823395 URL: http://svn.apache.org/viewvc?rev=823395&view=rev Log: Make if/unless und junit test children use the same logic as target's if/unless
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java ant/core/trunk/src/tests/antunit/taskdefs/optional/junit/junit-test.xml Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java?rev=823395&r1=823394&r2=823395&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java Fri Oct 9 03:56:28 2009 @@ -41,6 +41,8 @@ protected String errorProperty; // CheckStyle:VisibilityModifier ON + private Object ifCond, unlessCond; + /** * Set the filtertrace attribute. * @param value a <code>boolean</code> value. @@ -107,22 +109,63 @@ /** * Set the if attribute. - * If this property is present in project, - * the test will be run. - * @param propertyName the name of the property to look for. + * If this expression evaluates to true or the name of a property + * which is present in project, the test will be run. + * @param ifCondition the expression to evaluate + * @since Ant 1.8.0 + */ + public void setIf(Object ifCondition) { + ifCond = ifCondition; + ifProperty = ifCondition != null ? String.valueOf(ifCondition) : null; + } + + /** + * Set the if attribute. + * If this expression evaluates to true or the name of a property + * which is present in project, the test will be run. + * @param propertyName the expression to evaluate */ public void setIf(String propertyName) { - ifProperty = propertyName; + setIf((Object) propertyName); + } + + /** + * The if expression + * @since Ant 1.8.0 + */ + public Object getIfCondition() { + return ifCond; } /** - * Set the unless attribute. - * If this property is present in project, - * the test will *not* be run. - * @param propertyName the name of the property to look for. + * Set the unless attribute. If this expression evaluates to + * false or the name of a property which is not present in + * project, the test will be run. + * @param unlessCondition the expression to evaluate + * @since Ant 1.8.0 + */ + public void setUnless(Object unlessCondition) { + unlessCond = unlessCondition; + unlessProperty = unlessCondition != null + ? String.valueOf(unlessCondition) : null; + } + + /** + * Set the unless attribute. If this expression evaluates to + * false or the name of a property which is not present in + * project, the test will be run. + * @param propertyName the expression to evaluate */ public void setUnless(String propertyName) { - unlessProperty = propertyName; + setUnless((Object) propertyName); + } + + /** + * The unless expression + * @since Ant 1.8.0 + */ + public Object getUnlessCondition() { + return unlessCond; } /** Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java?rev=823395&r1=823394&r2=823395&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java Fri Oct 9 03:56:28 2009 @@ -188,8 +188,8 @@ test.setHaltonfailure(this.haltOnFail); test.setFiltertrace(this.filtertrace); test.setFork(this.fork); - test.setIf(this.ifProperty); - test.setUnless(this.unlessProperty); + test.setIf(getIfCondition()); + test.setUnless(getUnlessCondition()); test.setTodir(this.destDir); test.setFailureProperty(failureProperty); test.setErrorProperty(errorProperty); Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java?rev=823395&r1=823394&r2=823395&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java Fri Oct 9 03:56:28 2009 @@ -23,6 +23,7 @@ import java.util.Properties; import java.util.Vector; import org.apache.tools.ant.Project; +import org.apache.tools.ant.PropertyHelper; /** * <p> Run a single JUnit test. @@ -193,14 +194,9 @@ * @return true if this test or testsuite should be run. */ public boolean shouldRun(Project p) { - if (ifProperty != null && p.getProperty(ifProperty) == null) { - return false; - } else if (unlessProperty != null - && p.getProperty(unlessProperty) != null) { - return false; - } - - return true; + PropertyHelper ph = PropertyHelper.getPropertyHelper(p); + return ph.testIfCondition(getIfCondition()) + && ph.testUnlessCondition(getUnlessCondition()); } /** Modified: ant/core/trunk/src/tests/antunit/taskdefs/optional/junit/junit-test.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/optional/junit/junit-test.xml?rev=823395&r1=823394&r2=823395&view=diff ============================================================================== --- ant/core/trunk/src/tests/antunit/taskdefs/optional/junit/junit-test.xml (original) +++ ant/core/trunk/src/tests/antunit/taskdefs/optional/junit/junit-test.xml Fri Oct 9 03:56:28 2009 @@ -36,6 +36,11 @@ </sequential> </macrodef> + <target name="setUp"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + </target> + <target name="testTimeoutLogOfBatchTests"> <mkdir dir="${input}"/> <mkdir dir="${output}"/> @@ -187,4 +192,101 @@ <au:assertFileExists file="${output}/TEST-test.BTest.xml"/> </target> + <target name="-ifUnlessSetup" depends="setUp"> + <empty-test classname="ATest"/> + <empty-test classname="BTest"/> + <empty-test classname="CTest"/> + <empty-test classname="DTest"/> + <empty-test classname="ETest"/> + <empty-test classname="FTest"/> + <empty-test classname="GTest"/> + <empty-test classname="HTest"/> + <javac srcdir="${input}" destdir="${output}"> + <classpath refid="junit"/> + </javac> + <macrodef name="j"> + <sequential> + <junit fork="true" forkMode="perBatch" printsummary="yes"> + <classpath refid="junit"/> + <classpath location="${output}"/> + <test name="test.ATest" if="${if}"/> + <test name="test.BTest" if="if"/> + <test name="test.CTest" unless="${if}"/> + <test name="test.DTest" unless="if"/> + <batchtest if="${if}"> + <fileset dir="${output}"> + <include name="**/ETest.class" /> + </fileset> + </batchtest> + <batchtest if="if"> + <fileset dir="${output}"> + <include name="**/FTest.class" /> + </fileset> + </batchtest> + <batchtest unless="${if}"> + <fileset dir="${output}"> + <include name="**/GTest.class" /> + </fileset> + </batchtest> + <batchtest unless="if"> + <fileset dir="${output}"> + <include name="**/HTest.class" /> + </fileset> + </batchtest> + </junit> + </sequential> + </macrodef> + </target> + + <target name="testPropertiesNotSet" depends="-ifUnlessSetup"> + <j/> + <au:assertLogDoesntContain text="Running test.ATest"/> + <au:assertLogDoesntContain text="Running test.BTest"/> + <au:assertLogContains text="Running test.CTest"/> + <au:assertLogContains text="Running test.DTest"/> + <au:assertLogDoesntContain text="Running test.ETest"/> + <au:assertLogDoesntContain text="Running test.FTest"/> + <au:assertLogContains text="Running test.GTest"/> + <au:assertLogContains text="Running test.HTest"/> + </target> + + <target name="testPropertiesSet" depends="-ifUnlessSetup"> + <property name="if" value="whatever"/> + <j/> + <au:assertLogDoesntContain text="Running test.ATest"/> + <au:assertLogContains text="Running test.BTest"/> + <au:assertLogContains text="Running test.CTest"/> + <au:assertLogDoesntContain text="Running test.DTest"/> + <au:assertLogDoesntContain text="Running test.ETest"/> + <au:assertLogContains text="Running test.FTest"/> + <au:assertLogContains text="Running test.GTest"/> + <au:assertLogDoesntContain text="Running test.HTest"/> + </target> + + <target name="testPropertiesTrue" depends="-ifUnlessSetup"> + <property name="if" value="true"/> + <j/> + <au:assertLogContains text="Running test.ATest"/> + <au:assertLogContains text="Running test.BTest"/> + <au:assertLogDoesntContain text="Running test.CTest"/> + <au:assertLogDoesntContain text="Running test.DTest"/> + <au:assertLogContains text="Running test.ETest"/> + <au:assertLogContains text="Running test.FTest"/> + <au:assertLogDoesntContain text="Running test.GTest"/> + <au:assertLogDoesntContain text="Running test.HTest"/> + </target> + + <target name="testPropertiesFalse" depends="-ifUnlessSetup"> + <property name="if" value="false"/> + <j/> + <au:assertLogDoesntContain text="Running test.ATest"/> + <au:assertLogContains text="Running test.BTest"/> + <au:assertLogContains text="Running test.CTest"/> + <au:assertLogDoesntContain text="Running test.DTest"/> + <au:assertLogDoesntContain text="Running test.ETest"/> + <au:assertLogContains text="Running test.FTest"/> + <au:assertLogContains text="Running test.GTest"/> + <au:assertLogDoesntContain text="Running test.HTest"/> + </target> + </project>