diff --git a/changes.xml b/changes.xml index 45cb0cd..7381cc7 100644 --- a/changes.xml +++ b/changes.xml @@ -52,6 +52,10 @@ assertPropertyContains was not checking the value of the property but the name of the property. + + Add a fail task that makes a test case fail if no condition is provided or + if the provided one is evaluated to false. + diff --git a/src/etc/testcases/assert.xml b/src/etc/testcases/assert.xml index 60075cf..99aaff9 100644 --- a/src/etc/testcases/assert.xml +++ b/src/etc/testcases/assert.xml @@ -29,6 +29,14 @@ under the License. + + + + + + + + diff --git a/src/main/org/apache/ant/antunit/AssertTask.java b/src/main/org/apache/ant/antunit/AssertTask.java index ecbb3d3..45ca462 100644 --- a/src/main/org/apache/ant/antunit/AssertTask.java +++ b/src/main/org/apache/ant/antunit/AssertTask.java @@ -26,7 +26,7 @@ import org.apache.tools.ant.taskdefs.condition.ConditionBase; /** * Exits the active build, giving an additional message if the single - * nested condition fails. + * nested condition fails or if there is no condition at all. * *

This one could as well be implemented as * @@ -68,11 +68,7 @@ public class AssertTask extends ConditionBase { throw new BuildException("You must not specify more than one " + "condition", getLocation()); } - if (count < 1) { - throw new BuildException("You must specify a condition", - getLocation()); - } - if (!((Condition) getConditions().nextElement()).eval()) { + if (count < 1 || !((Condition) getConditions().nextElement()).eval()) { throw new AssertionFailedException(message, getLocation()); } } diff --git a/src/main/org/apache/ant/antunit/AssertionFailedException.java b/src/main/org/apache/ant/antunit/AssertionFailedException.java index 3929c98..f5f10a9 100644 --- a/src/main/org/apache/ant/antunit/AssertionFailedException.java +++ b/src/main/org/apache/ant/antunit/AssertionFailedException.java @@ -29,7 +29,7 @@ import org.apache.tools.ant.Location; public class AssertionFailedException extends BuildException { private static final long serialVersionUID = -1193299712860263327L; - public static final String DEFAULT_MESSAGE = "Assertion failed"; + public static final String DEFAULT_MESSAGE = "Test failed"; public AssertionFailedException(String message) { super(message); diff --git a/src/main/org/apache/ant/antunit/antlib.xml b/src/main/org/apache/ant/antunit/antlib.xml index c8edb02..c9beab2 100644 --- a/src/main/org/apache/ant/antunit/antlib.xml +++ b/src/main/org/apache/ant/antunit/antlib.xml @@ -21,7 +21,7 @@ under the License. - + + + + + + + + + + + - + - + @@ -64,10 +75,10 @@ under the License. - + - + @@ -76,9 +87,9 @@ under the License. - + - + @@ -103,10 +114,10 @@ under the License. default="Expected property '@{name}' to contain value '@{value}' but was '${@{name}}'"/> - + - + @@ -115,9 +126,9 @@ under the License. - + - + @@ -139,10 +150,10 @@ under the License. - + - + @@ -166,9 +177,9 @@ under the License. - + - + @@ -190,9 +201,9 @@ under the License. - + - + @@ -213,9 +224,9 @@ under the License. - + - + @@ -226,9 +237,9 @@ under the License. default="Expected reference '@{refid}' to be a '@{type}'"/> - + - + @@ -238,9 +249,9 @@ under the License. - + - + @@ -265,12 +276,12 @@ under the License. - + - + @@ -283,14 +294,14 @@ under the License. - + - + diff --git a/src/tests/junit/org/apache/ant/antunit/AssertTest.java b/src/tests/junit/org/apache/ant/antunit/AssertTest.java index 5494cdd..d278f15 100644 --- a/src/tests/junit/org/apache/ant/antunit/AssertTest.java +++ b/src/tests/junit/org/apache/ant/antunit/AssertTest.java @@ -31,6 +31,12 @@ public class AssertTest extends BuildFileTest { configureProject("src/etc/testcases/assert.xml"); } + public void testFail() { + testFail("fail", "Test failed"); + } + public void testFailWithMessage() { + testFail("failWithMessage", "This test is expecting to fail"); + } public void testTruePass() { testPass("assertTruePass"); }