From fa67ab4990484bbb112ea3f2fd8c350c7046a99b Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 9 Oct 2009 03:56:28 +0000 Subject: [PATCH] Make if/unless und junit test children use the same logic as target's if/unless git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@823395 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/taskdefs/optional/junit/BaseTest.java | 61 +++++++++-- .../taskdefs/optional/junit/BatchTest.java | 4 +- .../taskdefs/optional/junit/JUnitTest.java | 12 +-- .../taskdefs/optional/junit/junit-test.xml | 102 ++++++++++++++++++ 4 files changed, 160 insertions(+), 19 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java index 13c6c330e..6d993717e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java @@ -41,6 +41,8 @@ public abstract class BaseTest { protected String errorProperty; // CheckStyle:VisibilityModifier ON + private Object ifCond, unlessCond; + /** * Set the filtertrace attribute. * @param value a boolean value. @@ -107,22 +109,63 @@ public abstract class BaseTest { /** * 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 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) { - unlessProperty = propertyName; + setUnless((Object) propertyName); + } + + /** + * The unless expression + * @since Ant 1.8.0 + */ + public Object getUnlessCondition() { + return unlessCond; } /** diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java index 673f57fdc..5feeafacf 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java @@ -188,8 +188,8 @@ public final class BatchTest extends BaseTest { 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); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java index e3cac5647..960a254b3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java @@ -23,6 +23,7 @@ import java.util.Hashtable; import java.util.Properties; import java.util.Vector; import org.apache.tools.ant.Project; +import org.apache.tools.ant.PropertyHelper; /** *

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. */ 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()); } /** diff --git a/src/tests/antunit/taskdefs/optional/junit/junit-test.xml b/src/tests/antunit/taskdefs/optional/junit/junit-test.xml index 7bb8f6acd..4613d23df 100644 --- a/src/tests/antunit/taskdefs/optional/junit/junit-test.xml +++ b/src/tests/antunit/taskdefs/optional/junit/junit-test.xml @@ -36,6 +36,11 @@ public class @{classname} extends TestCase { + + + + + @@ -187,4 +192,101 @@ public class BTest extends TestCase { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +