@@ -9,7 +9,7 @@ import scala.tools.partest._
9
9
import scala .tools .partest .nest ._
10
10
import scala .util .matching .Regex
11
11
import tools .nsc .io .{ File => NSCFile }
12
- import java .io .File
12
+ import java .io .{ File , PrintStream , FileOutputStream }
13
13
import java .net .URLClassLoader
14
14
15
15
/** Runs dotty partest from the Console, discovering test sources in
@@ -25,7 +25,7 @@ object DPConsoleRunner {
25
25
val (jarList, otherArgs) = args.toList.partition(jarFinder.findFirstIn(_).isDefined)
26
26
val (extraJars, moreArgs) = jarList match {
27
27
case Nil => sys.error(" Error: DPConsoleRunner needs \" -dottyJars <jarCount> <jars>*\" ." )
28
- case jarFinder(nr, jarString) :: Nil =>
28
+ case jarFinder(nr, jarString) :: Nil =>
29
29
val jars = jarString.split(" " ).toList
30
30
val count = nr.toInt
31
31
if (jars.length < count)
@@ -64,7 +64,7 @@ class DPSuiteRunner(testSourcePath: String, // relative path, like "files", or "
64
64
failed : Boolean ,
65
65
javaCmdPath : String = PartestDefaults .javaCmd,
66
66
javacCmdPath : String = PartestDefaults .javacCmd,
67
- scalacExtraArgs : Seq [String ] = Seq .empty)
67
+ scalacExtraArgs : Seq [String ] = Seq .empty)
68
68
extends SuiteRunner (testSourcePath, fileManager, updateCheck, failed, javaCmdPath, javacCmdPath, scalacExtraArgs) {
69
69
70
70
if (! DPConfig .runTestsInParallel)
@@ -82,32 +82,38 @@ extends SuiteRunner(testSourcePath, fileManager, updateCheck, failed, javaCmdPat
82
82
""" .stripMargin
83
83
}
84
84
85
- // override to provide DPTestRunner
85
+ // override for DPTestRunner and redirecting compilation output to test.clog
86
86
override def runTest (testFile : File ): TestState = {
87
87
val runner = new DPTestRunner (testFile, this )
88
88
89
- // when option "--failed" is provided execute test only if log
90
- // is present (which means it failed before)
91
89
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)
103
111
}
112
+ NestUI .reportTest(state)
113
+ runner.cleanup()
114
+
104
115
onFinishTest(testFile, state)
105
116
}
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
111
117
}
112
118
113
119
class DPTestRunner (testFile : File , suiteRunner : DPSuiteRunner ) extends nest.Runner (testFile, suiteRunner) {
@@ -146,18 +152,18 @@ class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runn
146
152
def nerrIsOk (reason : String ) = {
147
153
val nerrFinder = """ compilation failed with (\d+) errors""" .r
148
154
reason match {
149
- case nerrFinder(found) =>
155
+ case nerrFinder(found) =>
150
156
SFile (FileOps (testFile) changeExtension " nerr" ).safeSlurp match {
151
157
case Some (exp) if (exp != found) => CompFailedButWrongNErr (exp, found)
152
158
case _ => CompFailed
153
159
}
154
160
case _ => CompFailed
155
161
}
156
162
}
157
-
163
+
158
164
// we keep the partest semantics where only one round needs to fail
159
165
// compilation, not all
160
- val compFailingRounds = compilationRounds(testFile).map({round =>
166
+ val compFailingRounds = compilationRounds(testFile).map({round =>
161
167
val ok = round.isOk
162
168
setLastState(if (ok) genPass else genFail(" compilation failed" ))
163
169
(round.result, ok)
@@ -173,14 +179,14 @@ class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runn
173
179
if (failureStates.exists({ case CompFailed => true ; case _ => false })) {
174
180
true
175
181
} else {
176
- val existsNerr = failureStates.exists({
182
+ val existsNerr = failureStates.exists({
177
183
case CompFailedButWrongNErr (exp, found) => nextTestActionFailing(s " wrong number of compilation errors, expected: $exp, found: $found" ); true
178
184
case _ => false
179
185
})
180
186
if (existsNerr) {
181
- false
187
+ false
182
188
} else {
183
- val existsDiff = failureStates.exists({
189
+ val existsDiff = failureStates.exists({
184
190
case CompFailedButWrongDiff () => nextTestActionFailing(s " output differs " ); true
185
191
case _ => false
186
192
})
0 commit comments