Skip to content

Commit 9b42731

Browse files
authored
Merge pull request #4383 from dotty-staging/test-replace-errors-by-failures
Test reporting should consistently count and report test failures, not compiler errors
2 parents 3026574 + 4300c07 commit 9b42731

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,12 @@ trait ParallelTesting extends RunnerOrchestration { self =>
226226
/** Total amount of test sources being compiled by this test */
227227
val sourceCount = filteredSources.length
228228

229-
private[this] var _errorCount = 0
230-
def errorCount: Int = _errorCount
231-
232229
private[this] var _testSourcesCompleted = 0
233230
private def testSourcesCompleted: Int = _testSourcesCompleted
234231

235232
/** Complete the current compilation with the amount of errors encountered */
236-
protected final def registerCompletion(errors: Int) = synchronized {
233+
protected final def registerCompletion() = synchronized {
237234
_testSourcesCompleted += 1
238-
_errorCount += errors
239235
}
240236

241237
sealed trait Failure
@@ -244,17 +240,20 @@ trait ParallelTesting extends RunnerOrchestration { self =>
244240
case object Generic extends Failure
245241

246242
private[this] var _failures = Set.empty[Failure]
243+
private[this] var _failureCount = 0
244+
247245
/** Fail the current test */
248246
protected[this] final def fail(failure: Failure = Generic): Unit = synchronized {
249247
_failures = _failures + failure
248+
_failureCount = _failureCount + 1
250249
}
251-
def didFail: Boolean = _failures.nonEmpty
250+
def didFail: Boolean = _failureCount != 0
252251

253252
/** A set of the different failures */
254253
def failureReasons: Set[Failure] = _failures
255254

256255
/** Number of failed tests */
257-
def failureCount: Int = _failures.size
256+
def failureCount: Int = _failureCount
258257

259258
protected def logBuildInstructions(reporter: TestReporter, testSource: TestSource, err: Int, war: Int) = {
260259
val errorMsg = testSource.buildInstructions(reporter.errorCount, reporter.warningCount)
@@ -327,7 +326,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
327326
// run should fail
328327
failTestSource(testSource)
329328
e.printStackTrace()
330-
registerCompletion(1)
329+
registerCompletion()
331330
throw e
332331
}
333332
}
@@ -555,7 +554,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
555554
}
556555
else if (fromTasty) compileFromTasty(flags, false, outDir)
557556
else compile(testSource.sourceFiles, flags, false, outDir)
558-
registerCompletion(reporter.errorCount)
557+
registerCompletion()
559558

560559
if (reporter.compilerCrashed || reporter.errorCount > 0) {
561560
logReporterContents(reporter)
@@ -574,7 +573,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
574573

575574
def warningCount = reporters.foldLeft(0)(_ + _.warningCount)
576575

577-
registerCompletion(errorCount)
576+
registerCompletion()
578577

579578
if (compilerCrashed || errorCount > 0) {
580579
reporters.foreach(logReporterContents)
@@ -695,7 +694,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
695694
addFailureInstruction(buildInstr)
696695
failTestSource(testSource)
697696
}
698-
registerCompletion(errorCount)
697+
registerCompletion()
699698
}
700699
}
701700
}
@@ -748,9 +747,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
748747
true
749748
}
750749
else {
751-
echo {
752-
s"Error reported in ${error.pos.source}, but no annotation found"
753-
}
750+
echo(s"Error reported in ${error.pos.source}, but no annotation found")
754751
false
755752
}
756753
}
@@ -798,7 +795,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
798795
else if (!errorMap.isEmpty)
799796
fail(s"\nExpected error(s) have {<error position>=<unreported error>}: $errorMap")
800797

801-
registerCompletion(actualErrors)
798+
registerCompletion()
802799
}
803800
}
804801
}
@@ -1012,11 +1009,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
10121009

