ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r448635 - in /ant/antlibs/dotnet/trunk: docs/nunit.html src/etc/testcases/nunit.xml src/main/org/apache/ant/dotnet/DotNetExecTask.java src/main/org/apache/ant/dotnet/NUnitTask.java src/tests/junit/org/apache/ant/dotnet/NUnitTaskTest.java
Date Thu, 21 Sep 2006 19:09:08 GMT
Author: bodewig
Date: Thu Sep 21 12:09:08 2006
New Revision: 448635

URL: http://svn.apache.org/viewvc?view=rev&rev=448635
Log:
Add errorProperty to <nunit>, PR 40552

Modified:
    ant/antlibs/dotnet/trunk/docs/nunit.html
    ant/antlibs/dotnet/trunk/src/etc/testcases/nunit.xml
    ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/DotNetExecTask.java
    ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/NUnitTask.java
    ant/antlibs/dotnet/trunk/src/tests/junit/org/apache/ant/dotnet/NUnitTaskTest.java

Modified: ant/antlibs/dotnet/trunk/docs/nunit.html
URL: http://svn.apache.org/viewvc/ant/antlibs/dotnet/trunk/docs/nunit.html?view=diff&rev=448635&r1=448634&r2=448635
==============================================================================
--- ant/antlibs/dotnet/trunk/docs/nunit.html (original)
+++ ant/antlibs/dotnet/trunk/docs/nunit.html Thu Sep 21 12:09:08 2006
@@ -100,6 +100,13 @@
         indicating an error or failure.</td>
         <td align="center">No - defaults to false.</td>
       </tr>
+      <tr>
+        <td valign="top">errorProperty</td>
+        <td valign="top">Name of the Ant property to set if one of the
+        tests fails/causes an error.  Only useful if the failOnError
+        attribute is set to false.</td>
+        <td align="center">No.</td>
+      </tr>
     </table>
 
     <h3>Parameters specified as nested elements</h3>

Modified: ant/antlibs/dotnet/trunk/src/etc/testcases/nunit.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/dotnet/trunk/src/etc/testcases/nunit.xml?view=diff&rev=448635&r1=448634&r2=448635
==============================================================================
--- ant/antlibs/dotnet/trunk/src/etc/testcases/nunit.xml (original)
+++ ant/antlibs/dotnet/trunk/src/etc/testcases/nunit.xml Thu Sep 21 12:09:08 2006
@@ -52,7 +52,7 @@
   </target>
 
   <target name="passing-test" depends="compile-pass">
-    <dn:nunit>
+    <dn:nunit errorProperty="nunit.failed">
       <testassembly name="${build.dir}/Pass.dll"/>
     </dn:nunit>
   </target>
@@ -65,6 +65,12 @@
 
   <target name="failing-test-with-fail" depends="compile-fail">
     <dn:nunit failonerror="true">
+      <testassembly name="${build.dir}/Fail.dll"/>
+    </dn:nunit>
+  </target>
+
+  <target name="failing-test-errorproperty" depends="compile-fail">
+    <dn:nunit errorProperty="nunit.failed">
       <testassembly name="${build.dir}/Fail.dll"/>
     </dn:nunit>
   </target>

Modified: ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/DotNetExecTask.java
URL: http://svn.apache.org/viewvc/ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/DotNetExecTask.java?view=diff&rev=448635&r1=448634&r2=448635
==============================================================================
--- ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/DotNetExecTask.java (original)
+++ ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/DotNetExecTask.java Thu Sep 21
12:09:08 2006
@@ -20,6 +20,7 @@
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.Execute;
 import org.apache.tools.ant.taskdefs.ExecTask;
 import org.apache.tools.ant.taskdefs.condition.Os;
 import org.apache.tools.ant.types.Environment;
