You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2005/07/04 15:12:07 UTC

svn commit: r209070 - in /ant/sandbox/antlibs/antunit/trunk: docs/assertions.html src/etc/testcases/assert.xml src/main/org/apache/ant/antunit/antlib.xml src/testcases/org/apache/ant/antunit/AssertTest.java

Author: bodewig
Date: Mon Jul  4 06:12:05 2005
New Revision: 209070

URL: http://svn.apache.org/viewcvs?rev=209070&view=rev
Log:
New assertions for references

Modified:
    ant/sandbox/antlibs/antunit/trunk/docs/assertions.html
    ant/sandbox/antlibs/antunit/trunk/src/etc/testcases/assert.xml
    ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml
    ant/sandbox/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/AssertTest.java

Modified: ant/sandbox/antlibs/antunit/trunk/docs/assertions.html
URL: http://svn.apache.org/viewcvs/ant/sandbox/antlibs/antunit/trunk/docs/assertions.html?rev=209070&r1=209069&r2=209070&view=diff
==============================================================================
--- ant/sandbox/antlibs/antunit/trunk/docs/assertions.html (original)
+++ ant/sandbox/antlibs/antunit/trunk/docs/assertions.html Mon Jul  4 06:12:05 2005
@@ -375,6 +375,78 @@
       <assertFilesDiffer expected="backups/build.xml" actual="build.xml"/>
     </pre>
 
+    <h2><a name="assertReferenceSet">assertReferenceSet</a></h2>
+
+    <p>Asserts that a reference has a value.</p>
+
+    <table border="1" cellpadding="2" cellspacing="0">
+        <tr>
+          <td valign="top"><b>Attribute</b></td>
+          <td valign="top"><b>Description</b></td>
+          <td align="center" valign="top"><b>Required</b></td>
+        </tr>
+        <tr>
+          <td valign="top">refid</td>
+          <td valign="top">Id of the reference.</td>
+          <td valign="top" align="center">Yes</td>
+        </tr>
+        <tr>
+          <td valign="top">message</td>
+          <td valign="top">Message for the exception if the condition
+            doesn't hold true.  Defaults to "Expected
+            reference '<em>id</em>'".</td>
+          <td align="center">No.</td>
+        </tr>
+    </table>
+
+    <h3>Examples</h3>
+
+    <p>Make the build fail with the message "Expected reference 'foo'"
+    if the reference foo is not defined:</p>
+
+    <pre>
+      &lt;assertReferenceSet name="foo"/&gt;
+    </pre>
+
+    <h2><a name="assertReferenceIsType">assertReferenceIsType</a></h2>
+
+    <p>Asserts that a reference has a value of a given type.</p>
+
+    <table border="1" cellpadding="2" cellspacing="0">
+        <tr>
+          <td valign="top"><b>Attribute</b></td>
+          <td valign="top"><b>Description</b></td>
+          <td align="center" valign="top"><b>Required</b></td>
+        </tr>
+        <tr>
+          <td valign="top">refid</td>
+          <td valign="top">Id of the reference.</td>
+          <td valign="top" align="center">Yes</td>
+        </tr>
+        <tr>
+          <td valign="top">type</td>
+          <td valign="top">Name of the data type or task this
+          reference is expected to be.</td>
+          <td valign="top" align="center">Yes</td>
+        </tr>
+        <tr>
+          <td valign="top">message</td>
+          <td valign="top">Message for the exception if the condition
+            doesn't hold true.  Defaults to "Expected
+            reference '<em>id</em>' to be a '<em>type</em>'".</td>
+          <td align="center">No.</td>
+        </tr>
+    </table>
+
+    <h3>Examples</h3>
+
+    <p>Make the build fail if Ant's current Executor is not of type
+    org.apache.tools.ant.helper.DefaultExecutor:</p>
+
+    <pre>
+      &lt;assertReferenceIsType name="ant.executor" type="org.apache.tools.ant.helper.DefaultExecutor"/&gt;
+    </pre>
+
     <hr/>
       <p align="center">Copyright &copy; 2005 The Apache Software Foundation. All rights Reserved.</p>
   </body>

