Skip to content

Commit b1801a4

Browse files
committed
test locky
1 parent 058771a commit b1801a4

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

compiler/test/dotty/tools/dotc/ParallelTesting.scala

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ trait ParallelTesting { self =>
174174
* according to the implementing class "neg", "run" or "pos".
175175
*/
176176
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
177179

178180
/** Actual compilation run logic, the test behaviour is defined here */
179181
protected def compilationRunnable(testSource: TestSource): Runnable
@@ -192,10 +194,10 @@ trait ParallelTesting { self =>
192194
val sourceCount = filteredSources.length
193195

194196
private[this] var _errorCount = 0
195-
def errorCount: Int = synchronized { _errorCount }
197+
def errorCount: Int = _errorCount
196198

197199
private[this] var _testSourcesCompiled = 0
198-
private def testSourcesCompiled : Int = synchronized { _testSourcesCompiled }
200+
private def testSourcesCompiled: Int = _testSourcesCompiled
199201

200202
/** Complete the current compilation with the amount of errors encountered */
201203
protected final def registerCompilation(errors: Int) = synchronized {
@@ -227,8 +229,9 @@ trait ParallelTesting { self =>
227229
}
228230

229231
/** Prints to `System.err` if we're not suppressing all output */
230-
protected def echo(msg: String): Unit =
231-
if (!suppressAllOutput) System.err.println(msg)
232+
protected def echo(msg: String): Unit = realStderr.synchronized {
233+
if (!suppressAllOutput) realStderr.println(msg)
234+
}
232235

233236
/** A single `Runnable` that prints a progress bar for the curent `Test` */
234237
private def createProgressMonitor: Runnable = new Runnable {
@@ -238,17 +241,21 @@ trait ParallelTesting { self =>
238241
while (tCompiled < sourceCount) {
239242
val timestamp = (System.currentTimeMillis - start) / 1000
240243
val progress = (tCompiled.toDouble / sourceCount * 40).toInt
241-
print(
242-
"[" + ("=" * (math.max(progress - 1, 0))) +
243-
(if (progress > 0) ">" else "") +
244-
(" " * (39 - progress)) +
245-
s"] compiling ($tCompiled/$sourceCount, ${timestamp}s)\r"
246-
)
244+
245+
realStdout.synchronized {
246+
realStdout.print(
247+
"[" + ("=" * (math.max(progress - 1, 0))) +
248+
(if (progress > 0) ">" else "") +
249+
(" " * (39 - progress)) +
250+
s"] compiling ($tCompiled/$sourceCount, ${timestamp}s)\r"
251+
)
252+
}
253+
247254
Thread.sleep(100)
248255
tCompiled = testSourcesCompiled
249256
}
250257
// println, otherwise no newline and cursor at start of line
251-
println(
258+
realStdout.println(
252259
s"[=======================================] compiled ($sourceCount/$sourceCount, " +
253260
s"${(System.currentTimeMillis - start) / 1000}s) "
254261
)
@@ -259,7 +266,12 @@ trait ParallelTesting { self =>
259266
* if it did, the test should automatically fail.
260267
*/
261268
protected def tryCompile(testSource: TestSource)(op: => Unit): Unit =
262-
try op catch {
269+
try {
270+
if (!isInteractive) realStdout.synchronized {
271+
realStdout.println(s"Testing ${testSource.title}")
272+
}
273+
op
274+
} catch {
263275
case NonFatal(e) => {
264276
// if an exception is thrown during compilation, the complete test
265277
// run should fail
@@ -309,8 +321,10 @@ trait ParallelTesting { self =>
309321
Runtime.getRuntime.exec(fullArgs).waitFor() == 0
310322
} else true
311323

312-
val reporter = TestReporter.parallelReporter(self, logLevel =
313-
if (suppressErrors || suppressAllOutput) ERROR + 1 else ERROR)
324+
val reporter = System.out.synchronized {
325+
TestReporter.parallelReporter(System.out, logLevel =
326+
if (suppressErrors || suppressAllOutput) ERROR + 1 else ERROR)
327+
}
314328
val driver =
315329
if (times == 1) new Driver { def newCompiler(implicit ctx: Context) = new Compiler }
316330
else new Driver {
@@ -426,7 +440,7 @@ trait ParallelTesting { self =>
426440
val cls = ucl.loadClass("Test")
427441
val meth = cls.getMethod("main", classOf[Array[String]])
428442

429-
self.synchronized {
443+
oldOut.synchronized {
430444
try {
431445
val ps = new PrintStream(printStream)
432446
System.setOut(ps)

0 commit comments

Comments
 (0)