Skip to content

Fix #2147: redirect both java and scala std out/err #2148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added compiler/foo
Empty file.
3 changes: 3 additions & 0 deletions compiler/test/dotty/tools/dotc/ParallelTestTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
23 changes: 19 additions & 4 deletions compiler/test/dotty/tools/dotc/ParallelTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions tests/partest-test/i2147.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Felix is number 1
ducksarethebest.org
foolsRus.org
7 changes: 7 additions & 0 deletions tests/partest-test/i2147.scala
Original file line number Diff line number Diff line change
@@ -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")
}
}
3 changes: 3 additions & 0 deletions tests/run/i2147.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
before
42
lol
7 changes: 7 additions & 0 deletions tests/run/i2147.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Test {
def main(args: Array[String]): Unit = {
println("before")
System.out.println("42")
println("lol")
}
}