Skip to content

Commit e23b33e

Browse files
committed
Fix #2147: redirect both java and scala std out/err
1 parent f49c10d commit e23b33e

File tree

7 files changed

+41
-4
lines changed

7 files changed

+41
-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: 18 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,28 @@ 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+
val ps = new PrintStream(printStream)
417+
System.setOut(ps)
418+
System.setErr(ps)
419+
Console.withOut(printStream) {
420+
Console.withErr(printStream) {
421+
meth.invoke(null, Array("jvm")) // partest passes at least "jvm" as an arg
422+
}
423+
}
414424
}
415425
}
416426
catch {
@@ -426,6 +436,10 @@ trait ParallelTesting {
426436
echo(s"An exception ocurred when running main: ${ex.getCause}\n${renderStackTrace(ex.getCause)}")
427437
failTestSource(testSource)
428438
}
439+
finally {
440+
System.setOut(oldOut)
441+
System.setErr(oldErr)
442+
}
429443
printStream.toString("utf-8").lines.toArray
430444
}
431445

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)