Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 72942 invoked from network); 18 Apr 2002 09:50:04 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 18 Apr 2002 09:50:04 -0000 Received: (qmail 9351 invoked by uid 97); 18 Apr 2002 09:50:11 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 9333 invoked by uid 97); 18 Apr 2002 09:50:11 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 9308 invoked by uid 97); 18 Apr 2002 09:50:10 -0000 Date: 18 Apr 2002 09:49:55 -0000 Message-ID: <20020418094955.77259.qmail@icarus.apache.org> From: bodewig@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/xdocs ant15_todo.xml X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N bodewig 02/04/18 02:49:55 Modified: . WHATSNEW docs ant15_todo.html docs/manual/OptionalTasks junit.html src/etc/testcases/taskdefs/optional junit.xml src/main/org/apache/tools/ant/taskdefs/optional/junit JUnitTask.java JUnitTestRunner.java xdocs ant15_todo.xml Log: Add new showoutput attribute to . There is no automatic testcase for this, but if your run ant -f src/etc/testcases/taskdefs/optional/junit.xml -Dshowoutput=off ant -f src/etc/testcases/taskdefs/optional/junit.xml -Dshowoutput=on you'll see it in action. Revision Changes Path 1.255 +9 -4 jakarta-ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/jakarta-ant/WHATSNEW,v retrieving revision 1.254 retrieving revision 1.255 diff -u -r1.254 -r1.255 --- WHATSNEW 17 Apr 2002 01:36:50 -0000 1.254 +++ WHATSNEW 18 Apr 2002 09:49:54 -0000 1.255 @@ -4,10 +4,6 @@ Changes that could break older environments: -------------------------------------------- -* Shipped XML parser is now Xerces 2.0.1 along with the XML Parser APIs. - XML Parser APIs is a separate jar that contains the necessary - JAXP/DOM/SAX classes. - * Important: Single $ signs are no longer silently stripped! Before you panic that we have broken all your build files, we have kept the old "$$" -> "$" behaviour. So only build files which accidentally had @@ -16,6 +12,10 @@ build file which works on ant versions 1.4.1 or earlier, stay with the double $$ sign rule. +* Shipped XML parser is now Xerces 2.0.1 along with the XML Parser APIs. + XML Parser APIs is a separate jar that contains the necessary + JAXP/DOM/SAX classes. + * was fixed to expand properties inside nested and elements; before this only happened when you assigned the text to the string attribute. If you had $ signs in the string, they may @@ -320,6 +320,11 @@ * org.apache.tools.ant.XmlLogger now is a BuildLogger, rather than just a BuildListener. It can operate in either mode successfully. + +* has a new attribute "showoutput". If set to true, output + generated by tests will be sent to Ant's logging system as well as + to the formatters (instead of sending it to the formatters + exclusively). Changes from Ant 1.4 to Ant 1.4.1 =========================================== 1.11 +22 -22 jakarta-ant/docs/ant15_todo.html Index: ant15_todo.html =================================================================== RCS file: /home/cvs/jakarta-ant/docs/ant15_todo.html,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ant15_todo.html 17 Apr 2002 01:41:02 -0000 1.10 +++ ant15_todo.html 18 Apr 2002 09:49:54 -0000 1.11 @@ -346,27 +346,6 @@ - JUnit's System.err/.out handling - - - - - Currently this is coupled to SummaryResultFormatter - - no SummaryFormatter, no output. Want to decouple it. - - - - - Stefan, others welcome - - - - - - Make javadoc a real directory based task @@ -494,7 +473,28 @@ - Stefan, others welcome + Stefan + + + + + + + JUnit's System.err/.out handling + + + + + showoutput attribute has been added - doesn't work in + some cases yet (same reason as bug PR 7980) + + + + + Stefan 1.18 +7 -0 jakarta-ant/docs/manual/OptionalTasks/junit.html Index: junit.html =================================================================== RCS file: /home/cvs/jakarta-ant/docs/manual/OptionalTasks/junit.html,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- junit.html 9 Apr 2002 12:13:25 -0000 1.17 +++ junit.html 18 Apr 2002 09:49:54 -0000 1.18 @@ -135,6 +135,13 @@ the tests and JUnit to the classpath in forked mode. No; default is true. + + showoutput + Send any output generated by tests to Ant's + logging system as well as to the formatters. By default only the + formatters receive the output. + No +

