Skip to content

Commit b5b6f5e

Browse files
committed
Fix test reporting for exceptions in compiler
1 parent 8dc162c commit b5b6f5e

File tree

1 file changed

+45
-40
lines changed

1 file changed

+45
-40
lines changed

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

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ trait ParallelTesting {
4646
* in a specific way defined by the `Test`
4747
*/
4848
private sealed trait TestSource { self =>
49+
def name: String
4950
def outDir: JFile
5051
def flags: Array[String]
5152

@@ -80,7 +81,7 @@ trait ParallelTesting {
8081
}
8182

8283
self match {
83-
case JointCompilationSource(files, _, _) => {
84+
case JointCompilationSource(_, files, _, _) => {
8485
files.map(_.getAbsolutePath).foreach { path =>
8586
sb.append("\\\n ")
8687
sb.append(path)
@@ -111,6 +112,7 @@ trait ParallelTesting {
111112
* and output directory
112113
*/
113114
private final case class JointCompilationSource(
115+
name: String,
114116
files: Array[JFile],
115117
flags: Array[String],
116118
outDir: JFile
@@ -124,6 +126,7 @@ trait ParallelTesting {
124126
* suffix `_X`
125127
*/
126128
private final case class SeparateCompilationSource(
129+
name: String,
127130
dir: JFile,
128131
flags: Array[String],
129132
outDir: JFile
@@ -164,9 +167,9 @@ trait ParallelTesting {
164167
private val filteredSources =
165168
if (!testFilter.isDefined) testSources
166169
else testSources.filter {
167-
case JointCompilationSource(files, _, _) =>
170+
case JointCompilationSource(_, files, _, _) =>
168171
files.exists(file => testFilter.get.findFirstIn(file.getAbsolutePath).isDefined)
169-
case SeparateCompilationSource(dir, _, _) =>
172+
case SeparateCompilationSource(_, dir, _, _) =>
170173
testFilter.get.findFirstIn(dir.getAbsolutePath).isDefined
171174
}
172175

@@ -206,19 +209,10 @@ trait ParallelTesting {
206209

207210
/** The test sources that failed according to the implementing subclass */
208211
private[this] val failedTestSources = mutable.ArrayBuffer.empty[String]
209-
protected final def addFailedCompilationTarget(testSource: String): Unit =
210-
synchronized { failedTestSources.append(testSource) }
211-
212-
/** Fails the current `TestSource`, and makes sure it gets logged */
213-
protected final def failTestSource(testSource: TestSource) =
214-
testSource match {
215-
case JointCompilationSource(files, _, _) =>
216-
files.map(_.getAbsolutePath).foreach(addFailedCompilationTarget)
217-
fail()
218-
case SeparateCompilationSource(dir, _, _) =>
219-
addFailedCompilationTarget(dir.getAbsolutePath)
220-
fail()
221-
}
212+
protected final def failTestSource(testSource: TestSource) = synchronized {
213+
failedTestSources.append(testSource.name)
214+
fail()
215+
}
222216

223217
/** Prints to `System.err` if we're not suppressing all output */
224218
protected def echo(msg: String): Unit =
@@ -252,12 +246,12 @@ trait ParallelTesting {
252246
/** Wrapper function to make sure that the compiler itself did not crash -
253247
* if it did, the test should automatically fail.
254248
*/
255-
protected def tryCompile(op: => Unit): Unit =
249+
protected def tryCompile(testSource: TestSource)(op: => Unit): Unit =
256250
try op catch {
257251
case NonFatal(e) => {
258252
// if an exception is thrown during compilation, the complete test
259253
// run should fail
260-
fail()
254+
failTestSource(testSource)
261255
e.printStackTrace()
262256
registerCompilation(1)
263257
throw e
@@ -353,12 +347,17 @@ trait ParallelTesting {
353347
if (didFail) {
354348
echo {
355349
"""|
350+
|
351+
|
356352
|================================================================================
357353
|Test Report
358354
|================================================================================
359355
|Failing tests:""".stripMargin
360356
}
361-
failedTestSources.toArray.sorted.foreach(echo)
357+
failedTestSources.toSet.foreach { source: String =>
358+
echo(" " + source)
359+
}
360+
echo("")
362361
reproduceInstructions.iterator.foreach(echo)
363362
}
364363
}
@@ -375,17 +374,17 @@ trait ParallelTesting {
375374
private final class PosTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)
376375
extends Test(testSources, times, threadLimit, suppressAllOutput) {
377376
protected def compilationRunnable(testSource: TestSource): Runnable = new Runnable {
378-
def run(): Unit = tryCompile {
377+
def run(): Unit = tryCompile(testSource) {
379378
testSource match {
380-
case testSource @ JointCompilationSource(files, flags, outDir) => {
379+
case testSource @ JointCompilationSource(_, files, flags, outDir) => {
381380
val reporter = compile(testSource.sourceFiles, flags, false, outDir)
382381
registerCompilation(reporter.errorCount)
383382

384383
if (reporter.errorCount > 0)
385384
echoBuildInstructions(reporter, testSource, reporter.errorCount, reporter.warningCount)
386385
}
387386

388-
case testSource @ SeparateCompilationSource(dir, flags, outDir) => {
387+
case testSource @ SeparateCompilationSource(_, dir, flags, outDir) => {
389388
val reporters = testSource.compilationGroups.map(files => compile(files, flags, false, outDir))
390389
val errorCount = reporters.foldLeft(0) { (acc, reporter) =>
391390
if (reporter.errorCount > 0)
@@ -470,9 +469,9 @@ trait ParallelTesting {
470469
}
471470

472471
protected def compilationRunnable(testSource: TestSource): Runnable = new Runnable {
473-
def run(): Unit = tryCompile {
472+
def run(): Unit = tryCompile(testSource) {
474473
val (errorCount, warningCount, hasCheckFile, verifier: Function0[Unit]) = testSource match {
475-
case testSource @ JointCompilationSource(files, flags, outDir) => {
474+
case testSource @ JointCompilationSource(_, files, flags, outDir) => {
476475
val checkFile = files.flatMap { file =>
477476
if (file.isDirectory) Nil
478477
else {
@@ -491,7 +490,7 @@ trait ParallelTesting {
491490
(reporter.errorCount, reporter.warningCount, checkFile.isDefined, () => verifyOutput(checkFile.get, outDir, testSource, reporter.warningCount))
492491
}
493492

494-
case testSource @ SeparateCompilationSource(dir, flags, outDir) => {
493+
case testSource @ SeparateCompilationSource(_, dir, flags, outDir) => {
495494
val checkFile = new JFile(dir.getAbsolutePath.reverse.dropWhile(_ == '/').reverse + ".check")
496495
val (errorCount, warningCount) =
497496
testSource
@@ -526,7 +525,7 @@ trait ParallelTesting {
526525
private final class NegTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)
527526
extends Test(testSources, times, threadLimit, suppressAllOutput) {
528527
protected def compilationRunnable(testSource: TestSource): Runnable = new Runnable {
529-
def run(): Unit = tryCompile {
528+
def run(): Unit = tryCompile(testSource) {
530529
// In neg-tests we allow two types of error annotations,
531530
// "nopos-error" which doesn't care about position and "error" which
532531
// has to be annotated on the correct line number.
@@ -579,7 +578,7 @@ trait ParallelTesting {
579578
}
580579

581580
val (expectedErrors, actualErrors, hasMissingAnnotations, errorMap) = testSource match {
582-
case testSource @ JointCompilationSource(files, flags, outDir) => {
581+
case testSource @ JointCompilationSource(_, files, flags, outDir) => {
583582
val sourceFiles = testSource.sourceFiles
584583
val (errorMap, expectedErrors) = getErrorMapAndExpectedCount(sourceFiles)
585584
val reporter = compile(sourceFiles, flags, true, outDir)
@@ -588,7 +587,7 @@ trait ParallelTesting {
588587
(expectedErrors, actualErrors, () => getMissingExpectedErrors(errorMap, reporter.errors), errorMap)
589588
}
590589

591-
case testSource @ SeparateCompilationSource(dir, flags, outDir) => {
590+
case testSource @ SeparateCompilationSource(_, dir, flags, outDir) => {
592591
val compilationGroups = testSource.compilationGroups
593592
val (errorMap, expectedErrors) = getErrorMapAndExpectedCount(compilationGroups.toArray.flatten)
594593
val reporters = compilationGroups.map(compile(_, flags, true, outDir))
@@ -837,9 +836,9 @@ trait ParallelTesting {
837836
*/
838837
def copyToTarget(): CompilationTest = new CompilationTest (
839838
targets.map {
840-
case target @ JointCompilationSource(files, _, outDir) =>
839+
case target @ JointCompilationSource(_, files, _, outDir) =>
841840
target.copy(files = files.map(copyToDir(outDir,_)))
842-
case target @ SeparateCompilationSource(dir, _, outDir) =>
841+
case target @ SeparateCompilationSource(_, dir, _, outDir) =>
843842
target.copy(dir = copyToDir(outDir, dir))
844843
},
845844
times, shouldDelete, threadLimit, shouldFail
@@ -950,10 +949,11 @@ trait ParallelTesting {
950949

951950
/** Compiles a single file from the string path `f` using the supplied flags */
952951
def compileFile(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = {
952+
val callingMethod = getCallingMethod
953953
val sourceFile = new JFile(f)
954954
val parent = sourceFile.getParentFile
955955
val outDir =
956-
outDirectory + getCallingMethod + "/" +
956+
outDirectory + callingMethod + "/" +
957957
sourceFile.getName.substring(0, sourceFile.getName.lastIndexOf('.')) + "/"
958958

959959
require(
@@ -963,6 +963,7 @@ trait ParallelTesting {
963963
)
964964

965965
val target = JointCompilationSource(
966+
callingMethod,
966967
Array(sourceFile),
967968
flags,
968969
createOutputDirsForFile(sourceFile, parent, outDir)
@@ -975,7 +976,8 @@ trait ParallelTesting {
975976
* contained within the directory `f`.
976977
*/
977978
def compileDir(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = {
978-
val outDir = outDirectory + getCallingMethod + "/"
979+
val callingMethod = getCallingMethod
980+
val outDir = outDirectory + callingMethod + "/"
979981
val sourceDir = new JFile(f)
980982
checkRequirements(f, sourceDir, outDir)
981983

@@ -987,7 +989,7 @@ trait ParallelTesting {
987989
val targetDir = new JFile(outDir + "/" + sourceDir.getName + "/")
988990
targetDir.mkdirs()
989991

990-
val target = JointCompilationSource(flatten(sourceDir), flags, targetDir)
992+
val target = JointCompilationSource(callingMethod, flatten(sourceDir), flags, targetDir)
991993
new CompilationTest(target)
992994
}
993995

@@ -996,14 +998,15 @@ trait ParallelTesting {
996998
* dissociated
997999
*/
9981000
def compileList(testName: String, files: List[String], flags: Array[String])(implicit outDirectory: String): CompilationTest = {
999-
val outDir = outDirectory + getCallingMethod + "/" + testName + "/"
1001+
val callingMethod = getCallingMethod
1002+
val outDir = outDirectory + callingMethod + "/" + testName + "/"
10001003

10011004
// Directories in which to compile all containing files with `flags`:
10021005
val targetDir = new JFile(outDir)
10031006
targetDir.mkdirs()
10041007
assert(targetDir.exists, s"couldn't create target directory: $targetDir")
10051008

1006-
val target = JointCompilationSource(files.map(new JFile(_)).toArray, flags, targetDir)
1009+
val target = JointCompilationSource(callingMethod, files.map(new JFile(_)).toArray, flags, targetDir)
10071010

10081011
// Create a CompilationTest and let the user decide whether to execute a pos or a neg test
10091012
new CompilationTest(target)
@@ -1027,15 +1030,16 @@ trait ParallelTesting {
10271030
* the same name as the directory (with the file extension `.check`)
10281031
*/
10291032
def compileFilesInDir(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = {
1030-
val outDir = outDirectory + getCallingMethod + "/"
1033+
val callingMethod = getCallingMethod
1034+
val outDir = outDirectory + callingMethod + "/"
10311035
val sourceDir = new JFile(f)
10321036
checkRequirements(f, sourceDir, outDir)
10331037

10341038
val (dirs, files) = compilationTargets(sourceDir)
10351039

10361040
val targets =
1037-
files.map(f => JointCompilationSource(Array(f), flags, createOutputDirsForFile(f, sourceDir, outDir))) ++
1038-
dirs.map(dir => SeparateCompilationSource(dir, flags, createOutputDirsForDir(dir, sourceDir, outDir)))
1041+
files.map(f => JointCompilationSource(callingMethod, Array(f), flags, createOutputDirsForFile(f, sourceDir, outDir))) ++
1042+
dirs.map(dir => SeparateCompilationSource(callingMethod, dir, flags, createOutputDirsForDir(dir, sourceDir, outDir)))
10391043

10401044
// Create a CompilationTest and let the user decide whether to execute a pos or a neg test
10411045
new CompilationTest(targets)
@@ -1046,14 +1050,15 @@ trait ParallelTesting {
10461050
* tests.
10471051
*/
10481052
def compileShallowFilesInDir(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = {
1049-
val outDir = outDirectory + getCallingMethod + "/"
1053+
val callingMethod = getCallingMethod
1054+
val outDir = outDirectory + callingMethod + "/"
10501055
val sourceDir = new JFile(f)
10511056
checkRequirements(f, sourceDir, outDir)
10521057

10531058
val (_, files) = compilationTargets(sourceDir)
10541059

10551060
val targets = files.map { file =>
1056-
JointCompilationSource(Array(file), flags, createOutputDirsForFile(file, sourceDir, outDir))
1061+
JointCompilationSource(callingMethod, Array(file), flags, createOutputDirsForFile(file, sourceDir, outDir))
10571062
}
10581063

10591064
// Create a CompilationTest and let the user decide whether to execute a pos or a neg test

0 commit comments

Comments
 (0)