Skip to content

Commit c56b981

Browse files
committed
Cleaner, quieter test rig tests
1 parent cbc3edb commit c56b981

File tree

2 files changed

+66
-75
lines changed

2 files changed

+66
-75
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,14 +1352,14 @@ trait ParallelTesting extends RunnerOrchestration:
13521352
* This behaviour is mainly needed for the tests that test the test suite.
13531353
*/
13541354
def expectFailure: CompilationTest =
1355-
new CompilationTest(targets, times, shouldDelete, threadLimit, true, shouldSuppressOutput)
1355+
new CompilationTest(targets, times, shouldDelete, threadLimit, shouldFail = true, shouldSuppressOutput)
13561356

13571357
/** Builds a `CompilationTest` where all output is suppressed
13581358
*
13591359
* This behaviour is mainly needed for the tests that test the test suite.
13601360
*/
13611361
def suppressAllOutput: CompilationTest =
1362-
new CompilationTest(targets, times, shouldDelete, threadLimit, shouldFail, true)
1362+
new CompilationTest(targets, times, shouldDelete, threadLimit, shouldFail, shouldSuppressOutput = true)
13631363

13641364
/** Delete all output files generated by this `CompilationTest` */
13651365
def delete(): Unit = targets.foreach(t => delete(t.outDir))
Lines changed: 64 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,99 @@
11
package dotty.tools
22
package vulpix
33

4-
import scala.language.unsafeNulls
5-
6-
import java.io.{File => JFile}
7-
import org.junit.Assert._
8-
import org.junit.{ Test, AfterClass }
9-
10-
import scala.concurrent.duration._
11-
import scala.util.control.NonFatal
4+
import org.junit.{Test as test, AfterClass as tearDown}
125

