git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@823395 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -41,6 +41,8 @@ public abstract class BaseTest { | |||||
| protected String errorProperty; | protected String errorProperty; | ||||
| // CheckStyle:VisibilityModifier ON | // CheckStyle:VisibilityModifier ON | ||||
| private Object ifCond, unlessCond; | |||||
| /** | /** | ||||
| * Set the filtertrace attribute. | * Set the filtertrace attribute. | ||||
| * @param value a <code>boolean</code> value. | * @param value a <code>boolean</code> value. | ||||
| @@ -107,22 +109,63 @@ public abstract class BaseTest { | |||||
| /** | /** | ||||
| * Set the if attribute. | * 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) { | 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 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 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 propertyName the expression to evaluate | |||||
| */ | */ | ||||
| public void setUnless(String propertyName) { | public void setUnless(String propertyName) { | ||||
| unlessProperty = propertyName; | |||||
| setUnless((Object) propertyName); | |||||
| } | |||||
| /** | |||||
| * The unless expression | |||||
| * @since Ant 1.8.0 | |||||
| */ | |||||
| public Object getUnlessCondition() { | |||||
| return unlessCond; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -188,8 +188,8 @@ public final class BatchTest extends BaseTest { | |||||
| test.setHaltonfailure(this.haltOnFail); | test.setHaltonfailure(this.haltOnFail); | ||||
| test.setFiltertrace(this.filtertrace); | test.setFiltertrace(this.filtertrace); | ||||
| test.setFork(this.fork); | test.setFork(this.fork); | ||||
| test.setIf(this.ifProperty); | |||||
| test.setUnless(this.unlessProperty); | |||||
| test.setIf(getIfCondition()); | |||||
| test.setUnless(getUnlessCondition()); | |||||
| test.setTodir(this.destDir); | test.setTodir(this.destDir); | ||||
| test.setFailureProperty(failureProperty); | test.setFailureProperty(failureProperty); | ||||
| test.setErrorProperty(errorProperty); | test.setErrorProperty(errorProperty); | ||||
| @@ -23,6 +23,7 @@ import java.util.Hashtable; | |||||
| import java.util.Properties; | import java.util.Properties; | ||||
| import java.util.Vector; | import java.util.Vector; | ||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.PropertyHelper; | |||||
| /** | /** | ||||
| * <p> Run a single JUnit test. | * <p> Run a single JUnit test. | ||||
| @@ -193,14 +194,9 @@ public class JUnitTest extends BaseTest implements Cloneable { | |||||
| * @return true if this test or testsuite should be run. | * @return true if this test or testsuite should be run. | ||||
| */ | */ | ||||
| public boolean shouldRun(Project p) { | 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()); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -36,6 +36,11 @@ public class @{classname} extends TestCase { | |||||
| </sequential> | </sequential> | ||||
| </macrodef> | </macrodef> | ||||
| <target name="setUp"> | |||||
| <mkdir dir="${input}"/> | |||||
| <mkdir dir="${output}"/> | |||||
| </target> | |||||
| <target name="testTimeoutLogOfBatchTests"> | <target name="testTimeoutLogOfBatchTests"> | ||||
| <mkdir dir="${input}"/> | <mkdir dir="${input}"/> | ||||
| <mkdir dir="${output}"/> | <mkdir dir="${output}"/> | ||||
| @@ -187,4 +192,101 @@ public class BTest extends TestCase { | |||||
| <au:assertFileExists file="${output}/TEST-test.BTest.xml"/> | <au:assertFileExists file="${output}/TEST-test.BTest.xml"/> | ||||
| </target> | </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> | </project> | ||||