From dd0e8824b463ce3748ee8fdbb4df389586547f20 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 9 Apr 2002 14:04:27 +0000 Subject: [PATCH] capture System.out and System.err and pass it to the formatters in 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 --- .../optional/junit/JUnitTestRunner.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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 d7b123a74..04c956cc9 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 @@ -1,7 +1,7 @@ /* * 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. * * 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 */ 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 * classpath. @@ -261,9 +264,27 @@ public class JUnitTestRunner implements TestListener { ByteArrayOutputStream outStrm = new ByteArrayOutputStream(); 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 { suite.run(res); } finally { + if (savedOut != null) { + System.setOut(savedOut); + } + if (savedErr != null) { + System.setErr(savedOut); + } + systemError.close(); systemError = null; systemOut.close(); @@ -442,6 +463,7 @@ public class JUnitTestRunner implements TestListener { t.setProperties(props); JUnitTestRunner runner = new JUnitTestRunner(t, haltError, stackfilter, haltFail); + runner.forked = true; transferFormatters(runner); runner.run(); System.exit(runner.getRetCode());