Modified: ant/sandbox/antlibs/antunit/trunk/src/etc/testcases/assert.xml
URL: http://svn.apache.org/viewcvs/ant/sandbox/antlibs/antunit/trunk/src/etc/testcases/assert.xml?rev=209070&r1=209069&r2=209070&view=diff
==============================================================================
--- ant/sandbox/antlibs/antunit/trunk/src/etc/testcases/assert.xml (original)
+++ ant/sandbox/antlibs/antunit/trunk/src/etc/testcases/assert.xml Mon Jul  4 06:12:05 2005
@@ -156,4 +156,26 @@
     <au:assertFilesDiffer expected="assert.xml" actual="antunit.xml"/>
   </target>
 
+  <target name="assertReferenceSetPass">
+    <path id="foo1"/>
+    <au:assertReferenceSet refid="foo1"/>
+  </target>
+
+  <target name="assertReferenceSetFail">
+    <au:assertReferenceSet refid="foo2"/>
+  </target>
+
+  <target name="assertReferenceIsTypePass">
+    <path id="foo3"/>
+    <au:assertReferenceIsType refid="foo3" type="org.apache.tools.ant.types.Path"/>
+  </target>
+
+  <target name="assertReferenceIsTypeFailNotSet">
+    <au:assertReferenceIsType refid="foo4" type="org.apache.tools.ant.types.Path"/>
+  </target>
+
+  <target name="assertReferenceIsTypeFailWrongType">
+    <path id="foo5"/>
+    <au:assertReferenceIsType refid="foo5" type="org.apache.tools.ant.types.FileSet"/>
+  </target>
 </project>

Modified: ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml
URL: http://svn.apache.org/viewcvs/ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml?rev=209070&r1=209069&r2=209070&view=diff
==============================================================================
--- ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml (original)
+++ ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml Mon Jul  4 06:12:05 2005
@@ -147,4 +147,28 @@
     </sequential>
   </macrodef>
 
+  <macrodef name="assertReferenceSet">
+    <attribute name="refid"/>
+    <attribute name="message"
+      default="Expected reference '@{refid}'"/>
+    <sequential>
+      <au:assertTrue message="@{message}">
+        <isreference refid="@{refid}"/>
+      </au:assertTrue>
+    </sequential>
+  </macrodef>
+
+  <macrodef name="assertReferenceIsType">
+    <attribute name="refid"/>
+    <attribute name="type"/>
+    <attribute name="message"
+      default="Expected reference '@{refid}' to be a '@{type}'"/>
+    <sequential>
+      <au:assertReferenceSet refid="@{refid}"/>
+      <au:assertTrue message="@{message}">
+        <isreference refid="@{refid}" type="@{type}"/>
+      </au:assertTrue>
+    </sequential>
+  </macrodef>
+
 </antlib>

Modified: ant/sandbox/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/AssertTest.java
URL: http://svn.apache.org/viewcvs/ant/sandbox/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/AssertTest.java?rev=209070&r1=209069&r2=209070&view=diff
==============================================================================
--- ant/sandbox/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/AssertTest.java (original)
+++ ant/sandbox/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/AssertTest.java Mon Jul  4 06:12:05 2005
@@ -68,6 +68,13 @@
     public void testFilesDifferPass() {
         testPass("assertFilesDifferPass");
     }
+    public void testReferenceSetPass() {
+        testPass("assertReferenceSetPass");
+    }
+    // fails, probably due to classloader issues
+    public void NotestReferenceIsTypePass() {
+        testPass("assertReferenceIsTypePass");
+    }
 
     public void testTrueFail() {
         testFail("assertTrueFail");
@@ -116,6 +123,17 @@
     public void testFilesDifferFail() {
         testFail("assertFilesDifferFail",
                  "Expected files 'assert.xml' and 'assert.xml' to differ");
+    }
+    public void testReferenceSetFail() {
+        testFail("assertReferenceSetFail", "Expected reference 'foo2'");
+    }
+    public void testReferenceIsTypeFailNotSet() {
+        testFail("assertReferenceIsTypeFailNotSet",
+                 "Expected reference 'foo4'");
+    }
+    public void testReferenceIsTypeFailWrongType() {
+        testFail("assertReferenceIsTypeFailWrongType",
+                 "Expected reference 'foo5' to be a 'org.apache.tools.ant.types.FileSet'");
     }
 
     private void testPass(String target) {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org