Browse Source

Added outputtoformatters attribute to <junit> to allow suppression

of noisey tests. Bugzilla report 12817.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@463045 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 18 years ago
parent
commit
79f24fd579
7 changed files with 98 additions and 25 deletions
  1. +2
    -0
      CONTRIBUTORS
  2. +3
    -0
      WHATSNEW
  3. +8
    -0
      contributors.xml
  4. +9
    -0
      docs/manual/OptionalTasks/junit.html
  5. +1
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java
  6. +28
    -5
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  7. +47
    -20
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java

+ 2
- 0
CONTRIBUTORS View File

@@ -160,6 +160,7 @@ Matt Albrecht
Matt Benson
Matt Bishop
Matt Foemmel
Matt Grosso
Matt Humphrey
Matt Small
Matthew Hawthorne
@@ -244,6 +245,7 @@ Thomas Butz
Thomas Christen
Thomas Christensen
Thomas Haas
Tim Drury
Tim Fennell
Timothy Gerard Endres
Tim Stephenson


+ 3
- 0
WHATSNEW View File

@@ -74,6 +74,9 @@ Other changes:
* Added <compare> resource selector to select resources based on the
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
=============================================



+ 8
- 0
contributors.xml View File

@@ -646,6 +646,10 @@
<first>Matt</first>
<last>Foemmel</last>
</name>
<name>
<first>Matt</first>
<last>Grosso</last>
</name>
<name>
<first>Matt</first>
<last>Humphrey</last>
@@ -969,6 +973,10 @@
<first>Thomas</first>
<last>Haas</last>
</name>
<name>
<first>Tim</first>
<last>Drury</last>
</name>
<name>
<first>Tim</first>
<last>Fennell</last>


+ 9
- 0
docs/manual/OptionalTasks/junit.html View File

@@ -190,6 +190,15 @@ elements</a>).</p>
formatters receive the output.</td>
<td align="center" valign="top">No</td>
</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>
<td valign="top">tempdir</td>
<td valign="top">Where Ant should place temporary files.


+ 1
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java View File

@@ -30,6 +30,7 @@ public class Constants {
static final String BEFORE_FIRST_TEST = "BeforeFirstTest";
static final String PROPSFILE = "propsfile=";
static final String SHOWOUTPUT = "showoutput=";
static final String OUTPUT_TO_FORMATTERS = "outputtoformatters=";
static final String FORMATTER = "formatter=";
static final String LOGTESTLISTENEREVENTS = "logtestlistenerevents=";
static final String TESTSFILE = "testsfile=";


+ 28
- 5
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -145,7 +145,12 @@ public class JUnitTask extends Task {
private boolean includeAntRuntime = true;
private Path antRuntimeClasses = null;

// Do we send output to System.out/.err in addition to the formatters?
private boolean showOutput = false;

// Do we send output to the formatters ?
private boolean outputToFormatters = true;

private File tmpDir;
private AntClassLoader classLoader = null;
private Permissions perm = null;
@@ -549,6 +554,17 @@ public class JUnitTask extends Task {
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)
* @since Ant 1.6
@@ -923,6 +939,9 @@ public class JUnitTask extends Task {

cmd.createArgument().setValue(Constants.SHOWOUTPUT
+ String.valueOf(showOutput));
cmd.createArgument().setValue(Constants.OUTPUT_TO_FORMATTERS
+ String.valueOf(outputToFormatters));
cmd.createArgument().setValue(Constants.LOGTESTLISTENEREVENTS+"true"); // #31885

StringBuffer formatterArg = new StringBuffer(STRING_BUFFER_SIZE);
@@ -964,10 +983,12 @@ public class JUnitTask extends Task {
+ "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.setAntRun(getProject());
if (dir != null) {
@@ -1051,7 +1072,9 @@ public class JUnitTask extends Task {
if (output.startsWith(TESTLISTENER_PREFIX)) {
log(output, Project.MSG_VERBOSE);
} else if (runner != null) {
runner.handleOutput(output);
if (outputToFormatters) {
runner.handleOutput(output);
}
if (showOutput) {
super.handleOutput(output);
}


+ 47
- 20
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java View File

@@ -87,6 +87,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
*/
private boolean showOutput = false;

private boolean outputToFormatters = true;

/**
* The permissions set for the test to run.
*/
@@ -244,23 +246,40 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
PrintStream savedErr = null;

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 {
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 {
if (perm != null) {
perm.setSecurityManager();
@@ -428,7 +447,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
}

private void logTestListenerEvent(String msg) {
PrintStream out = forked ? savedOut : System.out;
PrintStream out = savedOut != null ? savedOut : System.out;
if (logTestListenerEvents) {
out.flush();
out.println(JUnitTask.TESTLISTENER_PREFIX + msg);
@@ -581,6 +600,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
boolean stackfilter = true;
Properties props = new Properties();
boolean showOut = false;
boolean outputToFormat = true;
boolean logTestListenerEvents = false;


@@ -620,6 +640,9 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
showOut = Project.toBoolean(args[i].substring(Constants.SHOWOUTPUT.length()));
} else if (args[i].startsWith(Constants.LOGTESTLISTENEREVENTS)) {
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.setOutfile(st.nextToken());
code = launch(t, haltError, stackfilter, haltFail,
showOut, logTestListenerEvents, props);
showOut, outputToFormat,
logTestListenerEvents, props);
errorOccurred = (code == ERRORS);
failureOccurred = (code != SUCCESS);
if (errorOccurred || failureOccurred) {
@@ -669,7 +693,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
}
} else {
returnCode = launch(new JUnitTest(args[0]), haltError,
stackfilter, haltFail, showOut,
stackfilter, haltFail,
showOut, outputToFormat,
logTestListenerEvents, props);
}

@@ -798,13 +823,15 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
*/
private static int launch(JUnitTest t, boolean haltError,
boolean stackfilter, boolean haltFail,
boolean showOut, boolean logTestListenerEvents,
boolean showOut, boolean outputToFormat,
boolean logTestListenerEvents,
Properties props) {
t.setProperties(props);
JUnitTestRunner runner =
new JUnitTestRunner(t, haltError, stackfilter, haltFail, showOut,
logTestListenerEvents);
logTestListenerEvents, null);
runner.forked = true;
runner.outputToFormatters = outputToFormat;
transferFormatters(runner, t);

runner.run();


Loading…
Cancel
Save