Skip to content

Commit 13350b2

Browse files
changes compile
1 parent ad902d8 commit 13350b2

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

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

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
5656
def name: String
5757
def outDir: JFile
5858
def flags: TestFlags
59+
def sourceFiles: Array[JFile]
5960

6061
def runClassPath: String = outDir.getAbsolutePath + JFile.pathSeparator + flags.runClassPath
6162

@@ -141,7 +142,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
141142
fromTasty: Boolean = false,
142143
decompilation: Boolean = false
143144
) extends TestSource {
144-
def sourceFiles: Array[JFile] = files.filter(isSourceFile)
145+
def sourceFiles: Array[JFile] = files.filter(isSourceFile).toArray
145146

146147
override def toString() = outDir.toString
147148
}
@@ -178,6 +179,8 @@ trait ParallelTesting extends RunnerOrchestration { self =>
178179
.getOrElse("")
179180
}
180181
.toList.sortBy(_._1).map(_._2.filter(isSourceFile).sorted)
182+
183+
def sourceFiles: Array[JFile] = compilationGroups.flatten.filter(isSourceFile).toArray
181184
}
182185

183186
private trait CompilationLogic { this: Test =>
@@ -205,29 +208,30 @@ trait ParallelTesting extends RunnerOrchestration { self =>
205208
ts.files.filter(f => !f.isDirectory).map { f => new JFile(f.getAbsolutePath.replaceFirst("\\.scala$", ".check")) }.headOption
206209

207210
case ts: SeparateCompilationSource =>
208-
Option(new JFile(dir.getAbsolutePath + ".check"))
211+
Option(new JFile(ts.dir.getAbsolutePath + ".check"))
209212
}).filter(_.exists)
210213

