ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r209062 - in /ant/sandbox/antlibs/antunit/trunk: docs/ src/etc/testcases/ src/main/org/apache/ant/antunit/ src/testcases/org/apache/ant/antunit/
Date Mon, 04 Jul 2005 12:07:51 GMT
Author: bodewig
Date: Mon Jul  4 05:07:49 2005
New Revision: 209062

URL: http://svn.apache.org/viewcvs?rev=209062&view=rev
Log:
New task expectfailure

Added:
    ant/sandbox/antlibs/antunit/trunk/docs/expectfailure.html   (with props)
    ant/sandbox/antlibs/antunit/trunk/src/etc/testcases/expectfailure.xml   (with props)
    ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/ExpectFailureTask.java
  (with props)
    ant/sandbox/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/ExpectFailureTest.java
  (with props)
Modified:
    ant/sandbox/antlibs/antunit/trunk/docs/index.hmtl
    ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml

Added: ant/sandbox/antlibs/antunit/trunk/docs/expectfailure.html
URL: http://svn.apache.org/viewcvs/ant/sandbox/antlibs/antunit/trunk/docs/expectfailure.html?rev=209062&view=auto
==============================================================================
--- ant/sandbox/antlibs/antunit/trunk/docs/expectfailure.html (added)
+++ ant/sandbox/antlibs/antunit/trunk/docs/expectfailure.html Mon Jul  4 05:07:49 2005
@@ -0,0 +1,67 @@
+<html>
+  <head>
+    <meta http-equiv="Content-Language" content="en-us"></meta>
+    <title>expectfailure Task</title>
+  </head>
+
+  <body>
+    <h2><a name="expectfailure">expectfailure</a></h2>
+
+    <h3>Description</h3>
+
+    <p>Asserts that a number of nested tasks throws a BuildException.</p>
+
+    <h3>Parameters</h3>
+    <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">message</td>
+        <td valign="top">Message for the exception if the condition
+        doesn't hold true.  Defaults to "Expected build failure" if
+        expectedMessage hasn't been specified or "Expected build
+        failure with message '<em>expectedMessage</em>' but was
+        '<em>actualMessage</em>'" if it has been specified and a
+        different exception has been thrown.</td>
+        <td align="center">No.</td>
+      </tr>
+      <tr>
+        <td valign="top">expectedMessage</td>
+        <td valign="top">Used to assert a specific exception message.</td>
+        <td align="center">No.</td>
+      </tr>
+    </table>
+
+    <h3>Parameters specified as nested elements</h3>
+    <h4>all Ant tasks</h4>
+
+    <p>You can use all supported tasks and types as nested element of
+    this task.</p>
+
+    <h3>Examples</h3>
+
+    <p>Make the build fail with the message "expected build failure
+    with message='failed' but was 'passed'":</p>
+
+    <pre>
+      &lt;expectfailure expectedMessage="failed"&gt;
+        &lt;fail&gt;passed&lt;fail&gt;
+      &lt;/expectfailure&gt;
+    </pre>
+
+    <p>Make the build fail with the message "expected build failure"
+    because the nested task doesn't cause a build failure:</p>
+
+    <pre>
+      &lt;expectfailure&gt;
+        &lt;echo&gt;BUILD FAILED&lt;/echo&gt;
+      &lt;/expectfailure&gt;
+    </pre>
+
+    <hr/>
+      <p align="center">Copyright &copy; 2005 The Apache Software Foundation. All
rights Reserved.</p>
+  </body>
+</html>
\ No newline at end of file

Propchange: ant/sandbox/antlibs/antunit/trunk/docs/expectfailure.html
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ant/sandbox/antlibs/antunit/trunk/docs/index.hmtl
URL: http://svn.apache.org/viewcvs/ant/sandbox/antlibs/antunit/trunk/docs/index.hmtl?rev=209062&r1=209061&r2=209062&view=diff
==============================================================================
--- ant/sandbox/antlibs/antunit/trunk/docs/index.hmtl (original)
+++ ant/sandbox/antlibs/antunit/trunk/docs/index.hmtl Mon Jul  4 05:07:49 2005
@@ -103,6 +103,10 @@
       <li><a href="assertions.html">more assertions</a> - useful
       specialized versions of assertTrue.</li>
 
+      <li><a href="expectfailure.html">expectfailure</a> - a task
+      container useful for tests that assert build failures.</li>
+    </ul>
+
     <hr/>
       <p align="center">Copyright &copy; 2005 The Apache Software Foundation. All
rights Reserved.</p>
   </body>

