ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r829913 - in /ant/antlibs/antunit/trunk: ./ src/etc/testcases/ src/main/org/apache/ant/antunit/ src/tests/junit/org/apache/ant/antunit/
Date Mon, 26 Oct 2009 19:25:02 GMT
Author: hibou
Date: Mon Oct 26 19:25:01 2009
New Revision: 829913

URL: http://svn.apache.org/viewvc?rev=829913&view=rev
Log:
Add a fail task that makes a test case fail if no condition is provided or if the provided
one is evaluated to false

Modified:
    ant/antlibs/antunit/trunk/changes.xml
    ant/antlibs/antunit/trunk/src/etc/testcases/assert.xml
    ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AssertTask.java
    ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AssertionFailedException.java
    ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml
    ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/AssertTest.java

Modified: ant/antlibs/antunit/trunk/changes.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/changes.xml?rev=829913&r1=829912&r2=829913&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/changes.xml (original)
+++ ant/antlibs/antunit/trunk/changes.xml Mon Oct 26 19:25:01 2009
@@ -52,6 +52,10 @@
       assertPropertyContains was not checking the value of the property but
       the name of the property.
     </action>
+    <action type="add">
+      Add a fail task that makes a test case fail if no condition is provided or
+      if the provided one is evaluated to false.
+    </action>
   </release>
   
   <release version="1.1" date="2008-09-26">

Modified: ant/antlibs/antunit/trunk/src/etc/testcases/assert.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/etc/testcases/assert.xml?rev=829913&r1=829912&r2=829913&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/etc/testcases/assert.xml (original)
+++ ant/antlibs/antunit/trunk/src/etc/testcases/assert.xml Mon Oct 26 19:25:01 2009
@@ -29,6 +29,14 @@
     </au:antunit>
   </target>
 
+  <target name="fail">
+    <au:fail />
+  </target>
+
+  <target name="failWithMessage">
+    <au:fail message="This test is expecting to fail" />
+  </target>
+
   <target name="assertTruePass">
     <au:assertTrue>
       <istrue value="true"/>