10131010
/** Extract `Failure` set and render from `Test` */
10141011
private[this] def reasonsForFailure(test: Test): String = {
1015-
val errors =
1016-
if (test.errorCount == 0) ""
1017-
else s"\n - encountered ${test.errorCount} error(s)"
1012+
val failureReport =
1013+
if (test.failureCount == 0) ""
1014+
else s"\n - encountered ${test.failureCount} test failures(s)"
10181015

1019-
errors + test.failureReasons.collect {
1016+
failureReport + test.failureReasons.collect {
10201017
case test.TimeoutFailure(title) =>
10211018
s" - test '$title' timed out"
10221019
case test.JavaCompilationFailure(msg) =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ final class SummaryReport extends SummaryReporting {
9898
|Test Report
9999
|================================================================================
100100
|
101-
|$passed passed, $failed failed, ${passed + failed} total
101+
|$passed suites passed, $failed failed, ${passed + failed} total
102102
|""".stripMargin
103103
)
104104

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ class VulpixUnitTests extends ParallelTesting {
9191
fail()
9292
} catch {
9393
case ae: AssertionError =>
94-
assertEquals(ae.getMessage, "Run test failed, but should not, reasons:\n - test 'tests/vulpix-tests/unit/timeout.scala' timed out")
94+
assertEquals("Run test failed, but should not, reasons:\n\n - encountered 1 test failures(s) - test 'tests/vulpix-tests/unit/timeout.scala' timed out",
95+
ae.getMessage)
9596
}
9697
}
9798
}

tests/vulpix-tests/meta/sbt-output.check

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Diff (expected on the left, actual right):
88
EOF | EOF
99

1010
[error] Test dotty.tools.vulpix.VulpixMetaTests.runAll failed: java.lang.AssertionError: Run test failed, but should not, reasons:
11-
[error] , took 1.682 sec SKIP
11+
[error]
12+
[error] - encountered 1 test failures(s), took 3.697 sec SKIP
1213
[error] at dotty.tools.vulpix.ParallelTesting$CompilationTest.checkRuns(ParallelTesting.scala:993) SKIP
1314
[error] at dotty.tools.vulpix.VulpixMetaTests.runAll(VulpixMetaTests.scala:26) SKIP
1415
[error] ...
@@ -18,7 +19,7 @@ Testing tests/vulpix-tests/meta/neg/missing-error-annotation.scala
1819
Wrong number of errors encountered when compiling out/VulpixMetaTests/neg/missing-error-annotation, expected: 0, actual: 2
1920
[error] Test dotty.tools.vulpix.VulpixMetaTests.compileNeg failed: java.lang.AssertionError: Neg test shouldn't have failed, but did. Reasons:
2021
[error]
21-
[error] - encountered 2 error(s), took 0.093 sec SKIP
22+
[error] - encountered 1 test failures(s), took 0.156 sec SKIP
2223
[error] at dotty.tools.vulpix.ParallelTesting$CompilationTest.checkExpectedErrors(ParallelTesting.scala:975) SKIP
2324
[error] at dotty.tools.vulpix.VulpixMetaTests.compileNeg(VulpixMetaTests.scala:25) SKIP
2425
[error] ...
@@ -30,7 +31,7 @@ Testing tests/vulpix-tests/meta/pos/does-not-compile.scala
3031
| not found: a
3132
[error] Test dotty.tools.vulpix.VulpixMetaTests.compilePos failed: java.lang.AssertionError: Expected no errors when compiling, failed for the following reason(s):
3233
[error]
33-
[error] - encountered 1 error(s), took 0.069 sec SKIP
34+
[error] - encountered 1 test failure(s), took 0.069 sec SKIP
3435
[error] at dotty.tools.vulpix.ParallelTesting$CompilationTest.checkCompile(ParallelTesting.scala:958) SKIP
3536
[error] at dotty.tools.vulpix.VulpixMetaTests.compilePos(VulpixMetaTests.scala:24) SKIP
3637
[error] ...

0 commit comments

Comments
 (0)