@@ -49,6 +50,13 @@
     private String vm = Os.isFamily("windows") ? MS_VM : "mono";
 
     /**
+     * Name of property to set if execution fails.
+     *
+     * @since 1.0 Beta 2
+     */
+    private String errorProperty;
+
+    /**
      * Empty Constructor.
      */
     public DotNetExecTask() {
@@ -75,6 +83,19 @@
     }
 
     /**
+     * Sets the name of the property to set if execution fails.
+     *
+     * <p>Not exposed as an attribute of the task, it just supports
+     * tasks like &lt;nunit&gt; which delegate to instances of this
+     * class.</p>
+     *
+     * @since 1.0 Beta 2
+     */
+    public void internalSetErrorProperty(String name) {
+        errorProperty = name;
+    }
+
+    /**
      * Do the work.
      *
      * @throws BuildException if executable is empty or &lt;exec&gt;
@@ -86,6 +107,19 @@
         }
         setupCommandline();
         super.execute();
+    }
+
+    /**
+     * Overridden to support the error-property handling required by
+     * NUnit, NAnt and friends.
+     *
+     * @since 1.0 Beta 2
+     */
+    protected void maybeSetResultPropertyValue(int result) {
+        if (errorProperty != null && Execute.isFailure(result)) {
+            getProject().setNewProperty(errorProperty, String.valueOf(true));
+        }
+        super.maybeSetResultPropertyValue(result);
     }
 
     /**

Modified: ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/NUnitTask.java
URL: http://svn.apache.org/viewvc/ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/NUnitTask.java?view=diff&rev=448635&r1=448634&r2=448635
==============================================================================
--- ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/NUnitTask.java (original)
+++ ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/NUnitTask.java Thu Sep 21 12:09:08
2006
@@ -110,6 +110,13 @@
     private boolean failOnError = false;
 
     /**
+     * Name of property to set if a test fails.
+     *
+     * @since 1.0 Beta 2
+     */
+    private String errorProperty;
+
+    /**
      * Support for nested environment variables.
      */
     private Environment env = new Environment();
@@ -198,6 +205,15 @@
     }
 
     /**
+     * Name of property to set if a test fails.
+     *
+     * @since 1.0 Beta 2
+     */
+    public void setErrorProperty(String name) {
+        errorProperty = name;
+    }
+
+    /**
      * Adds a test assembly by name.
      */
     public void addTestAssembly(NamedElement a) {
@@ -324,6 +340,7 @@
             exec.addConfiguredRedirector(redirectorElement);
         }
         exec.setFailonerror(failOnError);
+        exec.internalSetErrorProperty(errorProperty);
 
         exec.execute();
     }

Modified: ant/antlibs/dotnet/trunk/src/tests/junit/org/apache/ant/dotnet/NUnitTaskTest.java
URL: http://svn.apache.org/viewvc/ant/antlibs/dotnet/trunk/src/tests/junit/org/apache/ant/dotnet/NUnitTaskTest.java?view=diff&rev=448635&r1=448634&r2=448635
==============================================================================
--- ant/antlibs/dotnet/trunk/src/tests/junit/org/apache/ant/dotnet/NUnitTaskTest.java (original)
+++ ant/antlibs/dotnet/trunk/src/tests/junit/org/apache/ant/dotnet/NUnitTaskTest.java Thu
Sep 21 12:09:08 2006
@@ -61,6 +61,7 @@
         if (getProject().getProperty("nunit.found") != null) {
             expectLogContaining("passing-test", 
                                 "Tests run: 1, Failures: 0, Not run: 0");
+            assertNull(getProject().getProperty("nunit.failed"));
         }
     }
 
@@ -74,6 +75,12 @@
     public void testFailOnFail() {
         if (getProject().getProperty("nunit.found") != null) {
             expectBuildException("failing-test-with-fail", "test should fail");
+        }
+    }
+
+    public void testFailWithErrorProperty() {
+        if (getProject().getProperty("nunit.found") != null) {
+            expectPropertySet("failing-test-errorproperty", "nunit.failed");
         }
     }
 



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


Mime
View raw message