|
|
@@ -84,7 +84,7 @@ import org.apache.tools.ant.util.TeeOutputStream; |
|
|
* |
|
|
* |
|
|
* <p>This TestRunner expects a name of a TestCase class as its |
|
|
* <p>This TestRunner expects a name of a TestCase class as its |
|
|
* argument. If this class provides a static suite() method it will be |
|
|
* argument. If this class provides a static suite() method it will be |
|
|
* called and the resulting Test will be run. So, the signature should be |
|
|
|
|
|
|
|
|
* called and the resulting Test will be run. So, the signature should be |
|
|
* <pre><code> |
|
|
* <pre><code> |
|
|
* public static junit.framework.Test suite() |
|
|
* public static junit.framework.Test suite() |
|
|
* </code></pre> |
|
|
* </code></pre> |
|
|
@@ -92,7 +92,7 @@ import org.apache.tools.ant.util.TeeOutputStream; |
|
|
* <p> If no such method exists, all public methods starting with |
|
|
* <p> If no such method exists, all public methods starting with |
|
|
* "test" and taking no argument will be run. |
|
|
* "test" and taking no argument will be run. |
|
|
* |
|
|
* |
|
|
* <p> Summary output is generated at the end. |
|
|
|
|
|
|
|
|
* <p> Summary output is generated at the end. |
|
|
* |
|
|
* |
|
|
* @author Stefan Bodewig |
|
|
* @author Stefan Bodewig |
|
|
* @author <a href="mailto:ehatcher@apache.org">Erik Hatcher</a> |
|
|
* @author <a href="mailto:ehatcher@apache.org">Erik Hatcher</a> |
|
|
@@ -131,7 +131,7 @@ public class JUnitTestRunner implements TestListener { |
|
|
* Do we filter junit.*.* stack frames out of failure and error exceptions. |
|
|
* Do we filter junit.*.* stack frames out of failure and error exceptions. |
|
|
*/ |
|
|
*/ |
|
|
private static boolean filtertrace = true; |
|
|
private static boolean filtertrace = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Do we send output to System.out/.err in addition to the formatters? |
|
|
* Do we send output to System.out/.err in addition to the formatters? |
|
|
*/ |
|
|
*/ |
|
|
@@ -149,7 +149,7 @@ public class JUnitTestRunner implements TestListener { |
|
|
"org.apache.tools.ant." |
|
|
"org.apache.tools.ant." |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Do we stop on errors. |
|
|
* Do we stop on errors. |
|
|
*/ |
|
|
*/ |
|
|
@@ -182,27 +182,27 @@ public class JUnitTestRunner implements TestListener { |
|
|
|
|
|
|
|
|
/** output written during the test */ |
|
|
/** output written during the test */ |
|
|
private PrintStream systemError; |
|
|
private PrintStream systemError; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Error output during the test */ |
|
|
/** Error output during the test */ |
|
|
private PrintStream systemOut; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private PrintStream systemOut; |
|
|
|
|
|
|
|
|
/** is this runner running in forked mode? */ |
|
|
/** is this runner running in forked mode? */ |
|
|
private boolean forked = false; |
|
|
private boolean forked = false; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Constructor for fork=true or when the user hasn't specified a |
|
|
* Constructor for fork=true or when the user hasn't specified a |
|
|
* classpath. |
|
|
|
|
|
|
|
|
* classpath. |
|
|
*/ |
|
|
*/ |
|
|
public JUnitTestRunner(JUnitTest test, boolean haltOnError, |
|
|
|
|
|
|
|
|
public JUnitTestRunner(JUnitTest test, boolean haltOnError, |
|
|
boolean filtertrace, boolean haltOnFailure) { |
|
|
boolean filtertrace, boolean haltOnFailure) { |
|
|
this(test, haltOnError, filtertrace, haltOnFailure, false); |
|
|
this(test, haltOnError, filtertrace, haltOnFailure, false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Constructor for fork=true or when the user hasn't specified a |
|
|
* Constructor for fork=true or when the user hasn't specified a |
|
|
* classpath. |
|
|
|
|
|
|
|
|
* classpath. |
|
|
*/ |
|
|
*/ |
|
|
public JUnitTestRunner(JUnitTest test, boolean haltOnError, |
|
|
|
|
|
|
|
|
public JUnitTestRunner(JUnitTest test, boolean haltOnError, |
|
|
boolean filtertrace, boolean haltOnFailure, |
|
|
boolean filtertrace, boolean haltOnFailure, |
|
|
boolean showOutput) { |
|
|
boolean showOutput) { |
|
|
this(test, haltOnError, filtertrace, haltOnFailure, showOutput, null); |
|
|
this(test, haltOnError, filtertrace, haltOnFailure, showOutput, null); |
|
|
@@ -211,8 +211,8 @@ public class JUnitTestRunner implements TestListener { |
|
|
/** |
|
|
/** |
|
|
* Constructor to use when the user has specified a classpath. |
|
|
* Constructor to use when the user has specified a classpath. |
|
|
*/ |
|
|
*/ |
|
|
public JUnitTestRunner(JUnitTest test, boolean haltOnError, |
|
|
|
|
|
boolean filtertrace, boolean haltOnFailure, |
|
|
|
|
|
|
|
|
public JUnitTestRunner(JUnitTest test, boolean haltOnError, |
|
|
|
|
|
boolean filtertrace, boolean haltOnFailure, |
|
|
ClassLoader loader) { |
|
|
ClassLoader loader) { |
|
|
this(test, haltOnError, filtertrace, haltOnFailure, false, loader); |
|
|
this(test, haltOnError, filtertrace, haltOnFailure, false, loader); |
|
|
} |
|
|
} |
|
|
@@ -220,8 +220,8 @@ public class JUnitTestRunner implements TestListener { |
|
|
/** |
|
|
/** |
|
|
* Constructor to use when the user has specified a classpath. |
|
|
* Constructor to use when the user has specified a classpath. |
|
|
*/ |
|
|
*/ |
|
|
public JUnitTestRunner(JUnitTest test, boolean haltOnError, |
|
|
|
|
|
boolean filtertrace, boolean haltOnFailure, |
|
|
|
|
|
|
|
|
public JUnitTestRunner(JUnitTest test, boolean haltOnError, |
|
|
|
|
|
boolean filtertrace, boolean haltOnFailure, |
|
|
boolean showOutput, ClassLoader loader) { |
|
|
boolean showOutput, ClassLoader loader) { |
|
|
this.filtertrace = filtertrace; |
|
|
this.filtertrace = filtertrace; |
|
|
this.junitTest = test; |
|
|
this.junitTest = test; |
|
|
@@ -234,10 +234,9 @@ public class JUnitTestRunner implements TestListener { |
|
|
if (loader == null) { |
|
|
if (loader == null) { |
|
|
testClass = Class.forName(test.getName()); |
|
|
testClass = Class.forName(test.getName()); |
|
|
} else { |
|
|
} else { |
|
|
testClass = loader.loadClass(test.getName()); |
|
|
|
|
|
AntClassLoader.initializeClass(testClass); |
|
|
|
|
|
|
|
|
testClass = Class.forName(test.getName(), true, loader); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Method suiteMethod = null; |
|
|
Method suiteMethod = null; |
|
|
try { |
|
|
try { |
|
|
// check if there is a suite method |
|
|
// check if there is a suite method |
|
|
@@ -258,7 +257,7 @@ public class JUnitTestRunner implements TestListener { |
|
|
// this will generate warnings if the class is no suitable Test |
|
|
// this will generate warnings if the class is no suitable Test |
|
|
suite = new TestSuite(testClass); |
|
|
suite = new TestSuite(testClass); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
retCode = ERRORS; |
|
|
retCode = ERRORS; |
|
|
exception = e; |
|
|
exception = e; |
|
|
@@ -277,7 +276,7 @@ public class JUnitTestRunner implements TestListener { |
|
|
fireStartTestSuite(); |
|
|
fireStartTestSuite(); |
|
|
if (exception != null) { // had an exception in the constructor |
|
|
if (exception != null) { // had an exception in the constructor |
|
|
for (int i = 0; i < formatters.size(); i++) { |
|
|
for (int i = 0; i < formatters.size(); i++) { |
|
|
((TestListener) formatters.elementAt(i)).addError(null, |
|
|
|
|
|
|
|
|
((TestListener) formatters.elementAt(i)).addError(null, |
|
|
exception); |
|
|
exception); |
|
|
} |
|
|
} |
|
|
junitTest.setCounts(1, 0, 1); |
|
|
junitTest.setCounts(1, 0, 1); |
|
|
@@ -287,7 +286,7 @@ public class JUnitTestRunner implements TestListener { |
|
|
|
|
|
|
|
|
ByteArrayOutputStream errStrm = new ByteArrayOutputStream(); |
|
|
ByteArrayOutputStream errStrm = new ByteArrayOutputStream(); |
|
|
systemError = new PrintStream(errStrm); |
|
|
systemError = new PrintStream(errStrm); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteArrayOutputStream outStrm = new ByteArrayOutputStream(); |
|
|
ByteArrayOutputStream outStrm = new ByteArrayOutputStream(); |
|
|
systemOut = new PrintStream(outStrm); |
|
|
systemOut = new PrintStream(outStrm); |
|
|
|
|
|
|
|
|
@@ -306,13 +305,13 @@ public class JUnitTestRunner implements TestListener { |
|
|
) |
|
|
) |
|
|
); |
|
|
); |
|
|
System.setErr(new PrintStream( |
|
|
System.setErr(new PrintStream( |
|
|
new TeeOutputStream(savedErr, |
|
|
|
|
|
|
|
|
new TeeOutputStream(savedErr, |
|
|
systemError) |
|
|
systemError) |
|
|
) |
|
|
) |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
suite.run(res); |
|
|
suite.run(res); |
|
|
@@ -323,7 +322,7 @@ public class JUnitTestRunner implements TestListener { |
|
|
if (savedErr != null) { |
|
|
if (savedErr != null) { |
|
|
System.setErr(savedErr); |
|
|
System.setErr(savedErr); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
systemError.close(); |
|
|
systemError.close(); |
|
|
systemError = null; |
|
|
systemError = null; |
|
|
systemOut.close(); |
|
|
systemOut.close(); |
|
|
@@ -331,7 +330,7 @@ public class JUnitTestRunner implements TestListener { |
|
|
sendOutAndErr(new String(outStrm.toByteArray()), |
|
|
sendOutAndErr(new String(outStrm.toByteArray()), |
|
|
new String(errStrm.toByteArray())); |
|
|
new String(errStrm.toByteArray())); |
|
|
|
|
|
|
|
|
junitTest.setCounts(res.runCount(), res.failureCount(), |
|
|
|
|
|
|
|
|
junitTest.setCounts(res.runCount(), res.failureCount(), |
|
|
res.errorCount()); |
|
|
res.errorCount()); |
|
|
junitTest.setRunTime(System.currentTimeMillis() - start); |
|
|
junitTest.setRunTime(System.currentTimeMillis() - start); |
|
|
} |
|
|
} |
|
|
@@ -404,40 +403,40 @@ public class JUnitTestRunner implements TestListener { |
|
|
systemOut.println(line); |
|
|
systemOut.println(line); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @see Task#handleInput(byte[], int, int) |
|
|
* @see Task#handleInput(byte[], int, int) |
|
|
* |
|
|
|
|
|
|
|
|
* |
|
|
* @since Ant 1.6 |
|
|
* @since Ant 1.6 |
|
|
*/ |
|
|
*/ |
|
|
protected int handleInput(byte[] buffer, int offset, int length) |
|
|
|
|
|
|
|
|
protected int handleInput(byte[] buffer, int offset, int length) |
|
|
throws IOException { |
|
|
throws IOException { |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void handleErrorOutput(String line) { |
|
|
protected void handleErrorOutput(String line) { |
|
|
if (systemError != null) { |
|
|
if (systemError != null) { |
|
|
systemError.println(line); |
|
|
systemError.println(line); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void handleFlush(String line) { |
|
|
protected void handleFlush(String line) { |
|
|
if (systemOut != null) { |
|
|
if (systemOut != null) { |
|
|
systemOut.print(line); |
|
|
systemOut.print(line); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void handleErrorFlush(String line) { |
|
|
protected void handleErrorFlush(String line) { |
|
|
if (systemError != null) { |
|
|
if (systemError != null) { |
|
|
systemError.print(line); |
|
|
systemError.print(line); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void sendOutAndErr(String out, String err) { |
|
|
private void sendOutAndErr(String out, String err) { |
|
|
for (int i = 0; i < formatters.size(); i++) { |
|
|
for (int i = 0; i < formatters.size(); i++) { |
|
|
JUnitResultFormatter formatter = |
|
|
|
|
|
|
|
|
JUnitResultFormatter formatter = |
|
|
((JUnitResultFormatter) formatters.elementAt(i)); |
|
|
((JUnitResultFormatter) formatters.elementAt(i)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
formatter.setSystemOutput(out); |
|
|
formatter.setSystemOutput(out); |
|
|
formatter.setSystemError(err); |
|
|
formatter.setSystemError(err); |
|
|
} |
|
|
} |
|
|
@@ -483,7 +482,7 @@ public class JUnitTestRunner implements TestListener { |
|
|
* <tr><td>showoutput</td><td>send output to System.err/.out as |
|
|
* <tr><td>showoutput</td><td>send output to System.err/.out as |
|
|
* well as to the formatters?</td><td>false</td></tr> |
|
|
* well as to the formatters?</td><td>false</td></tr> |
|
|
* |
|
|
* |
|
|
* </table> |
|
|
|
|
|
|
|
|
* </table> |
|
|
*/ |
|
|
*/ |
|
|
public static void main(String[] args) throws IOException { |
|
|
public static void main(String[] args) throws IOException { |
|
|
boolean haltError = false; |
|
|
boolean haltError = false; |
|
|
@@ -520,9 +519,9 @@ public class JUnitTestRunner implements TestListener { |
|
|
showOut = Project.toBoolean(args[i].substring(11)); |
|
|
showOut = Project.toBoolean(args[i].substring(11)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JUnitTest t = new JUnitTest(args[0]); |
|
|
JUnitTest t = new JUnitTest(args[0]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add/overlay system properties on the properties from the Ant project |
|
|
// Add/overlay system properties on the properties from the Ant project |
|
|
Hashtable p = System.getProperties(); |
|
|
Hashtable p = System.getProperties(); |
|
|
for (Enumeration enum = p.keys(); enum.hasMoreElements();) { |
|
|
for (Enumeration enum = p.keys(); enum.hasMoreElements();) { |
|
|
@@ -563,7 +562,7 @@ public class JUnitTestRunner implements TestListener { |
|
|
} |
|
|
} |
|
|
fromCmdLine.addElement(fe.createFormatter()); |
|
|
fromCmdLine.addElement(fe.createFormatter()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Returns a filtered stack trace. |
|
|
* Returns a filtered stack trace. |
|
|
* This is ripped out of junit.runner.BaseTestRunner. |
|
|
* This is ripped out of junit.runner.BaseTestRunner. |
|
|
@@ -607,5 +606,5 @@ public class JUnitTestRunner implements TestListener { |
|
|
} |
|
|
} |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // JUnitTestRunner |
|
|
} // JUnitTestRunner |