|
|
@@ -19,7 +19,7 @@ package org.apache.tools.ant.taskdefs.optional.junit; |
|
|
|
|
|
|
|
import java.io.OutputStream; |
|
|
|
import junit.framework.AssertionFailedError; |
|
|
|
import junit.framework.Test; |
|
|
|
import junit.framework.TestCase; |
|
|
|
import junit.framework.TestResult; |
|
|
|
import org.apache.tools.ant.AntClassLoader; |
|
|
|
|
|
|
@@ -31,28 +31,22 @@ import org.apache.tools.ant.AntClassLoader; |
|
|
|
* @since 1.7 |
|
|
|
*/ |
|
|
|
public final class JUnitTaskMirrorImpl implements JUnitTaskMirror { |
|
|
|
|
|
|
|
|
|
|
|
private final JUnitTask task; |
|
|
|
|
|
|
|
|
|
|
|
public JUnitTaskMirrorImpl(JUnitTask task) { |
|
|
|
this.task = task; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void addVmExit(JUnitTest test, JUnitTaskMirror.JUnitResultFormatterMirror _formatter, |
|
|
|
OutputStream out, final String message) { |
|
|
|
JUnitResultFormatter formatter = (JUnitResultFormatter) _formatter; |
|
|
|
formatter.setOutput(out); |
|
|
|
formatter.startTestSuite(test); |
|
|
|
|
|
|
|
//the trick to integrating test output to the formatter, is to |
|
|
|
//create a special test class that asserts an error |
|
|
|
//and tell the formatter that it raised. |
|
|
|
Test t = new Test() { |
|
|
|
public int countTestCases() { return 1; } |
|
|
|
public void run(TestResult r) { |
|
|
|
throw new AssertionFailedError(message); |
|
|
|
} |
|
|
|
}; |
|
|
|
TestCase t = new VmExitErrorTest(message, test); |
|
|
|
formatter.startTest(t); |
|
|
|
formatter.addError(t, new AssertionFailedError(message)); |
|
|
|
formatter.endTestSuite(test); |
|
|
@@ -68,5 +62,31 @@ public final class JUnitTaskMirrorImpl implements JUnitTaskMirror { |
|
|
|
public JUnitTaskMirror.SummaryJUnitResultFormatterMirror newSummaryJUnitResultFormatter() { |
|
|
|
return new SummaryJUnitResultFormatter(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static class VmExitErrorTest extends TestCase { |
|
|
|
|
|
|
|
private String message; |
|
|
|
private JUnitTest test; |
|
|
|
|
|
|
|
VmExitErrorTest(String aMessage, JUnitTest anOriginalTest) { |
|
|
|
message = aMessage; |
|
|
|
test = anOriginalTest; |
|
|
|
} |
|
|
|
|
|
|
|
public int countTestCases() { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
public void run(TestResult r) { |
|
|
|
throw new AssertionFailedError(message); |
|
|
|
} |
|
|
|
|
|
|
|
public String getName() { |
|
|
|
return test.getName(); |
|
|
|
} |
|
|
|
|
|
|
|
public String toString() { |
|
|
|
return test.getName(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |