Skip to content

Commit 97e241c

Browse files
Merge pull request #2148 from dotty-staging/topic/fix-#2147
Fix #2147: redirect both java and scala std out/err
2 parents f49c10d + 6d852e1 commit 97e241c

File tree

7 files changed

+42
-4
lines changed

7 files changed

+42
-4
lines changed

compiler/foo

Whitespace-only changes.

compiler/test/dotty/tools/dotc/ParallelTestTests.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,7 @@ class ParallelTestTests extends ParallelTesting {
5252

5353
@Test def runStackOverflow: Unit =
5454
compileFile("../tests/partest-test/stackOverflow.scala", defaultOptions).expectFailure.checkRuns()
55+
56+
@Test def runOutRedirects: Unit =
57+
compileFile("../tests/partest-test/i2147.scala", defaultOptions).expectFailure.checkRuns()
5558
}

compiler/test/dotty/tools/dotc/ParallelTesting.scala

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import dotc.util.DiffUtil
2828
* using this, you should be running your JUnit tests **sequentially**, as the
2929
* test suite itself runs with a high level of concurrency.
3030
*/
31-
trait ParallelTesting {
31+
trait ParallelTesting { self =>
3232

3333
import ParallelTesting._
3434
import ParallelSummaryReport._
@@ -399,18 +399,33 @@ trait ParallelTesting {
399399
.takeWhile(_.getMethodName != "invoke0")
400400
.mkString(" ", "\n ", "")
401401

402-
import java.io.ByteArrayOutputStream
402+
import java.io.{ ByteArrayOutputStream, PrintStream }
403403
import java.net.{ URL, URLClassLoader }
404404

405405
val printStream = new ByteArrayOutputStream
406+
val oldOut = System.out
407+
val oldErr = System.out
408+
406409
try {
407410
// Do classloading magic and running here:
408411
val ucl = new URLClassLoader(Array(dir.toURI.toURL))
409412
val cls = ucl.loadClass("Test")
410413
val meth = cls.getMethod("main", classOf[Array[String]])
411414

412-
Console.withOut(printStream) {
413-
meth.invoke(null, Array("jvm")) // partest passes at least "jvm" as an arg
415+
self.synchronized {
416+
try {
417+
val ps = new PrintStream(printStream)
418+
System.setOut(ps)
419+
System.setErr(ps)
420+
Console.withOut(printStream) {
421+
Console.withErr(printStream) {
422+
meth.invoke(null, Array("jvm")) // partest passes at least "jvm" as an arg
423+
}
424+
}
425+
} finally {
426+
System.setOut(oldOut)
427+
System.setErr(oldErr)
428+
}
414429
}
415430
}
416431
catch {

tests/partest-test/i2147.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Felix is number 1
2+
ducksarethebest.org
3+
foolsRus.org

tests/partest-test/i2147.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
println("Guillaume is number 1")
4+
System.out.println("ducksarethebest.com")
5+
System.err.println("foolsRus.com")
6+
}
7+
}

tests/run/i2147.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
before
2+
42
3+
lol

tests/run/i2147.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
println("before")
4+
System.out.println("42")
5+
println("lol")
6+
}
7+
}

0 commit comments

Comments
 (0)