Skip to content
Permalink
Browse files
Add errorProperty to <nunit>, PR 40552
git-svn-id: https://svn.apache.org/repos/asf/ant/antlibs/dotnet/trunk@448635 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
bodewig committed Sep 21, 2006
1 parent d1470b0 commit 2a8e0c160cc7c406576784d1b4767ecc421d3b15
Showing 5 changed files with 72 additions and 1 deletion.
@@ -100,6 +100,13 @@ <h3>Parameters</h3>
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>
@@ -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>
@@ -69,6 +69,12 @@
</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>

<target name="teardown">
<delete dir="${build.dir}"/>
</target>
@@ -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;
@@ -48,6 +49,13 @@ public class DotNetExecTask extends ExecTask {
*/
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.
*/
@@ -74,6 +82,19 @@ public void setVm(String value) {
this.vm = value;
}

/**
* 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.
*
@@ -88,6 +109,19 @@ public void execute() throws BuildException {
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);
}

/**
* If the inherited Commandline doesn't know about the executable
* yet, set it and deal with the vm attribute.
@@ -109,6 +109,13 @@ public class NUnitTask extends Task {
*/
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.
*/
@@ -197,6 +204,15 @@ public void setFailOnError(boolean b) {
failOnError = b;
}

/**
* 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.
*/
@@ -324,6 +340,7 @@ public void execute() {
exec.addConfiguredRedirector(redirectorElement);
}
exec.setFailonerror(failOnError);
exec.internalSetErrorProperty(errorProperty);

exec.execute();
}
@@ -61,6 +61,7 @@ public void testPass() {
if (getProject().getProperty("nunit.found") != null) {
expectLogContaining("passing-test",
"Tests run: 1, Failures: 0, Not run: 0");
assertNull(getProject().getProperty("nunit.failed"));
}
}

@@ -77,4 +78,10 @@ public void testFailOnFail() {
}
}

public void testFailWithErrorProperty() {
if (getProject().getProperty("nunit.found") != null) {
expectPropertySet("failing-test-errorproperty", "nunit.failed");
}
}

}

0 comments on commit 2a8e0c1

Please sign in to comment.