Browse Source

capture System.out and System.err and pass it to the formatters in

<junit> with fork=yes as well.

PR: 5377


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272315 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
dd0e8824b4
1 changed files with 23 additions and 1 deletions
  1. +23
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java

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

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -180,6 +180,9 @@ public class JUnitTestRunner implements TestListener {
/** Error output during the test */ /** Error output during the test */
private PrintStream systemOut; private PrintStream systemOut;
/** is this runner running in forked mode? */
private boolean forked = false;

/** /**
* Constructor for fork=true or when the user hasn't specified a * Constructor for fork=true or when the user hasn't specified a
* classpath. * classpath.
@@ -261,9 +264,27 @@ public class JUnitTestRunner implements TestListener {
ByteArrayOutputStream outStrm = new ByteArrayOutputStream(); ByteArrayOutputStream outStrm = new ByteArrayOutputStream();
systemOut = new PrintStream(outStrm); systemOut = new PrintStream(outStrm);


PrintStream savedOut = null;
PrintStream savedErr = null;

if (forked) {
savedOut = System.out;
System.setOut(systemOut);
savedErr = System.err;
System.setErr(systemError);
}

try { try {
suite.run(res); suite.run(res);
} finally { } finally {
if (savedOut != null) {
System.setOut(savedOut);
}
if (savedErr != null) {
System.setErr(savedOut);
}
systemError.close(); systemError.close();
systemError = null; systemError = null;
systemOut.close(); systemOut.close();
@@ -442,6 +463,7 @@ public class JUnitTestRunner implements TestListener {
t.setProperties(props); t.setProperties(props);


JUnitTestRunner runner = new JUnitTestRunner(t, haltError, stackfilter, haltFail); JUnitTestRunner runner = new JUnitTestRunner(t, haltError, stackfilter, haltFail);
runner.forked = true;
transferFormatters(runner); transferFormatters(runner);
runner.run(); runner.run();
System.exit(runner.getRetCode()); System.exit(runner.getRetCode());


Loading…
Cancel
Save