@@ -202,8 +202,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
202202 def sourceFiles = compilationGroups.map(_._2).flatten.toArray
203203 }
204204
205- protected def shouldSkipTestSource (testSource : TestSource ): Boolean =
206- false
205+ protected def shouldSkipTestSource (testSource : TestSource ): Boolean = false
207206
208207 private trait CompilationLogic { this : Test =>
209208 def suppressErrors = false
@@ -423,20 +422,21 @@ trait ParallelTesting extends RunnerOrchestration { self =>
423422 }
424423
425424 /** 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 =
427433 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) "
440440
441441 /** Wrapper function to make sure that the compiler itself did not crash -
442442 * if it did, the test should automatically fail.
@@ -490,9 +490,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
490490 else None
491491 } else None
492492
493- val reporter =
494- TestReporter .reporter(realStdout, logLevel =
495- if (suppressErrors || suppressAllOutput) ERROR + 1 else ERROR )
493+ val reporter = mkReporter
496494
497495 val driver =
498496 if (times == 1 ) new Driver
@@ -599,8 +597,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
599597 val command = scalacCommand ++ flags1.all ++ files.map(_.getAbsolutePath)
600598 val process = Runtime .getRuntime.exec(command)
601599
602- val reporter = TestReporter .reporter(realStdout, logLevel =
603- if (suppressErrors || suppressAllOutput) ERROR + 1 else ERROR )
600+ val reporter = mkReporter
604601 val errorsText = Source .fromInputStream(process.getErrorStream).mkString
605602 if process.waitFor() != 0 then
606603 val diagnostics = parseErrors(errorsText, compiler, pageWidth)
@@ -618,9 +615,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
618615
619616 val classes = flattenFiles(targetDir).filter(isTastyFile).map(_.toString)
620617
621- val reporter =
622- TestReporter .reporter(realStdout, logLevel =
623- if (suppressErrors || suppressAllOutput) ERROR + 1 else ERROR )
618+ val reporter = mkReporter
624619
625620 val driver = new Driver
626621
@@ -629,68 +624,51 @@ trait ParallelTesting extends RunnerOrchestration { self =>
629624 reporter
630625 }
631626
627+ private def mkLogLevel = if suppressErrors || suppressAllOutput then ERROR + 1 else ERROR
628+ private def mkReporter = TestReporter .reporter(realStdout, logLevel = mkLogLevel)
629+
632630 private [ParallelTesting ] def executeTestSuite (): this .type = {
633631 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()))
641634 val timer = new Timer ()
642635 val logProgress = isInteractive && ! suppressAllOutput
643636 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*/ )
650639
651- val eventualResults = filteredSources.map { target =>
640+ val eventualResults = for target <- filteredSources yield
652641 pool.submit(encapsulatedCompilation(target))
653- }
654642
655643 pool.shutdown()
656644
657- if ( ! pool.awaitTermination(20 , TimeUnit .MINUTES )) {
645+ if ! pool.awaitTermination(20 , TimeUnit .MINUTES ) then
658646 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
661649 remaining += src
662- }
663650
664651 pool.shutdownNow()
665652 System .setOut(realStdout)
666653 System .setErr(realStderr)
667654 throw new TimeoutException (s " Compiling targets timed out, remaining targets: ${remaining.mkString(" , " )}" )
668- }
655+ end if
669656
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()
678662
679- if ( logProgress) {
663+ if logProgress then
680664 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)
686666
687- if ( didFail) {
667+ if didFail then
688668 reportFailed()
689669 failedTestSources.toSet.foreach(addFailedTest)
690670 reproduceInstructions.foreach(addReproduceInstruction)
691- }
692671 else reportPassed()
693- }
694672 else echo {
695673 testFilter match
696674 case _ :: _ => s """ No files matched " ${testFilter.mkString(" ," )}" in test """
0 commit comments