@@ -202,8 +202,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
202
202
def sourceFiles = compilationGroups.map(_._2).flatten.toArray
203
203
}
204
204
205
- protected def shouldSkipTestSource (testSource : TestSource ): Boolean =
206
- false
205
+ protected def shouldSkipTestSource (testSource : TestSource ): Boolean = false
207
206
208
207
private trait CompilationLogic { this : Test =>
209
208
def suppressErrors = false
@@ -423,20 +422,21 @@ trait ParallelTesting extends RunnerOrchestration { self =>
423
422
}
424
423
425
424
/** Print a progress bar for the current `Test` */
426
- private def updateProgressMonitor (start : Long ): Unit = {
425
+ private def updateProgressMonitor (start : Long ): Unit =
426
+ if testSourcesCompleted < sourceCount then
427
+ realStdout.print(s " \r ${makeProgressBar(start)}" )
428
+
429
+ private def finishProgressMonitor (start : Long ): Unit =
430
+ realStdout.println(s " \r ${makeProgressBar(start)}" )
431
+
432
+ private def makeProgressBar (start : Long ): String =
427
433
val tCompiled = testSourcesCompleted
428
- if (tCompiled < sourceCount) {
429
- val timestamp = (System .currentTimeMillis - start) / 1000
430
- val progress = (tCompiled.toDouble / sourceCount * 40 ).toInt
431
-
432
- realStdout.print(
433
- " [" + (" =" * (math.max(progress - 1 , 0 ))) +
434
- (if (progress > 0 ) " >" else " " ) +
435
- (" " * (39 - progress)) +
436
- s " ] completed ( $tCompiled/ $sourceCount, $failureCount failed, ${timestamp}s) \r "
437
- )
438
- }
439
- }
434
+ val timestamp = (System .currentTimeMillis - start) / 1000
435
+ val progress = (tCompiled.toDouble / sourceCount * 40 ).toInt
436
+ val past = " =" * math.max(progress - 1 , 0 )
437
+ val curr = if progress > 0 then " >" else " "
438
+ val next = " " * (40 - progress)
439
+ s " [ $past$curr$next] completed ( $tCompiled/ $sourceCount, $failureCount failed, ${timestamp}s) "
440
440
441
441
/** Wrapper function to make sure that the compiler itself did not crash -
442
442
* if it did, the test should automatically fail.
@@ -490,9 +490,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
490
490
else None
491
491
} else None
492
492
493
- val reporter =
494
- TestReporter .reporter(realStdout, logLevel =
495
- if (suppressErrors || suppressAllOutput) ERROR + 1 else ERROR )
493
+ val reporter = mkReporter
496
494
497
495
val driver =
498
496
if (times == 1 ) new Driver
@@ -599,8 +597,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
599
597
val command = scalacCommand ++ flags1.all ++ files.map(_.getAbsolutePath)
600
598
val process = Runtime .getRuntime.exec(command)
601
599
602
- val reporter = TestReporter .reporter(realStdout, logLevel =
603
- if (suppressErrors || suppressAllOutput) ERROR + 1 else ERROR )
600
+ val reporter = mkReporter
604
601
val errorsText = Source .fromInputStream(process.getErrorStream).mkString
605
602
if process.waitFor() != 0 then
606
603
val diagnostics = parseErrors(errorsText, compiler, pageWidth)
@@ -618,9 +615,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
618
615
619
616
val classes = flattenFiles(targetDir).filter(isTastyFile).map(_.toString)
620
617
621
- val reporter =
622
- TestReporter .reporter(realStdout, logLevel =
623
- if (suppressErrors || suppressAllOutput) ERROR + 1 else ERROR )
618
+ val reporter = mkReporter
624
619
625
620
val driver = new Driver
626
621
@@ -629,68 +624,51 @@ trait ParallelTesting extends RunnerOrchestration { self =>
629
624
reporter
630
625
}
631
626
627
+ private def mkLogLevel = if suppressErrors || suppressAllOutput then ERROR + 1 else ERROR
628
+ private def mkReporter = TestReporter .reporter(realStdout, logLevel = mkLogLevel)
629
+
632
630
private [ParallelTesting ] def executeTestSuite (): this .type = {
633
631
assert(testSourcesCompleted == 0 , " not allowed to re-use a `CompileRun`" )
634
-
635
- if (filteredSources.nonEmpty) {
636
- val pool = threadLimit match {
637
- case Some (i) => JExecutors .newWorkStealingPool(i)
638
- case None => JExecutors .newWorkStealingPool()
639
- }
640
-
632
+ if filteredSources.nonEmpty then
633
+ val pool = JExecutors .newWorkStealingPool(threadLimit.getOrElse(Runtime .getRuntime.availableProcessors()))
641
634
val timer = new Timer ()
642
635
val logProgress = isInteractive && ! suppressAllOutput
643
636
val start = System .currentTimeMillis()
644
- if (logProgress) {
645
- val task = new TimerTask {
646
- def run (): Unit = updateProgressMonitor(start)
647
- }
648
- timer.schedule(task, 100 , 200 )
649
- }
637
+ if logProgress then
638
+ timer.schedule((() => updateProgressMonitor(start)): TimerTask , 100 /* ms*/ , 200 /* ms*/ )
650
639
651
- val eventualResults = filteredSources.map { target =>
640
+ val eventualResults = for target <- filteredSources yield
652
641
pool.submit(encapsulatedCompilation(target))
653
- }
654
642
655
643
pool.shutdown()
656
644
657
- if ( ! pool.awaitTermination(20 , TimeUnit .MINUTES )) {
645
+ if ! pool.awaitTermination(20 , TimeUnit .MINUTES ) then
658
646
val remaining = new ListBuffer [TestSource ]
659
- filteredSources.lazyZip(eventualResults).foreach { (src, res) =>
660
- if ( ! res.isDone)
647
+ for (src, res) <- filteredSources.lazyZip(eventualResults) do
648
+ if ! res.isDone then
661
649
remaining += src
662
- }
663
650
664
651
pool.shutdownNow()
665
652
System .setOut(realStdout)
666
653
System .setErr(realStderr)
667
654
throw new TimeoutException (s " Compiling targets timed out, remaining targets: ${remaining.mkString(" , " )}" )
668
- }
655
+ end if
669
656
670
- eventualResults.foreach { x =>
671
- try x.get()
672
- catch {
673
- case ex : Exception =>
674
- System .err.println(ex.getMessage)
675
- ex.printStackTrace()
676
- }
677
- }
657
+ for fut <- eventualResults do
658
+ try fut.get()
659
+ catch case ex : Exception =>
660
+ System .err.println(ex.getMessage)
661
+ ex.printStackTrace()
678
662
679
- if ( logProgress) {
663
+ if logProgress then
680
664
timer.cancel()
681
- val timestamp = (System .currentTimeMillis - start) / 1000
682
- realStdout.println(
683
- s " [=======================================] completed ( $sourceCount/ $sourceCount, $failureCount failed, ${timestamp}s) "
684
- )
685
- }
665
+ finishProgressMonitor(start)
686
666
687
- if ( didFail) {
667
+ if didFail then
688
668
reportFailed()
689
669
failedTestSources.toSet.foreach(addFailedTest)
690
670
reproduceInstructions.foreach(addReproduceInstruction)
691
- }
692
671
else reportPassed()
693
- }
694
672
else echo {
695
673
testFilter match
696
674
case _ :: _ => s """ No files matched " ${testFilter.mkString(" ," )}" in test """
0 commit comments