From 79f24fd579a41a9c6a82611e7b9210c0113187da Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Wed, 11 Oct 2006 23:13:08 +0000 Subject: [PATCH] Added outputtoformatters attribute to 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 --- CONTRIBUTORS | 2 + WHATSNEW | 3 + contributors.xml | 8 +++ docs/manual/OptionalTasks/junit.html | 9 +++ .../taskdefs/optional/junit/Constants.java | 1 + .../taskdefs/optional/junit/JUnitTask.java | 33 +++++++-- .../optional/junit/JUnitTestRunner.java | 67 +++++++++++++------ 7 files changed, 98 insertions(+), 25 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 957dd0c57..67a402b7f 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -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 diff --git a/WHATSNEW b/WHATSNEW index 0e28be3a1..ff6c69ca7 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -74,6 +74,9 @@ Other changes: * Added resource selector to select resources based on the results of their comparison to other resources. +* Added outputtoformatters attribute to to allow suppression + of noisey tests. Bugzilla report 12817. + Changes from Ant 1.7.0Beta1 to Ant 1.7.0Beta2 ============================================= diff --git a/contributors.xml b/contributors.xml index 701eb6a0d..f5793f77a 100644 --- a/contributors.xml +++ b/contributors.xml @@ -646,6 +646,10 @@ Matt Foemmel + + Matt + Grosso + Matt Humphrey @@ -969,6 +973,10 @@ Thomas Haas + + Tim + Drury + Tim Fennell diff --git a/docs/manual/OptionalTasks/junit.html b/docs/manual/OptionalTasks/junit.html index 2a980006d..1b5d72f5b 100644 --- a/docs/manual/OptionalTasks/junit.html +++ b/docs/manual/OptionalTasks/junit.html @@ -190,6 +190,15 @@ elements).

formatters receive the output. No + + outputtoformatters + + Since Ant 1.7.0.
+ Send any output generated by tests to the test formatters. + This is "true" by default. + + No + tempdir Where Ant should place temporary files. diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java index e093cb2f0..48b6a6547 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java @@ -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="; diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java index add0ce01b..d935ebfb4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java @@ -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); } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java index 523d42d0d..212a209eb 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java @@ -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();