By using the errorproperty and failureproperty 1.2 +9 -4 jakarta-ant/src/etc/testcases/taskdefs/optional/junit.xml Index: junit.xml =================================================================== RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/optional/junit.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- junit.xml 16 Apr 2002 15:14:59 -0000 1.1 +++ junit.xml 18 Apr 2002 09:49:54 -0000 1.2 @@ -1,34 +1,39 @@ + - + - + - + - + 1.43 +26 -1 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java Index: JUnitTask.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- JUnitTask.java 16 Apr 2002 14:01:17 -0000 1.42 +++ JUnitTask.java 18 Apr 2002 09:49:54 -0000 1.43 @@ -146,7 +146,7 @@ * @author Gerrit Riessen * @author Erik Hatcher * - * @version $Revision: 1.42 $ + * @version $Revision: 1.43 $ * * @since Ant 1.2 * @@ -172,6 +172,8 @@ private boolean includeAntRuntime = true; private Path antRuntimeClasses = null; + private boolean showOutput = false; + /** * Tells this task whether to smartly filter the stack frames of * JUnit testcase errors and failures before reporting them. @@ -468,6 +470,20 @@ } /** + * Whether to send output of the testcases to Ant's logging system or not. + * + *

Output will always be passed to the formatters and not by + * shown by default. This option should for example be set for + * tests that are interactive and prompt the user to do + * something.

+ * + * @since Ant 1.5 + */ + public void setShowOutput(boolean showOutput) { + this.showOutput = showOutput; + } + + /** * Creates a new JUnitRunner and enables fork of a new Java VM. * * @since Ant 1.2 @@ -590,6 +606,9 @@ .setValue("formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter"); } + cmd.createArgument().setValue("showoutput=" + + String.valueOf(showOutput)); + StringBuffer formatterArg = new StringBuffer(128); final FormatterElement[] feArray = mergeFormatters(test); for (int i = 0; i < feArray.length; i++) { @@ -674,6 +693,9 @@ protected void handleOutput(String line) { if (runner != null) { runner.handleOutput(line); + if (showOutput) { + super.handleOutput(line); + } } else { super.handleOutput(line); } @@ -688,6 +710,9 @@ protected void handleErrorOutput(String line) { if (runner != null) { runner.handleErrorOutput(line); + if (showOutput) { + super.handleErrorOutput(line); + } } else { super.handleErrorOutput(line); } 1.23 +97 -19 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java Index: JUnitTestRunner.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- JUnitTestRunner.java 15 Apr 2002 14:56:33 -0000 1.22 +++ JUnitTestRunner.java 18 Apr 2002 09:49:54 -0000 1.23 @@ -65,19 +65,20 @@ import junit.framework.TestSuite; import junit.framework.AssertionFailedError; import java.lang.reflect.Method; + import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.OutputStream; import java.io.PrintStream; import java.io.PrintWriter; import java.io.StringReader; import java.io.StringWriter; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.FileInputStream; -import java.io.File; import java.util.Enumeration; import java.util.Hashtable; import java.util.Properties; - import java.util.Vector; /** @@ -90,13 +91,15 @@ * public static junit.framework.Test suite() * * - *

If no such method exists, all public methods starting with "test" and taking no - * argument will be run. + *

If no such method exists, all public methods starting with + * "test" and taking no argument will be run. * *

Summary output is generated at the end. * * @author Stefan Bodewig * @author Erik Hatcher + * + * @since Ant 1.2 */ public class JUnitTestRunner implements TestListener { @@ -131,6 +134,11 @@ */ private static boolean filtertrace = true; + /** + * Do we send output to System.out/.err in addition to the formatters? + */ + private boolean showOutput = false; + private static final String[] DEFAULT_TRACE_FILTERS = new String[] { "junit.framework.TestCase", "junit.framework.TestResult", @@ -187,20 +195,41 @@ * Constructor for fork=true or when the user hasn't specified a * classpath. */ - public JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean filtertrace, - boolean haltOnFailure) { - this(test, haltOnError, filtertrace, haltOnFailure, null); + public JUnitTestRunner(JUnitTest test, boolean haltOnError, + boolean filtertrace, boolean haltOnFailure) { + this(test, haltOnError, filtertrace, haltOnFailure, false); + } + + /** + * Constructor for fork=true or when the user hasn't specified a + * classpath. + */ + public JUnitTestRunner(JUnitTest test, boolean haltOnError, + boolean filtertrace, boolean haltOnFailure, + boolean showOutput) { + this(test, haltOnError, filtertrace, haltOnFailure, showOutput, null); } /** * Constructor to use when the user has specified a classpath. */ - public JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean filtertrace, - boolean haltOnFailure, ClassLoader loader) { + public JUnitTestRunner(JUnitTest test, boolean haltOnError, + boolean filtertrace, boolean haltOnFailure, + ClassLoader loader) { + this(test, haltOnError, filtertrace, haltOnFailure, false, loader); + } + + /** + * Constructor to use when the user has specified a classpath. + */ + public JUnitTestRunner(JUnitTest test, boolean haltOnError, + boolean filtertrace, boolean haltOnFailure, + boolean showOutput, ClassLoader loader) { this.filtertrace = filtertrace; this.junitTest = test; this.haltOnError = haltOnError; this.haltOnFailure = haltOnFailure; + this.showOutput = showOutput; try { Class testClass = null; @@ -269,9 +298,26 @@ if (forked) { savedOut = System.out; - System.setOut(systemOut); savedErr = System.err; - System.setErr(systemError); + if (!showOutput) { + System.setOut(systemOut); + System.setErr(systemError); + } else { + System.setOut(new PrintStream( + new TeeOutputStream( + new OutputStream[] {savedOut, + systemOut} + ) + ) + ); + System.setErr(new PrintStream( + new TeeOutputStream( + new OutputStream[] {savedErr, + systemError} + ) + ) + ); + } } @@ -384,13 +430,15 @@ private void fireStartTestSuite() { for (int i = 0; i < formatters.size(); i++) { - ((JUnitResultFormatter) formatters.elementAt(i)).startTestSuite(junitTest); + ((JUnitResultFormatter) formatters.elementAt(i)) + .startTestSuite(junitTest); } } private void fireEndTestSuite() { for (int i = 0; i < formatters.size(); i++) { - ((JUnitResultFormatter) formatters.elementAt(i)).endTestSuite(junitTest); + ((JUnitResultFormatter) formatters.elementAt(i)) + .endTestSuite(junitTest); } } @@ -417,6 +465,9 @@ * classname,filename. If filename is ommitted, System.out is * assumed.none * + * showoutputsend output to System.err/.out as + * well as to the formatters?false + * * */ public static void main(String[] args) throws IOException { @@ -425,6 +476,7 @@ boolean haltFail = false; boolean stackfilter = true; Properties props = new Properties(); + boolean showOut = false; if (args.length == 0) { System.err.println("required argument TestClassName missing"); @@ -446,9 +498,12 @@ System.exit(ERRORS); } } else if (args[i].startsWith("propsfile=")) { - FileInputStream in = new FileInputStream(args[i].substring(10)); + FileInputStream in = new FileInputStream(args[i] + .substring(10)); props.load(in); in.close(); + } else if (args[i].startsWith("showoutput=")) { + showOut = Project.toBoolean(args[i].substring(11)); } } @@ -462,7 +517,8 @@ } t.setProperties(props); - JUnitTestRunner runner = new JUnitTestRunner(t, haltError, stackfilter, haltFail); + JUnitTestRunner runner = new JUnitTestRunner(t, haltError, stackfilter, + haltFail, showOut); runner.forked = true; transferFormatters(runner); runner.run(); @@ -473,7 +529,8 @@ private static void transferFormatters(JUnitTestRunner runner) { for (int i = 0; i < fromCmdLine.size(); i++) { - runner.addFormatter((JUnitResultFormatter) fromCmdLine.elementAt(i)); + runner.addFormatter((JUnitResultFormatter) fromCmdLine + .elementAt(i)); } } @@ -537,4 +594,25 @@ return false; } + /** + * Helper class that sends output sent to multiple streams. + * + * @since Ant 1.5 + */ + private class TeeOutputStream extends OutputStream { + + private OutputStream[] outs; + + private TeeOutputStream(OutputStream[] outs) { + this.outs = outs; + } + + public void write(int b) throws IOException { + for (int i = 0; i < outs.length; i++) { + outs[i].write(b); + } + } + + } + } // JUnitTestRunner 1.11 +8 -8 jakarta-ant/xdocs/ant15_todo.xml Index: ant15_todo.xml =================================================================== RCS file: /home/cvs/jakarta-ant/xdocs/ant15_todo.xml,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ant15_todo.xml 17 Apr 2002 01:41:02 -0000 1.10 +++ ant15_todo.xml 18 Apr 2002 09:49:55 -0000 1.11 @@ -90,13 +90,6 @@ - JUnit's System.err/.out handling - Currently this is coupled to SummaryResultFormatter - - no SummaryFormatter, no output. Want to decouple it. - Stefan, others welcome - - - Make javadoc a real directory based task Stefan, others welcome @@ -141,8 +134,15 @@ PGP signing task if possible Not done, but deemed impossible - at least in the 1.5 time frame. - Stefan, others welcome + Stefan + + + JUnit's System.err/.out handling + showoutput attribute has been added - doesn't work in + some cases yet (same reason as bug PR 7980) + Stefan + -- To unsubscribe, e-mail: For additional commands, e-mail: