of noisey tests. Bugzilla report 12817. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@463045 13f79535-47bb-0310-9956-ffa450edef68master
@@ -160,6 +160,7 @@ Matt Albrecht | |||||
Matt Benson | Matt Benson | ||||
Matt Bishop | Matt Bishop | ||||
Matt Foemmel | Matt Foemmel | ||||
Matt Grosso | |||||
Matt Humphrey | Matt Humphrey | ||||
Matt Small | Matt Small | ||||
Matthew Hawthorne | Matthew Hawthorne | ||||
@@ -244,6 +245,7 @@ Thomas Butz | |||||
Thomas Christen | Thomas Christen | ||||
Thomas Christensen | Thomas Christensen | ||||
Thomas Haas | Thomas Haas | ||||
Tim Drury | |||||
Tim Fennell | Tim Fennell | ||||
Timothy Gerard Endres | Timothy Gerard Endres | ||||
Tim Stephenson | Tim Stephenson | ||||
@@ -74,6 +74,9 @@ Other changes: | |||||
* Added <compare> resource selector to select resources based on the | * Added <compare> resource selector to select resources based on the | ||||
results of their comparison to other resources. | results of their comparison to other resources. | ||||
* Added outputtoformatters attribute to <junit> to allow suppression | |||||
of noisey tests. Bugzilla report 12817. | |||||
Changes from Ant 1.7.0Beta1 to Ant 1.7.0Beta2 | Changes from Ant 1.7.0Beta1 to Ant 1.7.0Beta2 | ||||
============================================= | ============================================= | ||||
@@ -646,6 +646,10 @@ | |||||
<first>Matt</first> | <first>Matt</first> | ||||
<last>Foemmel</last> | <last>Foemmel</last> | ||||
</name> | </name> | ||||
<name> | |||||
<first>Matt</first> | |||||
<last>Grosso</last> | |||||
</name> | |||||
<name> | <name> | ||||
<first>Matt</first> | <first>Matt</first> | ||||
<last>Humphrey</last> | <last>Humphrey</last> | ||||
@@ -969,6 +973,10 @@ | |||||
<first>Thomas</first> | <first>Thomas</first> | ||||
<last>Haas</last> | <last>Haas</last> | ||||
</name> | </name> | ||||
<name> | |||||
<first>Tim</first> | |||||
<last>Drury</last> | |||||
</name> | |||||
<name> | <name> | ||||
<first>Tim</first> | <first>Tim</first> | ||||
<last>Fennell</last> | <last>Fennell</last> | ||||
@@ -190,6 +190,15 @@ elements</a>).</p> | |||||
formatters receive the output.</td> | formatters receive the output.</td> | ||||
<td align="center" valign="top">No</td> | <td align="center" valign="top">No</td> | ||||
</tr> | </tr> | ||||
<tr> | |||||
<td valign="top">outputtoformatters</td> | |||||
<td valign="top"> | |||||
<em>Since Ant 1.7.0.</em><br/> | |||||
Send any output generated by tests to the test formatters. | |||||
This is "true" by default. | |||||
</td> | |||||
<td align="center" valign="top">No</td> | |||||
</tr> | |||||
<tr> | <tr> | ||||
<td valign="top">tempdir</td> | <td valign="top">tempdir</td> | ||||
<td valign="top">Where Ant should place temporary files. | <td valign="top">Where Ant should place temporary files. | ||||
@@ -30,6 +30,7 @@ public class Constants { | |||||
static final String BEFORE_FIRST_TEST = "BeforeFirstTest"; | static final String BEFORE_FIRST_TEST = "BeforeFirstTest"; | ||||
static final String PROPSFILE = "propsfile="; | static final String PROPSFILE = "propsfile="; | ||||
static final String SHOWOUTPUT = "showoutput="; | static final String SHOWOUTPUT = "showoutput="; | ||||
static final String OUTPUT_TO_FORMATTERS = "outputtoformatters="; | |||||
static final String FORMATTER = "formatter="; | static final String FORMATTER = "formatter="; | ||||
static final String LOGTESTLISTENEREVENTS = "logtestlistenerevents="; | static final String LOGTESTLISTENEREVENTS = "logtestlistenerevents="; | ||||
static final String TESTSFILE = "testsfile="; | static final String TESTSFILE = "testsfile="; | ||||
@@ -145,7 +145,12 @@ public class JUnitTask extends Task { | |||||
private boolean includeAntRuntime = true; | private boolean includeAntRuntime = true; | ||||
private Path antRuntimeClasses = null; | private Path antRuntimeClasses = null; | ||||
// Do we send output to System.out/.err in addition to the formatters? | |||||
private boolean showOutput = false; | private boolean showOutput = false; | ||||
// Do we send output to the formatters ? | |||||
private boolean outputToFormatters = true; | |||||
private File tmpDir; | private File tmpDir; | ||||
private AntClassLoader classLoader = null; | private AntClassLoader classLoader = null; | ||||
private Permissions perm = null; | private Permissions perm = null; | ||||
@@ -549,6 +554,17 @@ public class JUnitTask extends Task { | |||||
this.showOutput = showOutput; | this.showOutput = showOutput; | ||||
} | } | ||||
/** | |||||
* If true, send any output generated by tests to the formatters. | |||||
* | |||||
* @param outputToFormatters if true, send output to formatters (Default | |||||
* is true). | |||||
* @since Ant 1.7.0 | |||||
*/ | |||||
public void setOutputToFormatters(boolean outputToFormatters) { | |||||
this.outputToFormatters = outputToFormatters; | |||||
} | |||||
/** | /** | ||||
* Assertions to enable in this program (if fork=true) | * Assertions to enable in this program (if fork=true) | ||||
* @since Ant 1.6 | * @since Ant 1.6 | ||||
@@ -923,6 +939,9 @@ public class JUnitTask extends Task { | |||||
cmd.createArgument().setValue(Constants.SHOWOUTPUT | cmd.createArgument().setValue(Constants.SHOWOUTPUT | ||||
+ String.valueOf(showOutput)); | + String.valueOf(showOutput)); | ||||
cmd.createArgument().setValue(Constants.OUTPUT_TO_FORMATTERS | |||||
+ String.valueOf(outputToFormatters)); | |||||
cmd.createArgument().setValue(Constants.LOGTESTLISTENEREVENTS+"true"); // #31885 | cmd.createArgument().setValue(Constants.LOGTESTLISTENEREVENTS+"true"); // #31885 | ||||
StringBuffer formatterArg = new StringBuffer(STRING_BUFFER_SIZE); | StringBuffer formatterArg = new StringBuffer(STRING_BUFFER_SIZE); | ||||
@@ -964,10 +983,12 @@ public class JUnitTask extends Task { | |||||
+ "file.", e, getLocation()); | + "file.", e, getLocation()); | ||||
} | } | ||||
Execute execute = new Execute(new JUnitLogStreamHandler(this, | |||||
Project.MSG_INFO, | |||||
Project.MSG_WARN), | |||||
watchdog); | |||||
Execute execute = new Execute( | |||||
new JUnitLogStreamHandler( | |||||
this, | |||||
Project.MSG_INFO, | |||||
Project.MSG_WARN), | |||||
watchdog); | |||||
execute.setCommandline(cmd.getCommandline()); | execute.setCommandline(cmd.getCommandline()); | ||||
execute.setAntRun(getProject()); | execute.setAntRun(getProject()); | ||||
if (dir != null) { | if (dir != null) { | ||||
@@ -1051,7 +1072,9 @@ public class JUnitTask extends Task { | |||||
if (output.startsWith(TESTLISTENER_PREFIX)) { | if (output.startsWith(TESTLISTENER_PREFIX)) { | ||||
log(output, Project.MSG_VERBOSE); | log(output, Project.MSG_VERBOSE); | ||||
} else if (runner != null) { | } else if (runner != null) { | ||||
runner.handleOutput(output); | |||||
if (outputToFormatters) { | |||||
runner.handleOutput(output); | |||||
} | |||||
if (showOutput) { | if (showOutput) { | ||||
super.handleOutput(output); | super.handleOutput(output); | ||||
} | } | ||||
@@ -87,6 +87,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||||
*/ | */ | ||||
private boolean showOutput = false; | private boolean showOutput = false; | ||||
private boolean outputToFormatters = true; | |||||
/** | /** | ||||
* The permissions set for the test to run. | * The permissions set for the test to run. | ||||
*/ | */ | ||||
@@ -244,23 +246,40 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||||
PrintStream savedErr = null; | PrintStream savedErr = null; | ||||
if (forked) { | if (forked) { | ||||
savedOut = System.out; | |||||
savedErr = System.err; | |||||
if (!showOutput) { | |||||
System.setOut(systemOut); | |||||
System.setErr(systemError); | |||||
if (!outputToFormatters) { | |||||
if (!showOutput) { | |||||
savedOut = System.out; | |||||
savedErr = System.err; | |||||
System.setOut( | |||||
new PrintStream( | |||||
new OutputStream() { | |||||
public void write(int b) {} | |||||
})); | |||||
System.setErr( | |||||
new PrintStream( | |||||
new OutputStream() { | |||||
public void write(int b) {} | |||||
})); | |||||
} | |||||
} else { | } else { | ||||
System.setOut(new PrintStream( | |||||
new TeeOutputStream(savedOut, systemOut) | |||||
) | |||||
); | |||||
System.setErr(new PrintStream( | |||||
new TeeOutputStream(savedErr, | |||||
systemError) | |||||
) | |||||
); | |||||
savedOut = System.out; | |||||
savedErr = System.err; | |||||
if (!showOutput) { | |||||
System.setOut(systemOut); | |||||
System.setErr(systemError); | |||||
} else { | |||||
System.setOut(new PrintStream( | |||||
new TeeOutputStream(savedOut, systemOut) | |||||
) | |||||
); | |||||
System.setErr(new PrintStream( | |||||
new TeeOutputStream(savedErr, | |||||
systemError) | |||||
) | |||||
); | |||||
} | |||||
perm = null; | |||||
} | } | ||||
perm = null; | |||||
} else { | } else { | ||||
if (perm != null) { | if (perm != null) { | ||||
perm.setSecurityManager(); | perm.setSecurityManager(); | ||||
@@ -428,7 +447,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||||
} | } | ||||
private void logTestListenerEvent(String msg) { | private void logTestListenerEvent(String msg) { | ||||
PrintStream out = forked ? savedOut : System.out; | |||||
PrintStream out = savedOut != null ? savedOut : System.out; | |||||
if (logTestListenerEvents) { | if (logTestListenerEvents) { | ||||
out.flush(); | out.flush(); | ||||
out.println(JUnitTask.TESTLISTENER_PREFIX + msg); | out.println(JUnitTask.TESTLISTENER_PREFIX + msg); | ||||
@@ -581,6 +600,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||||
boolean stackfilter = true; | boolean stackfilter = true; | ||||
Properties props = new Properties(); | Properties props = new Properties(); | ||||
boolean showOut = false; | boolean showOut = false; | ||||
boolean outputToFormat = true; | |||||
boolean logTestListenerEvents = false; | boolean logTestListenerEvents = false; | ||||
@@ -620,6 +640,9 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||||
showOut = Project.toBoolean(args[i].substring(Constants.SHOWOUTPUT.length())); | showOut = Project.toBoolean(args[i].substring(Constants.SHOWOUTPUT.length())); | ||||
} else if (args[i].startsWith(Constants.LOGTESTLISTENEREVENTS)) { | } else if (args[i].startsWith(Constants.LOGTESTLISTENEREVENTS)) { | ||||
logTestListenerEvents = Project.toBoolean(args[i].substring(Constants.LOGTESTLISTENEREVENTS.length())); | logTestListenerEvents = Project.toBoolean(args[i].substring(Constants.LOGTESTLISTENEREVENTS.length())); | ||||
} else if (args[i].startsWith(Constants.OUTPUT_TO_FORMATTERS)) { | |||||
outputToFormat = Project.toBoolean( | |||||
args[i].substring(Constants.OUTPUT_TO_FORMATTERS.length())); | |||||
} | } | ||||
} | } | ||||
@@ -647,7 +670,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||||
t.setTodir(new File(st.nextToken())); | t.setTodir(new File(st.nextToken())); | ||||
t.setOutfile(st.nextToken()); | t.setOutfile(st.nextToken()); | ||||
code = launch(t, haltError, stackfilter, haltFail, | code = launch(t, haltError, stackfilter, haltFail, | ||||
showOut, logTestListenerEvents, props); | |||||
showOut, outputToFormat, | |||||
logTestListenerEvents, props); | |||||
errorOccurred = (code == ERRORS); | errorOccurred = (code == ERRORS); | ||||
failureOccurred = (code != SUCCESS); | failureOccurred = (code != SUCCESS); | ||||
if (errorOccurred || failureOccurred) { | if (errorOccurred || failureOccurred) { | ||||
@@ -669,7 +693,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||||
} | } | ||||
} else { | } else { | ||||
returnCode = launch(new JUnitTest(args[0]), haltError, | returnCode = launch(new JUnitTest(args[0]), haltError, | ||||
stackfilter, haltFail, showOut, | |||||
stackfilter, haltFail, | |||||
showOut, outputToFormat, | |||||
logTestListenerEvents, props); | logTestListenerEvents, props); | ||||
} | } | ||||
@@ -798,13 +823,15 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||||
*/ | */ | ||||
private static int launch(JUnitTest t, boolean haltError, | private static int launch(JUnitTest t, boolean haltError, | ||||
boolean stackfilter, boolean haltFail, | boolean stackfilter, boolean haltFail, | ||||
boolean showOut, boolean logTestListenerEvents, | |||||
boolean showOut, boolean outputToFormat, | |||||
boolean logTestListenerEvents, | |||||
Properties props) { | Properties props) { | ||||
t.setProperties(props); | t.setProperties(props); | ||||
JUnitTestRunner runner = | JUnitTestRunner runner = | ||||
new JUnitTestRunner(t, haltError, stackfilter, haltFail, showOut, | new JUnitTestRunner(t, haltError, stackfilter, haltFail, showOut, | ||||
logTestListenerEvents); | |||||
logTestListenerEvents, null); | |||||
runner.forked = true; | runner.forked = true; | ||||
runner.outputToFormatters = outputToFormat; | |||||
transferFormatters(runner, t); | transferFormatters(runner, t); | ||||
runner.run(); | runner.run(); | ||||