Author: peterreilly Date: Thu Aug 16 07:22:15 2007 New Revision: 566727 URL: http://svn.apache.org/viewvc?view=rev&rev=566727 Log: sync
Modified: ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java Modified: ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java URL: http://svn.apache.org/viewvc/ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java?view=diff&rev=566727&r1=566726&r2=566727 ============================================================================== --- ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java (original) +++ ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java Thu Aug 16 07:22:15 2007 @@ -262,42 +262,32 @@ } private PrintStream savedOut = null; + private PrintStream savedErr = null; - /** - * Run the test. - */ - public void run() { - res = new TestResult(); - res.addListener(wrapListener(this)); - for (int i = 0; i < formatters.size(); i++) { - res.addListener(wrapListener((TestListener) formatters.elementAt(i))); - } - - ByteArrayOutputStream errStrm = new ByteArrayOutputStream(); - systemError = new PrintStream(errStrm); + private PrintStream createEmptyStream() { + return new PrintStream( + new OutputStream() { + public void write(int b) { + } + }); + } - ByteArrayOutputStream outStrm = new ByteArrayOutputStream(); - systemOut = new PrintStream(outStrm); + private PrintStream createTeePrint(PrintStream ps1, PrintStream ps2) { + return new PrintStream(new TeeOutputStream(ps1, ps2)); + } - PrintStream savedErr = null; + private void setupIOStreams(ByteArrayOutputStream o, + ByteArrayOutputStream e) { + systemOut = new PrintStream(o); + systemError = new PrintStream(e); if (forked) { 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) { - } - })); + System.setOut(createEmptyStream()); + System.setErr(createEmptyStream()); } } else { savedOut = System.out; @@ -306,15 +296,8 @@ System.setOut(systemOut); System.setErr(systemError); } else { - System.setOut(new PrintStream( - new TeeOutputStream(savedOut, systemOut) - ) - ); - System.setErr(new PrintStream( - new TeeOutputStream(savedErr, - systemError) - ) - ); + System.setOut(createTeePrint(savedOut, systemOut)); + System.setErr(createTeePrint(savedErr, systemError)); } perm = null; } @@ -323,6 +306,22 @@ perm.setSecurityManager(); } } + } + + /** + * Run the test. + */ + public void run() { + res = new TestResult(); + res.addListener(wrapListener(this)); + for (int i = 0; i < formatters.size(); i++) { + res.addListener(wrapListener((TestListener) formatters.elementAt(i))); + } + + ByteArrayOutputStream errStrm = new ByteArrayOutputStream(); + ByteArrayOutputStream outStrm = new ByteArrayOutputStream(); + + setupIOStreams(outStrm, errStrm); Test suite = null; Throwable exception = null; @@ -740,9 +739,10 @@ JUnitTest t = new JUnitTest(testCaseName); t.setTodir(new File(st.nextToken())); t.setOutfile(st.nextToken()); + t.setProperties(props); code = launch(t, haltError, stackfilter, haltFail, showOut, outputToFormat, - logTestListenerEvents, props); + logTestListenerEvents); errorOccurred = (code == ERRORS); failureOccurred = (code != SUCCESS); if (errorOccurred || failureOccurred) { @@ -763,10 +763,11 @@ e.printStackTrace(); } } else { - returnCode = launch(new JUnitTest(args[0]), haltError, - stackfilter, haltFail, - showOut, outputToFormat, - logTestListenerEvents, props); + JUnitTest t = new JUnitTest(args[0]); + t.setProperties(props); + returnCode = launch( + t, haltError, stackfilter, haltFail, + showOut, outputToFormat, logTestListenerEvents); } registerNonCrash(); @@ -899,9 +900,7 @@ private static int launch(JUnitTest t, boolean haltError, boolean stackfilter, boolean haltFail, boolean showOut, boolean outputToFormat, - boolean logTestListenerEvents, - Properties props) { - t.setProperties(props); + boolean logTestListenerEvents) { JUnitTestRunner runner = new JUnitTestRunner(t, haltError, stackfilter, haltFail, showOut, logTestListenerEvents, null); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]