Author: peterreilly Date: Wed Oct 11 16:13:08 2006 New Revision: 463045 URL: http://svn.apache.org/viewvc?view=rev&rev=463045 Log: Added outputtoformatters attribute to <junit> to allow suppression of noisey tests. Bugzilla report 12817.
Modified: ant/core/trunk/CONTRIBUTORS ant/core/trunk/WHATSNEW ant/core/trunk/contributors.xml ant/core/trunk/docs/manual/OptionalTasks/junit.html ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java Modified: ant/core/trunk/CONTRIBUTORS URL: http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?view=diff&rev=463045&r1=463044&r2=463045 ============================================================================== Binary files - no diff available. Modified: ant/core/trunk/WHATSNEW URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=463045&r1=463044&r2=463045 ============================================================================== --- ant/core/trunk/WHATSNEW (original) +++ ant/core/trunk/WHATSNEW Wed Oct 11 16:13:08 2006 @@ -74,6 +74,9 @@ * 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 ============================================= Modified: ant/core/trunk/contributors.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?view=diff&rev=463045&r1=463044&r2=463045 ============================================================================== --- ant/core/trunk/contributors.xml (original) +++ ant/core/trunk/contributors.xml Wed Oct 11 16:13:08 2006 @@ -648,6 +648,10 @@ </name> <name> <first>Matt</first> + <last>Grosso</last> + </name> + <name> + <first>Matt</first> <last>Humphrey</last> </name> <name> @@ -968,6 +972,10 @@ <name> <first>Thomas</first> <last>Haas</last> + </name> + <name> + <first>Tim</first> + <last>Drury</last> </name> <name> <first>Tim</first> Modified: ant/core/trunk/docs/manual/OptionalTasks/junit.html URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/OptionalTasks/junit.html?view=diff&rev=463045&r1=463044&r2=463045 ============================================================================== --- ant/core/trunk/docs/manual/OptionalTasks/junit.html (original) +++ ant/core/trunk/docs/manual/OptionalTasks/junit.html Wed Oct 11 16:13:08 2006 @@ -191,6 +191,15 @@ <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. <em>Since Ant 1.6</em>.</td> Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java?view=diff&rev=463045&r1=463044&r2=463045 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java Wed Oct 11 16:13:08 2006 @@ -30,6 +30,7 @@ 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="; Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java?view=diff&rev=463045&r1=463044&r2=463045 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java Wed Oct 11 16:13:08 2006 @@ -145,7 +145,12 @@ 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; @@ -550,6 +555,17 @@ } /** + * 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 * @param asserts assertion set @@ -923,6 +939,9 @@ 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 @@ + "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 @@ 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); } Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java?view=diff&rev=463045&r1=463044&r2=463045 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java Wed Oct 11 16:13:08 2006 @@ -87,6 +87,8 @@ */ private boolean showOutput = false; + private boolean outputToFormatters = true; + /** * The permissions set for the test to run. */ @@ -244,23 +246,40 @@ 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 @@ } 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 @@ boolean stackfilter = true; Properties props = new Properties(); boolean showOut = false; + boolean outputToFormat = true; boolean logTestListenerEvents = false; @@ -620,6 +640,9 @@ 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 @@ 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 @@ } } else { returnCode = launch(new JUnitTest(args[0]), haltError, - stackfilter, haltFail, showOut, + stackfilter, haltFail, + showOut, outputToFormat, logTestListenerEvents, props); } @@ -798,13 +823,15 @@ */ 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(); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]