211-
final def diffTest(sourceName: String, checkFile: JFile, actual: List[String]) = {
214+
final def diffTest(testSource: TestSource, checkFile: JFile, actual: List[String]) = {
212215
val expected = Source.fromFile(checkFile, "UTF-8").getLines().toList
213-
for (msg <- diffMessage(sourceName, actual, expected)) {
214-
fail(msg)
216+
for (msg <- diffMessage(testSource.title, actual, expected)) {
217+
echo(msg)
218+
failTestSource(testSource)
215219
dumpOutputToFile(checkFile, actual)
216220
}
217221
}
218222

219-
final def encapsulatedCompilation(testSource: TestSource) = new LoggedRunnable { self =>
223+
def encapsulatedCompilation(testSource: TestSource) = new LoggedRunnable { self =>
220224
def checkTestSource(): Unit = tryCompile(testSource) {
221225
val reporters = compileTestSource(testSource)
222226
onComplete(testSource, reporters, self)
223227
registerCompletion()
224228
}
225229
}
226230

227-
final def onComplete(testSource: TestSource, reporters: Seq[TestReporter], logger: LoggedRunnable): Unit =
228-
testFailed(testSource, reporters).fold(
229-
onSuccess(testSource, reporters, logger )
230-
, msg => onFailure(testSource, reporters, logger, Option(msg).filter(_.nonEmpty)) )
231+
final def onComplete(testSource: TestSource, reporters: Seq[TestReporter], logger: LoggedRunnable): Unit = (
232+
testFailed(testSource, reporters).fold
233+
( onSuccess(testSource, reporters, logger ) )
234+
(msg => onFailure(testSource, reporters, logger, Option(msg).filter(_.nonEmpty)) ) )
231235

232236
def testFailed(testSource: TestSource, reporters: Seq[TestReporter]): Option[String] =
233237
Option(reporters.exists(reporterFailed)).map(_ => s"Compilation failed for: '${testSource.title}'")
@@ -621,8 +625,8 @@ trait ParallelTesting extends RunnerOrchestration { self =>
621625
private[this] def verifyOutput(checkFile: Option[JFile], dir: JFile, testSource: TestSource, warnings: Int) = {
622626
if (Properties.testsNoRun) addNoRunWarning()
623627
else runMain(testSource.runClassPath) match {
624-
case Success(_) if !checkFile.isDefined || !checkFile.get.exists => // success!
625-
case Success(output) => checkFile.foreach(diffTest(testSource, _, output.linesIterator.toSeq))
628+
case Success(_) if !checkFile.isDefined || !checkFile.get.exists =>
629+
case Success(output) => checkFile.foreach(diffTest(testSource, _, output.linesIterator.toList))
626630
case Failure(output) =>
627631
echo(s"Test '${testSource.title}' failed with output:")
628632
echo(output)
@@ -639,33 +643,34 @@ trait ParallelTesting extends RunnerOrchestration { self =>
639643

640644
private final class NegTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)(implicit summaryReport: SummaryReporting)
641645
extends Test(testSources, times, threadLimit, suppressAllOutput) {
642-
override def testFailed(reporters: Seq[TestReporter]): Option[() => Unit] = {
646+
override def testFailed(testSource: TestSource, reporters: Seq[TestReporter]): Option[String] = {
643647
val compilerCrashed = reporters.exists(_.compilerCrashed)
644648
val (errorMap, expectedErrors) = getErrorMapAndExpectedCount(testSource.sourceFiles)
645649
val actualErrors = reporters.foldLeft(0)(_ + _.errorCount)
650+
val hasMissingAnnotations = getMissingExpectedErrors(errorMap, reporters.iterator.flatMap(_.errors))
646651

647652
if (compilerCrashed ) Some(s"Compiler crashed when compiling: ${testSource.title}" )
648653
else if (actualErrors == 0 ) Some(s"\nNo errors found when compiling neg test $testSource" )
649654
else if (expectedErrors != actualErrors) Some(s"\nWrong number of errors encountered when compiling $testSource, expected: $expectedErrors, actual: $actualErrors")
650-
else if (hasMissingAnnotations() ) Some(s"\nErrors found on incorrect row numbers when compiling $testSource" )
655+
else if (hasMissingAnnotations ) Some(s"\nErrors found on incorrect row numbers when compiling $testSource" )
651656
else if (!errorMap.isEmpty ) Some(s"\nExpected error(s) have {<error position>=<unreported error>}: $errorMap" )
652657
else None
653658
}
654659

655660
override def onSuccess(testSource: TestSource, reporters: Seq[TestReporter], logger: LoggedRunnable): Unit =
656-
checkFile(testSource).foreach(diffTest(testSource.title, _, reporterOutputLines(reporters)))
661+
checkFile(testSource).foreach(diffTest(testSource, _, reporterOutputLines(reporters)))
657662

658-
def reporterOutputLines(reporters: List[TestReporter]): List[String] =
663+
def reporterOutputLines(reporters: Seq[TestReporter]): List[String] =
659664
reporters.flatMap(_.allErrors).sortBy(_.pos.source.toString).flatMap { error =>
660-
(error.pos.span.toString + " in " + error.pos.source.file.name) :: error.getMessage().linesIterator.toList }
665+
(error.pos.span.toString + " in " + error.pos.source.file.name) :: error.getMessage().linesIterator.toList }.toList
661666

662667
// In neg-tests we allow two types of error annotations,
663668
// "nopos-error" which doesn't care about position and "error" which
664669
// has to be annotated on the correct line number.
665670
//
666671
// We collect these in a map `"file:row" -> numberOfErrors`, for
667672
// nopos errors we save them in `"file" -> numberOfNoPosErrors`
668-
def getErrorMapAndExpectedCount(files: Array[JFile]): (HashMap[String, Integer], Int) = {
673+
def getErrorMapAndExpectedCount(files: Seq[JFile]): (HashMap[String, Integer], Int) = {
669674
val errorMap = new HashMap[String, Integer]()
670675
var expectedErrors = 0
671676
files.filter(_.getName.endsWith(".scala")).foreach { file =>
@@ -711,7 +716,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
711716

712717
private final class NoCrashTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)(implicit summaryReport: SummaryReporting)
713718
extends Test(testSources, times, threadLimit, suppressAllOutput) {
714-
override protected def encapsulatedCompilation(testSource: TestSource) = new LoggedRunnable {
719+
override def encapsulatedCompilation(testSource: TestSource) = new LoggedRunnable {
715720
def checkTestSource(): Unit = tryCompile(testSource) {
716721
def fail(msg: String): Nothing = {
717722
echo(msg)

0 commit comments

Comments
 (0)