Added: ant/sandbox/antlibs/antunit/trunk/src/etc/testcases/expectfailure.xml
URL: http://svn.apache.org/viewcvs/ant/sandbox/antlibs/antunit/trunk/src/etc/testcases/expectfailure.xml?rev=209062&view=auto
==============================================================================
--- ant/sandbox/antlibs/antunit/trunk/src/etc/testcases/expectfailure.xml (added)
+++ ant/sandbox/antlibs/antunit/trunk/src/etc/testcases/expectfailure.xml Mon Jul  4 05:07:49
2005
@@ -0,0 +1,58 @@
+<?xml version="1.0"?>
+
+<!--
+ Copyright  2005 The Apache Software Foundation
+ 
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+ 
+      http://www.apache.org/licenses/LICENSE-2.0
+ 
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<project name="antunit-test"
+         default="all" xmlns:au="antlib:org.apache.ant.antunit">
+
+  <target name="passNoMessage">
+    <au:expectfailure>
+      <fail>foo</fail>
+    </au:expectfailure>
+  </target>
+
+  <target name="passMessage">
+    <au:expectfailure expectedMessage="foo">
+      <fail>foo</fail>
+    </au:expectfailure>
+  </target>
+
+  <target name="failNoMessage">
+    <au:expectfailure>
+      <echo>foo</echo>
+    </au:expectfailure>
+  </target>
+
+  <target name="failWrongMessage">
+    <au:expectfailure expectedMessage="bar">
+      <fail>foo</fail>
+    </au:expectfailure>
+  </target>
+
+  <target name="failNoMessageMessageSet">
+    <au:expectfailure message="oops">
+      <echo>foo</echo>
+    </au:expectfailure>
+  </target>
+
+  <target name="failWrongMessageMessageSet">
+    <au:expectfailure expectedMessage="bar" message="oops">
+      <fail>foo</fail>
+    </au:expectfailure>
+  </target>
+
+</project>
\ No newline at end of file

Propchange: ant/sandbox/antlibs/antunit/trunk/src/etc/testcases/expectfailure.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/ExpectFailureTask.java
URL: http://svn.apache.org/viewcvs/ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/ExpectFailureTask.java?rev=209062&view=auto
==============================================================================
--- ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/ExpectFailureTask.java
(added)
+++ ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/ExpectFailureTask.java
Mon Jul  4 05:07:49 2005
@@ -0,0 +1,78 @@
+/*
+ * Copyright  2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.ant.antunit;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.Sequential;
+
+/**
+ * Expects the nested tasks to throw a BuildException and optinally
+ * asserts the message of that exception.
+ *
+ * <p>Throws a AssertFailedException if the nested tasks do not throw
+ * the expected BuildException.</p>
+ */
+public class ExpectFailureTask extends Sequential {
+
+    private String expectedMessage;
+    private String message;
+
+    /**
+     * The exception message to expect.
+     */
+    public void setExpectedMessage(String m) {
+        expectedMessage = m;
+    }
+
+    /**
+     * The message to use in the AssertinFailedException if the nested
+     * tasks fail to raise the "correct" exception.
+     */
+    public void setMessage(String m) {
+        message = m;
+    }
+
+    public void execute() {
+        boolean thrown = false;
+        try {
+            super.execute();
+        } catch (BuildException e) {
+            thrown = true;
+            if (expectedMessage != null
+                && !expectedMessage.equals(e.getMessage())) {
+                if (message == null) {
+                    throw new AssertionFailedException("Expected build failure "
+                                                       + "with message '"
+                                                       + expectedMessage
+                                                       + "' but was '"
+                                                       + e.getMessage() + "'");
+                } else {
+                    throw new AssertionFailedException(message);
+                }
+            }
+        }
+
+        if (!thrown) {
+            if (message == null) {
+                throw new AssertionFailedException("Expected build failure");
+            } else {
+                throw new AssertionFailedException(message);
+            }
+        }
+    }
+}        
\ No newline at end of file

Propchange: ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/ExpectFailureTask.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=209062&r1=209061&r2=209062&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 05:07:49 2005
@@ -21,6 +21,9 @@
   <taskdef name="assertTrue"
     classname="org.apache.ant.antunit.AssertTask"/>
 
+  <taskdef name="expectfailure"
+    classname="org.apache.ant.antunit.ExpectFailureTask"/>
+
   <typedef name="plainlistener"
     classname="org.apache.ant.antunit.PlainAntUnitListener"/>
 

Added: ant/sandbox/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/ExpectFailureTest.java
URL: http://svn.apache.org/viewcvs/ant/sandbox/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/ExpectFailureTest.java?rev=209062&view=auto
==============================================================================
--- ant/sandbox/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/ExpectFailureTest.java
(added)
+++ ant/sandbox/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/ExpectFailureTest.java
Mon Jul  4 05:07:49 2005
@@ -0,0 +1,64 @@
+/*
+ * Copyright  2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ant.antunit;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileTest;
+
+public class ExpectFailureTest extends BuildFileTest {
+
+    public ExpectFailureTest(String name) {
+        super(name);
+    }
+
+    public void setUp() {
+        configureProject("src/etc/testcases/expectfailure.xml");
+    }
+
+    public void testPassNoMessage() {
+        testPass("passNoMessage");
+    }
+    public void testPassMessage() {
+        testPass("passMessage");
+    }
+
+    public void testFailNoMessage() {
+        testFail("failNoMessage", "Expected build failure");
+    }
+    public void testFailMessage() {
+        testFail("failWrongMessage", "Expected build failure with message 'bar'"
+                 + " but was 'foo'");
+    }
+    public void testFailNoMessageMessageSet() {
+        testFail("failNoMessageMessageSet", "oops");
+    }
+    public void testFailMessageMessageSet() {
+        testFail("failWrongMessageMessageSet", "oops");
+    }
+
+    private void testPass(String target) {
+        executeTarget(target);
+    }
+    private void testFail(String target, String message) {
+        try {
+            executeTarget(target);
+            fail("Expected an exception");
+        } catch (AssertionFailedException e) {
+            assertEquals(message, e.getMessage());
+        }
+    }
+}

Propchange: ant/sandbox/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/ExpectFailureTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



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


Mime
View raw message