From 8e97f1595dfa63ef3351f178c29f6d37deab5354 Mon Sep 17 00:00:00 2001 From: mattinger Date: Wed, 7 Mar 2007 15:11:35 +0000 Subject: git-svn-id: file:///home/sven/projects/JOGL/temp/ant-contrib/svn/ant-contrib-code/trunk/ant-contrib@96 32d7a393-a5a9-423c-abd3-5d954feb1f2f --- docs/manual/tasks/assert_task.html | 76 +++++++++++------------- test/src/net/sf/antcontrib/logic/AssertTest.java | 10 +--- 2 files changed, 37 insertions(+), 49 deletions(-) diff --git a/docs/manual/tasks/assert_task.html b/docs/manual/tasks/assert_task.html index 7d375ce..82385f9 100644 --- a/docs/manual/tasks/assert_task.html +++ b/docs/manual/tasks/assert_task.html @@ -25,27 +25,25 @@ Assert Task

-The Assert task adds an assertion capability to Ant projects. This task works in a manner very similar to the Java -assert - keyword, and provides a limited "design by contract" facility to Ant. This is very useful for testing build scripts prior to putting them into production. +The Assert task adds an assertion capability to Ant projects. This task works in a manner +very similar to the Java assert keyword, and provides a +limited "design by contract" facility to Ant. This is very useful for testing build +scripts prior to putting them into production.

-The Assert task verifies that a given property has a -given value and throws a BuildException if the property value is not as expected -or the property does not exist. +The Assert task verifies that a particular boolean condition is met, and throws a BuildException +if it is not.

-Also like Java's -assert - keyword, the Assert task must be 'turned on' using the property -ant.enable.asserts -. If not set, or is set to -false +Also like Java's assert keyword, the Assert task must be +'turned on' using the property ant.enable.asserts +. If not set, or is set to false , the Assert task works exactly like the Sequential task. If the Variable task - is used to define this property, then it can be turned on and off as needed throughout a build. +is used to define this property, then it can be turned on and off as needed throughout a +build.

@@ -53,7 +51,10 @@ This task can hold other tasks including Assert.

-The Assert task may contain one 'bool' element. The 'bool' element is identical to the ConditionTask, but unlike the ConditionTask, is actually a Task. The 'bool' element can contain all the conditions permitted by the ConditionTask, plus the +Thie assert task may contain a single conditional element known by ANT, or one of +the following additional conditions: + + IsPropertyTrue , IsPropertyFalse @@ -106,31 +107,23 @@ Required name -The name of the property to test for. +The name of the property to test for. This is a shortcut for specifying an <equals> +condition. none -Yes - - - -exists - -Test for existence or non-existence of the property. - -True - -No +No. However, if specified, the 'value' attribute must also be present value -The value to test for, implies 'exists=true'. If the value in the project is different than this value, a BuildException will be thrown and the build will stop. +The value to test for, implies . If the value in the project is different than this value, +a BuildException will be thrown and the build will stop. none -No +No, unless the 'name' attribute is specified. @@ -158,13 +151,9 @@ No

-

- -As stated above, the Assert task may contain a nested "bool" task, otherwise, -the Assert task does not support any nested -elements apart from Ant tasks. Any valid Ant task may be embedded within the -assert task. -

+

+Examples +

In the following example, the first @@ -192,15 +181,20 @@ echo <property name="wait" value="2"/> - <assert name="wait" execute="false"> + <assert execute="false"> + <isset property="wait" /> + <sequential> <echo> Waiting ${wait} seconds... Click the red button to stop waiting. - </echo> - <sleep seconds="${wait}"/> + </echo> + <sleep seconds="${wait}"/> + </sequential> </assert> <assert name="wait" value="2" execute="true"> - <echo>done waiting!</echo> + <sequential> + <echo>done waiting!</echo> + </sequential> </assert> @@ -228,9 +222,7 @@ The next example shows Assert being used in a unit test for the "limit" task: </limit> <stopwatch name="timer" action="total"/> <assert message="Too much time."> - <bool> - <islessthan arg1="${timer}" arg2="2"/> - </bool> + <islessthan arg1="${timer}" arg2="2"/> </assert> </target> diff --git a/test/src/net/sf/antcontrib/logic/AssertTest.java b/test/src/net/sf/antcontrib/logic/AssertTest.java index 449068f..a5c66cc 100644 --- a/test/src/net/sf/antcontrib/logic/AssertTest.java +++ b/test/src/net/sf/antcontrib/logic/AssertTest.java @@ -49,12 +49,8 @@ public class AssertTest extends BuildFileTestBase { executeTarget( "test1" ); } - public void test2() { - expectBuildExceptionStackTraceContaining( "test2", "testing assert failure", "Property 'testprop' doesn't exist in this project." ); - } - public void test3() { - expectBuildExceptionStackTraceContaining( "test3", "testing assert failure", "Expected 'false', but was 'true'." ); + expectBuildException("test3"); } public void test4() { @@ -70,7 +66,7 @@ public class AssertTest extends BuildFileTestBase { } public void test7(){ - expectBuildExceptionStackTraceContaining( "test7", "testing conditions", "Assertion failed boolean test." ); + expectBuildException("test7"); } public void test8() { @@ -78,7 +74,7 @@ public class AssertTest extends BuildFileTestBase { } public void test9() { - expectBuildExceptionStackTraceContaining( "test9", "testing conditions", "Assertion failed boolean test." ); + expectBuildException("test9"); } } -- cgit v1.2.3