From 6d852e1f30ef9e704dbd88aefae60ad632ad3541 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Wed, 29 Mar 2017 17:14:40 +0200 Subject: Fix #2147: redirect both java and scala std out/err --- compiler/foo | 0 .../test/dotty/tools/dotc/ParallelTestTests.scala | 3 +++ .../test/dotty/tools/dotc/ParallelTesting.scala | 23 ++++++++++++++++++---- tests/partest-test/i2147.check | 3 +++ tests/partest-test/i2147.scala | 7 +++++++ tests/run/i2147.check | 3 +++ tests/run/i2147.scala | 7 +++++++ 7 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 compiler/foo create mode 100644 tests/partest-test/i2147.check create mode 100644 tests/partest-test/i2147.scala create mode 100644 tests/run/i2147.check create mode 100644 tests/run/i2147.scala diff --git a/compiler/foo b/compiler/foo new file mode 100644 index 000000000..e69de29bb diff --git a/compiler/test/dotty/tools/dotc/ParallelTestTests.scala b/compiler/test/dotty/tools/dotc/ParallelTestTests.scala index 9964be036..cfb108ea7 100644 --- a/compiler/test/dotty/tools/dotc/ParallelTestTests.scala +++ b/compiler/test/dotty/tools/dotc/ParallelTestTests.scala @@ -52,4 +52,7 @@ class ParallelTestTests extends ParallelTesting { @Test def runStackOverflow: Unit = compileFile("../tests/partest-test/stackOverflow.scala", defaultOptions).expectFailure.checkRuns() + + @Test def runOutRedirects: Unit = + compileFile("../tests/partest-test/i2147.scala", defaultOptions).expectFailure.checkRuns() } diff --git a/compiler/test/dotty/tools/dotc/ParallelTesting.scala b/compiler/test/dotty/tools/dotc/ParallelTesting.scala index 30679de9e..06105b043 100644 --- a/compiler/test/dotty/tools/dotc/ParallelTesting.scala +++ b/compiler/test/dotty/tools/dotc/ParallelTesting.scala @@ -28,7 +28,7 @@ import dotc.util.DiffUtil * using this, you should be running your JUnit tests **sequentially**, as the * test suite itself runs with a high level of concurrency. */ -trait ParallelTesting { +trait ParallelTesting { self => import ParallelTesting._ import ParallelSummaryReport._ @@ -399,18 +399,33 @@ trait ParallelTesting { .takeWhile(_.getMethodName != "invoke0") .mkString(" ", "\n ", "") - import java.io.ByteArrayOutputStream + import java.io.{ ByteArrayOutputStream, PrintStream } import java.net.{ URL, URLClassLoader } val printStream = new ByteArrayOutputStream + val oldOut = System.out + val oldErr = System.out + try { // Do classloading magic and running here: val ucl = new URLClassLoader(Array(dir.toURI.toURL)) val cls = ucl.loadClass("Test") val meth = cls.getMethod("main", classOf[Array[String]]) - Console.withOut(printStream) { - meth.invoke(null, Array("jvm")) // partest passes at least "jvm" as an arg + self.synchronized { + try { + val ps = new PrintStream(printStream) + System.setOut(ps) + System.setErr(ps) + Console.withOut(printStream) { + Console.withErr(printStream) { + meth.invoke(null, Array("jvm")) // partest passes at least "jvm" as an arg + } + } + } finally { + System.setOut(oldOut) + System.setErr(oldErr) + } } } catch { diff --git a/tests/partest-test/i2147.check b/tests/partest-test/i2147.check new file mode 100644 index 000000000..64a4b735b --- /dev/null +++ b/tests/partest-test/i2147.check @@ -0,0 +1,3 @@ +Felix is number 1 +ducksarethebest.org +foolsRus.org diff --git a/tests/partest-test/i2147.scala b/tests/partest-test/i2147.scala new file mode 100644 index 000000000..dd9839838 --- /dev/null +++ b/tests/partest-test/i2147.scala @@ -0,0 +1,7 @@ +object Test { + def main(args: Array[String]): Unit = { + println("Guillaume is number 1") + System.out.println("ducksarethebest.com") + System.err.println("foolsRus.com") + } +} diff --git a/tests/run/i2147.check b/tests/run/i2147.check new file mode 100644 index 000000000..f704ab00e --- /dev/null +++ b/tests/run/i2147.check @@ -0,0 +1,3 @@ +before +42 +lol diff --git a/tests/run/i2147.scala b/tests/run/i2147.scala new file mode 100644 index 000000000..f8e9f2181 --- /dev/null +++ b/tests/run/i2147.scala @@ -0,0 +1,7 @@ +object Test { + def main(args: Array[String]): Unit = { + println("before") + System.out.println("42") + println("lol") + } +} -- cgit v1.2.3