Modified: ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AssertTask.java
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AssertTask.java?rev=829913&r1=829912&r2=829913&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AssertTask.java (original)
+++ ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AssertTask.java Mon Oct 26 19:25:01
2009
@@ -26,7 +26,7 @@
 
 /**
  * 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.
  *
  * <p>This one could as well be implemented as
  *
@@ -68,11 +68,7 @@
             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());
         }
     }

Modified: ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AssertionFailedException.java
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AssertionFailedException.java?rev=829913&r1=829912&r2=829913&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AssertionFailedException.java
(original)
+++ ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AssertionFailedException.java
Mon Oct 26 19:25:01 2009
@@ -29,7 +29,7 @@
 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);

Modified: ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml?rev=829913&r1=829912&r2=829913&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml (original)
+++ ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml Mon Oct 26 19:25:01
2009
@@ -21,7 +21,7 @@
   <taskdef name="antunit"
     classname="org.apache.ant.antunit.AntUnit"/>
 
-  <taskdef name="assertTrue"
+  <taskdef name="fail"
     classname="org.apache.ant.antunit.AssertTask"/>
 
   <taskdef name="expectfailure"
@@ -45,15 +45,26 @@
   <typedef name="logcontent"
     classname="org.apache.ant.antunit.LogContent" />
 
+  <!-- Actually just an alias of fail that expects a condition -->
+  <macrodef name="assertTrue" backtrace="false">
+    <attribute name="message" default="Assertion failed"/>
+    <element name="assertion" implicit="true"/>
+    <sequential>
+      <au:fail message="@{message}">
+        <assertion/>
+      </au:fail>
+    </sequential>
+  </macrodef>
+
   <macrodef name="assertFalse" backtrace="false">
     <attribute name="message" default="Assertion failed"/>
     <element name="assertion" implicit="true"/>
     <sequential>
-      <au:assertTrue message="@{message}">
+      <au:fail message="@{message}">
         <not>
           <assertion/>
         </not>
-      </au:assertTrue>
+      </au:fail>
     </sequential>
   </macrodef>
 
@@ -64,10 +75,10 @@
     <attribute name="message"
       default="Expected '@{expected}' but was '@{actual}'"/>
     <sequential>
-      <au:assertTrue message="@{message}">
+      <au:fail message="@{message}">
         <equals arg1="@{expected}" arg2="@{actual}"
                   casesensitive="@{casesensitive}"/>
-      </au:assertTrue>
+      </au:fail>
     </sequential>
   </macrodef>
 
@@ -76,9 +87,9 @@
     <attribute name="message"
       default="Expected property '@{name}'"/>
     <sequential>
-      <au:assertTrue message="@{message}">
+      <au:fail message="@{message}">
         <isset property="@{name}"/>
-      </au:assertTrue>
+      </au:fail>
     </sequential>
   </macrodef>
 
@@ -103,10 +114,10 @@
                default="Expected property '@{name}' to contain value '@{value}' but was '${@{name}}'"/>
     <sequential>
       <au:assertPropertySet message="@{message}" name="@{name}"/>
-      <au:assertTrue message="@{message}">
+      <au:fail message="@{message}">
         <contains string="${@{name}}" substring="@{value}"
                   casesensitive="@{casesensitive}"/>
-      </au:assertTrue>
+      </au:fail>
     </sequential>
   </macrodef>
   
@@ -115,9 +126,9 @@
     <attribute name="message"
       default="Expected file '@{file}' to exist"/>
     <sequential>
-      <au:assertTrue message="@{message}">
+      <au:fail message="@{message}">
         <available file="@{file}"/>
-      </au:assertTrue>
+      </au:fail>
     </sequential>
   </macrodef>
 
@@ -139,10 +150,10 @@
     <attribute name="message"
 	       default="Expected resource '@{resource}' to contain value '@{value}' but was '${@{resource}}'"/>
     <sequential>
-      <au:assertTrue message="@{message}">
+      <au:fail message="@{message}">
 	<resourcecontains resource="@{resource}" substring="@{value}"
                           casesensitive="@{casesensitive}"/>
-      </au:assertTrue>
+      </au:fail>
     </sequential>
   </macrodef>
 
@@ -166,9 +177,9 @@
     <attribute name="message"
       default="Expected '@{dest}' to be more recent than '@{src}'"/>
     <sequential>
-      <au:assertTrue message="@{message}">
+      <au:fail message="@{message}">
         <uptodate srcfile="@{src}" targetfile="@{dest}"/>
-      </au:assertTrue>
+      </au:fail>
     </sequential>
   </macrodef>
 
@@ -190,9 +201,9 @@
     <attribute name="message"
       default="Expected files '@{expected}' and '@{actual}' to match"/>
     <sequential>
-      <au:assertTrue message="@{message}">
+      <au:fail message="@{message}">
         <filesmatch file1="@{expected}" file2="@{actual}"/>
-      </au:assertTrue>
+      </au:fail>
     </sequential>
   </macrodef>
 
@@ -213,9 +224,9 @@
     <attribute name="message"
       default="Expected reference '@{refid}'"/>
     <sequential>
-      <au:assertTrue message="@{message}">
+      <au:fail message="@{message}">
         <isreference refid="@{refid}"/>
-      </au:assertTrue>
+      </au:fail>
     </sequential>
   </macrodef>
 
@@ -226,9 +237,9 @@
       default="Expected reference '@{refid}' to be a '@{type}'"/>
     <sequential>
       <au:assertReferenceSet refid="@{refid}"/>
-      <au:assertTrue message="@{message}">
+      <au:fail message="@{message}">
         <isreference refid="@{refid}" type="@{type}"/>
-      </au:assertTrue>
+      </au:fail>
     </sequential>
   </macrodef>
 
@@ -238,9 +249,9 @@
     <attribute name="message"
       default="Expected log to contain '@{text}' at level @{level}"/>
     <sequential>
-      <au:assertTrue message="@{message}">
+      <au:fail message="@{message}">
         <au:logcontains text="@{text}" level="@{level}"/>
-      </au:assertTrue>
+      </au:fail>
     </sequential>
   </macrodef>
 
@@ -265,12 +276,12 @@
     <attribute name="message"
       default="Expected '@{string}' to match pattern '@{pattern}'"/>
     <sequential>
-      <au:assertTrue message="@{message}">
+      <au:fail message="@{message}">
 	<matches string="@{string}" pattern="@{pattern}"
                  casesensitive="@{casesensitive}"
                  singleline="@{singleline}"
                  multiline="@{multiline}"/>
-      </au:assertTrue>
+      </au:fail>
     </sequential>
   </macrodef>
 
@@ -283,14 +294,14 @@
     <attribute name="message"
       default="Expected '@{string}' to not match pattern '@{pattern}'"/>
     <sequential>
-      <au:assertTrue message="@{message}">
+      <au:fail message="@{message}">
         <not>
           <matches string="@{string}" pattern="@{pattern}"
                    casesensitive="@{casesensitive}"
                    singleline="@{singleline}"
                    multiline="@{multiline}"/>
         </not>
-      </au:assertTrue>
+      </au:fail>
     </sequential>
   </macrodef>
 

Modified: ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/AssertTest.java
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/AssertTest.java?rev=829913&r1=829912&r2=829913&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/AssertTest.java (original)
+++ ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/AssertTest.java Mon Oct
26 19:25:01 2009
@@ -31,6 +31,12 @@
         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");
     }



Mime
View raw message