@@ -174,6 +174,8 @@ trait ParallelTesting { self =>
174
174
* according to the implementing class "neg", "run" or "pos".
175
175
*/
176
176
private abstract class Test (testSources : List [TestSource ], times : Int , threadLimit : Option [Int ], suppressAllOutput : Boolean ) {
177
+ protected final val realStdout = System .out
178
+ protected final val realStderr = System .err
177
179
178
180
/** Actual compilation run logic, the test behaviour is defined here */
179
181
protected def compilationRunnable (testSource : TestSource ): Runnable
@@ -192,10 +194,10 @@ trait ParallelTesting { self =>
192
194
val sourceCount = filteredSources.length
193
195
194
196
private [this ] var _errorCount = 0
195
- def errorCount : Int = synchronized { _errorCount }
197
+ def errorCount : Int = _errorCount
196
198
197
199
private [this ] var _testSourcesCompiled = 0
198
- private def testSourcesCompiled : Int = synchronized { _testSourcesCompiled }
200
+ private def testSourcesCompiled : Int = _testSourcesCompiled
199
201
200
202
/** Complete the current compilation with the amount of errors encountered */
201
203
protected final def registerCompilation (errors : Int ) = synchronized {
@@ -228,7 +230,7 @@ trait ParallelTesting { self =>
228
230
229
231
/** Prints to `System.err` if we're not suppressing all output */
230
232
protected def echo (msg : String ): Unit =
231
- if (! suppressAllOutput) System .err .println(msg)
233
+ if (! suppressAllOutput) realStderr .println(msg)
232
234
233
235
/** A single `Runnable` that prints a progress bar for the curent `Test` */
234
236
private def createProgressMonitor : Runnable = new Runnable {
@@ -238,17 +240,19 @@ trait ParallelTesting { self =>
238
240
while (tCompiled < sourceCount) {
239
241
val timestamp = (System .currentTimeMillis - start) / 1000
240
242
val progress = (tCompiled.toDouble / sourceCount * 40 ).toInt
241
- print(
243
+
244
+ realStdout.print(
242
245
" [" + (" =" * (math.max(progress - 1 , 0 ))) +
243
246
(if (progress > 0 ) " >" else " " ) +
244
247
(" " * (39 - progress)) +
245
248
s " ] compiling ( $tCompiled/ $sourceCount, ${timestamp}s) \r "
246
249
)
250
+
247
251
Thread .sleep(100 )
248
252
tCompiled = testSourcesCompiled
249
253
}
250
254
// println, otherwise no newline and cursor at start of line
251
- println(
255
+ realStdout. println(
252
256
s " [=======================================] compiled ( $sourceCount/ $sourceCount, " +
253
257
s " ${(System .currentTimeMillis - start) / 1000 }s) "
254
258
)
@@ -259,7 +263,10 @@ trait ParallelTesting { self =>
259
263
* if it did, the test should automatically fail.
260
264
*/
261
265
protected def tryCompile (testSource : TestSource )(op : => Unit ): Unit =
262
- try op catch {
266
+ try {
267
+ if (! isInteractive) realStdout.println(s " Testing ${testSource.title}" )
268
+ op
269
+ } catch {
263
270
case NonFatal (e) => {
264
271
// if an exception is thrown during compilation, the complete test
265
272
// run should fail
@@ -309,8 +316,10 @@ trait ParallelTesting { self =>
309
316
Runtime .getRuntime.exec(fullArgs).waitFor() == 0
310
317
} else true
311
318
312
- val reporter = TestReporter .parallelReporter(this , logLevel =
313
- if (suppressErrors || suppressAllOutput) ERROR + 1 else ERROR )
319
+ val reporter =
320
+ TestReporter .reporter(realStdout, logLevel =
321
+ if (suppressErrors || suppressAllOutput) ERROR + 1 else ERROR )
322
+
314
323
val driver =
315
324
if (times == 1 ) new Driver { def newCompiler (implicit ctx : Context ) = new Compiler }
316
325
else new Driver {
@@ -353,8 +362,12 @@ trait ParallelTesting { self =>
353
362
}
354
363
355
364
pool.shutdown()
356
- if (! pool.awaitTermination(10 , TimeUnit .MINUTES ))
365
+ if (! pool.awaitTermination(20 , TimeUnit .MINUTES )) {
366
+ pool.shutdownNow()
367
+ System .setOut(realStdout)
368
+ System .setErr(realStderr)
357
369
throw new TimeoutException (" Compiling targets timed out" )
370
+ }
358
371
359
372
if (didFail) {
360
373
reportFailed()
@@ -417,16 +430,14 @@ trait ParallelTesting { self =>
417
430
import java .net .{ URL , URLClassLoader }
418
431
419
432
val printStream = new ByteArrayOutputStream
420
- val oldOut = System .out
421
- val oldErr = System .err
422
433
423
434
try {
424
435
// Do classloading magic and running here:
425
436
val ucl = new URLClassLoader (Array (dir.toURI.toURL))
426
437
val cls = ucl.loadClass(" Test" )
427
438
val meth = cls.getMethod(" main" , classOf [Array [String ]])
428
439
429
- self. synchronized {
440
+ synchronized {
430
441
try {
431
442
val ps = new PrintStream (printStream)
432
443
System .setOut(ps)
@@ -436,9 +447,13 @@ trait ParallelTesting { self =>
436
447
meth.invoke(null , Array (" jvm" )) // partest passes at least "jvm" as an arg
437
448
}
438
449
}
439
- } finally {
440
- System .setOut(oldOut)
441
- System .setErr(oldErr)
450
+ System .setOut(realStdout)
451
+ System .setErr(realStderr)
452
+ } catch {
453
+ case t : Throwable =>
454
+ System .setOut(realStdout)
455
+ System .setErr(realStderr)
456
+ throw t
442
457
}
443
458
}
444
459
}
0 commit comments