Skip to content

Commit 395e505

Browse files
committed
Less verbose partest with compiler output redirected, better --verbose output
1 parent 21cc045 commit 395e505

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

test/dotty/partest/DPConfig.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ object DPConfig {
1818
lazy val testDirs = {
1919
val root = new File(testRoot)
2020
val dirs = if (!root.exists) Array.empty[String] else root.listFiles.filter(_.isDirectory).map(_.getName)
21-
if (dirs.length > 0)
22-
println(s"Partest found generated source directories in $testRoot: " + dirs.mkString(", "))
23-
else
21+
if (dirs.isEmpty)
2422
throw new Exception("Partest did not detect any generated sources")
2523
dirs
2624
}

test/dotty/partest/DPConsoleRunner.scala

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import scala.tools.partest._
99
import scala.tools.partest.nest._
1010
import scala.util.matching.Regex
1111
import tools.nsc.io.{ File => NSCFile }
12-
import java.io.File
12+
import java.io.{ File, PrintStream, FileOutputStream }
1313
import java.net.URLClassLoader
1414

1515
/** Runs dotty partest from the Console, discovering test sources in
@@ -25,7 +25,7 @@ object DPConsoleRunner {
2525
val (jarList, otherArgs) = args.toList.partition(jarFinder.findFirstIn(_).isDefined)
2626
val (extraJars, moreArgs) = jarList match {
2727
case Nil => sys.error("Error: DPConsoleRunner needs \"-dottyJars <jarCount> <jars>*\".")
28-
case jarFinder(nr, jarString) :: Nil =>
28+
case jarFinder(nr, jarString) :: Nil =>
2929
val jars = jarString.split(" ").toList
3030
val count = nr.toInt
3131
if (jars.length < count)
@@ -64,7 +64,7 @@ class DPSuiteRunner(testSourcePath: String, // relative path, like "files", or "
6464
failed: Boolean,
6565
javaCmdPath: String = PartestDefaults.javaCmd,
6666
javacCmdPath: String = PartestDefaults.javacCmd,
67-
scalacExtraArgs: Seq[String] = Seq.empty)
67+
scalacExtraArgs: Seq[String] = Seq.empty)
6868
extends SuiteRunner(testSourcePath, fileManager, updateCheck, failed, javaCmdPath, javacCmdPath, scalacExtraArgs) {
6969

7070
if (!DPConfig.runTestsInParallel)
@@ -82,32 +82,38 @@ extends SuiteRunner(testSourcePath, fileManager, updateCheck, failed, javaCmdPat
8282
""".stripMargin
8383
}
8484

85-
// override to provide DPTestRunner
85+
// override for DPTestRunner and redirecting compilation output to test.clog
8686
override def runTest(testFile: File): TestState = {
8787
val runner = new DPTestRunner(testFile, this)
8888

89-
// when option "--failed" is provided execute test only if log
90-
// is present (which means it failed before)
9189
val state =
92-
if (failed && !runner.logFile.canRead)
93-
runner.genPass()
94-
else {
95-
val (state, _) =
96-
try timed(runner.run())
97-
catch {
98-
case t: Throwable => throw new RuntimeException(s"Error running $testFile", t)
99-
}
100-
NestUI.reportTest(state)
101-
runner.cleanup()
102-
state
90+
try {
91+
// IO redirection is messy, there are no concurrency guarantees.
92+
// Parts of test output might end up in the wrong file or get lost.
93+
Console.out.flush
94+
Console.err.flush
95+
val clog = SFile(runner.logFile).changeExtension("clog")
96+
val stream = new PrintStream(new FileOutputStream(clog.jfile), true)
97+
val result = Console.withOut(stream)({ Console.withErr(stream)({
98+
runner.run()
99+
Console.err.flush
100+
Console.out.flush
101+
})})
102+
result match {
103+
// Append compiler output to transcript if compilation failed,
104+
// printed with --verbose option
105+
case TestState.Fail(f, r@"compilation failed", transcript) =>
106+
TestState.Fail(f, r, transcript ++ clog.fileLines.dropWhile(_ == ""))
107+
case res => res
108+
}
109+
} catch {
110+
case t: Throwable => throw new RuntimeException(s"Error running $testFile", t)
103111
}
112+
NestUI.reportTest(state)
113+
runner.cleanup()
114+
104115
onFinishTest(testFile, state)
105116
}
106-
107-
// override val fileManager = new DottyFileManager(testClassLoader)
108-
// sbt package generates a dotty compiler jar, currently
109-
// ".../git/dotty/target/scala-2.11/dotty_2.11-0.1-SNAPSHOT.jar"
110-
// but it doesn't seem to be used anywhere
111117
}
112118

113119
class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runner(testFile, suiteRunner) {
@@ -146,18 +152,18 @@ class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runn
146152
def nerrIsOk(reason: String) = {
147153
val nerrFinder = """compilation failed with (\d+) errors""".r
148154
reason match {
149-
case nerrFinder(found) =>
155+
case nerrFinder(found) =>
150156
SFile(FileOps(testFile) changeExtension "nerr").safeSlurp match {
151157
case Some(exp) if (exp != found) => CompFailedButWrongNErr(exp, found)
152158
case _ => CompFailed
153159
}
154160
case _ => CompFailed
155161
}
156162
}
157-
163+
158164
// we keep the partest semantics where only one round needs to fail
159165
// compilation, not all
160-
val compFailingRounds = compilationRounds(testFile).map({round =>
166+
val compFailingRounds = compilationRounds(testFile).map({round =>
161167
val ok = round.isOk
162168
setLastState(if (ok) genPass else genFail("compilation failed"))
163169
(round.result, ok)
@@ -173,14 +179,14 @@ class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runn
173179
if (failureStates.exists({ case CompFailed => true; case _ => false })) {
174180
true
175181
} else {
176-
val existsNerr = failureStates.exists({
182+
val existsNerr = failureStates.exists({
177183
case CompFailedButWrongNErr(exp, found) => nextTestActionFailing(s"wrong number of compilation errors, expected: $exp, found: $found"); true
178184
case _ => false
179185
})
180186
if (existsNerr) {
181-
false
187+
false
182188
} else {
183-
val existsDiff = failureStates.exists({
189+
val existsDiff = failureStates.exists({
184190
case CompFailedButWrongDiff() => nextTestActionFailing(s"output differs"); true
185191
case _ => false
186192
})

0 commit comments

Comments
 (0)