136
/** Unit tests for the Vulpix test suite */
14-
class VulpixUnitTests {
15-
import VulpixUnitTests._
16-
import TestConfiguration._
7+
class VulpixUnitTests:
8+
import VulpixUnitTests.*
9+
import TestConfiguration.*
1710

18-
implicit val _: SummaryReporting = new NoSummaryReport
11+
given SummaryReporting = new NoSummaryReport
1912

20-
implicit def testGroup: TestGroup = TestGroup("VulpixTests")
13+
given TestGroup = TestGroup("VulpixTests")
2114

22-
// To fail with something else than an AssertionError
23-
def fail(): Unit = throw new Exception("didn't fail properly")
24-
25-
@Test def missingFile: Unit =
26-
try {
15+
@test def missingFile: Unit =
16+
assertThrows[IllegalArgumentException](_ => true):
2717
compileFile("tests/vulpix-tests/unit/i-dont-exist.scala", defaultOptions).expectFailure.checkExpectedErrors()
28-
fail()
29-
} catch {
30-
case _: IllegalArgumentException => // pass!
31-
}
3218

33-
@Test def pos1Error: Unit =
19+
@test def pos1Error: Unit =
3420
compileFile("tests/vulpix-tests/unit/posFail1Error.scala", defaultOptions).expectFailure.checkCompile()
3521

36-
@Test def negMissingAnnot: Unit =
37-
compileFile("tests/vulpix-tests/unit/negMissingAnnot.scala", defaultOptions).expectFailure.checkExpectedErrors()
38-
39-
@Test def negAnnotWrongLine: Unit =
40-
compileFile("tests/vulpix-tests/unit/negAnnotWrongLine.scala", defaultOptions).expectFailure.checkExpectedErrors()
41-
42-
@Test def negTooManyAnnots: Unit =
43-
compileFile("tests/vulpix-tests/unit/negTooManyAnnots.scala", defaultOptions).expectFailure.checkExpectedErrors()
44-
45-
@Test def negNoPositionAnnot: Unit =
46-
compileFile("tests/vulpix-tests/unit/negNoPositionAnnots.scala", defaultOptions).expectFailure.checkExpectedErrors()
47-
48-
@Test def negAnyPositionAnnot: Unit =
49-
compileFile("tests/vulpix-tests/unit/negAnyPositionAnnots.scala", defaultOptions).checkExpectedErrors()
50-
51-
@Test def runCompileFail: Unit =
22+
@test def negMissingAnnot: Unit =
23+
compileFile("tests/vulpix-tests/unit/negMissingAnnot.scala", defaultOptions)
24+
.suppressAllOutput
25+
.expectFailure
26+
.checkExpectedErrors()
27+
28+
@test def negAnnotWrongLine: Unit =
29+
compileFile("tests/vulpix-tests/unit/negAnnotWrongLine.scala", defaultOptions)
30+
.suppressAllOutput
31+
.expectFailure
32+
.checkExpectedErrors()
33+
34+
@test def negTooManyAnnots: Unit =
35+
compileFile("tests/vulpix-tests/unit/negTooManyAnnots.scala", defaultOptions)
36+
.suppressAllOutput
37+
.expectFailure
38+
.checkExpectedErrors()
39+
40+
@test def negNoPositionAnnot: Unit =
41+
compileFile("tests/vulpix-tests/unit/negNoPositionAnnots.scala", defaultOptions)
42+
.suppressAllOutput
43+
.expectFailure
44+
.checkExpectedErrors()
45+
46+
@test def negAnyPositionAnnot: Unit =
47+
compileFile("tests/vulpix-tests/unit/negAnyPositionAnnots.scala", defaultOptions)
48+
.suppressAllOutput
49+
.checkExpectedErrors()
50+
51+
@test def runCompileFail: Unit =
5252
compileFile("tests/vulpix-tests/unit/posFail1Error.scala", defaultOptions).expectFailure.checkRuns()
5353

54-
@Test def runWrongOutput1: Unit =
54+
@test def runWrongOutput1: Unit =
5555
compileFile("tests/vulpix-tests/unit/runWrongOutput1.scala", defaultOptions).expectFailure.checkRuns()
5656

57-
@Test def runWrongOutput2: Unit =
57+
@test def runWrongOutput2: Unit =
5858
compileFile("tests/vulpix-tests/unit/runWrongOutput2.scala", defaultOptions).expectFailure.checkRuns()
5959

60-
@Test def runDiffOutput1: Unit =
60+
@test def runDiffOutput1: Unit =
6161
compileFile("tests/vulpix-tests/unit/runDiffOutput1.scala", defaultOptions).expectFailure.checkRuns()
6262

63-
@Test def runStackOverflow: Unit =
63+
@test def runStackOverflow: Unit =
6464
compileFile("tests/vulpix-tests/unit/stackOverflow.scala", defaultOptions).expectFailure.checkRuns()
6565

66-
@Test def runOutRedirects: Unit =
66+
@test def runOutRedirects: Unit =
6767
compileFile("tests/vulpix-tests/unit/i2147.scala", defaultOptions).expectFailure.checkRuns()
6868

69-
@Test def infiteNonRec: Unit =
69+
@test def infiniteNonRec: Unit =
7070
compileFile("tests/vulpix-tests/unit/infinite.scala", defaultOptions).expectFailure.checkRuns()
7171

72-
@Test def infiteTailRec: Unit =
72+
@test def infiniteTailRec: Unit =
7373
compileFile("tests/vulpix-tests/unit/infiniteTail.scala", defaultOptions).expectFailure.checkRuns()
7474

75-
@Test def infiniteAlloc: Unit =
75+
@test def infiniteAlloc: Unit =
7676
compileFile("tests/vulpix-tests/unit/infiniteAlloc.scala", defaultOptions).expectFailure.checkRuns()
7777

78-
@Test def deadlock: Unit =
78+
@test def deadlock: Unit =
7979
compileFile("tests/vulpix-tests/unit/deadlock.scala", defaultOptions).expectFailure.checkRuns()
8080

81-
@Test def badJava: Unit =
82-
try {
83-
compileFile("tests/vulpix-tests/unit/BadJava.java", defaultOptions).suppressAllOutput.checkCompile()
84-
fail()
85-
} catch {
86-
case ae: AssertionError => assertTrue(ae.getMessage.contains("java compilation failed"))
87-
}
81+
@test def badJava: Unit =
82+
assertThrows[AssertionError](_.getMessage.contains("java compilation failed")):
83+
compileFile("tests/vulpix-tests/unit/BadJava.java", defaultOptions)
84+
.suppressAllOutput
85+
.checkCompile()
8886

89-
@Test def runTimeout: Unit = {
87+
@test def runTimeout: Unit =
9088
val fileName = s"tests/vulpix-tests/unit/timeout.scala"
91-
try {
92-
compileFile(fileName, defaultOptions).checkRuns()
93-
fail()
94-
} catch {
95-
case ae: AssertionError =>
96-
val expect = """(?m).*test '.+' timed out.*"""
97-
val actual = ae.getMessage.linesIterator.toList.last
98-
assert(actual.matches(expect), "actual = " + actual)
99-
}
100-
}
101-
}
102-
103-
104-
object VulpixUnitTests extends ParallelTesting {
89+
val expect = """(?m).*test '.+' timed out.*"""
90+
assertThrows[AssertionError](_.getMessage.linesIterator.toList.last.matches(expect)):
91+
compileFile(fileName, defaultOptions)
92+
.suppressAllOutput
93+
.checkRuns()
94+
95+
object VulpixUnitTests extends ParallelTesting:
96+
import scala.concurrent.duration.*
10597
def maxDuration = 3.seconds
10698
def numberOfSlaves = 5
10799
def safeMode = sys.env.get("SAFEMODE").isDefined
@@ -110,6 +102,5 @@ object VulpixUnitTests extends ParallelTesting {
110102
def updateCheckFiles: Boolean = false
111103
def failedTests = None
112104

113-
@AfterClass
114-
def tearDown() = this.cleanup()
115-
}
105+
@tearDown
106+
def tearDown() = cleanup()

0 commit comments

Comments
 (0)