From c56b9810b25eb84e600cd38b0fb8d1303b5790bc Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Thu, 25 Sep 2025 06:26:40 -0700 Subject: [PATCH] Cleaner, quieter test rig tests --- .../dotty/tools/vulpix/ParallelTesting.scala | 4 +- .../dotty/tools/vulpix/VulpixUnitTests.scala | 137 ++++++++---------- 2 files changed, 66 insertions(+), 75 deletions(-) diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index e84b721b0bb0..3a2f261a8e16 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -1352,14 +1352,14 @@ trait ParallelTesting extends RunnerOrchestration: * This behaviour is mainly needed for the tests that test the test suite. */ def expectFailure: CompilationTest = - new CompilationTest(targets, times, shouldDelete, threadLimit, true, shouldSuppressOutput) + new CompilationTest(targets, times, shouldDelete, threadLimit, shouldFail = true, shouldSuppressOutput) /** Builds a `CompilationTest` where all output is suppressed * * This behaviour is mainly needed for the tests that test the test suite. */ def suppressAllOutput: CompilationTest = - new CompilationTest(targets, times, shouldDelete, threadLimit, shouldFail, true) + new CompilationTest(targets, times, shouldDelete, threadLimit, shouldFail, shouldSuppressOutput = true) /** Delete all output files generated by this `CompilationTest` */ def delete(): Unit = targets.foreach(t => delete(t.outDir)) diff --git a/compiler/test/dotty/tools/vulpix/VulpixUnitTests.scala b/compiler/test/dotty/tools/vulpix/VulpixUnitTests.scala index ab8a611caa33..eaa071c487c2 100644 --- a/compiler/test/dotty/tools/vulpix/VulpixUnitTests.scala +++ b/compiler/test/dotty/tools/vulpix/VulpixUnitTests.scala @@ -1,107 +1,99 @@ package dotty.tools package vulpix -import scala.language.unsafeNulls - -import java.io.{File => JFile} -import org.junit.Assert._ -import org.junit.{ Test, AfterClass } - -import scala.concurrent.duration._ -import scala.util.control.NonFatal +import org.junit.{Test as test, AfterClass as tearDown} /** Unit tests for the Vulpix test suite */ -class VulpixUnitTests { - import VulpixUnitTests._ - import TestConfiguration._ +class VulpixUnitTests: + import VulpixUnitTests.* + import TestConfiguration.* - implicit val _: SummaryReporting = new NoSummaryReport + given SummaryReporting = new NoSummaryReport - implicit def testGroup: TestGroup = TestGroup("VulpixTests") + given TestGroup = TestGroup("VulpixTests") - // To fail with something else than an AssertionError - def fail(): Unit = throw new Exception("didn't fail properly") - - @Test def missingFile: Unit = - try { + @test def missingFile: Unit = + assertThrows[IllegalArgumentException](_ => true): compileFile("tests/vulpix-tests/unit/i-dont-exist.scala", defaultOptions).expectFailure.checkExpectedErrors() - fail() - } catch { - case _: IllegalArgumentException => // pass! - } - @Test def pos1Error: Unit = + @test def pos1Error: Unit = compileFile("tests/vulpix-tests/unit/posFail1Error.scala", defaultOptions).expectFailure.checkCompile() - @Test def negMissingAnnot: Unit = - compileFile("tests/vulpix-tests/unit/negMissingAnnot.scala", defaultOptions).expectFailure.checkExpectedErrors() - - @Test def negAnnotWrongLine: Unit = - compileFile("tests/vulpix-tests/unit/negAnnotWrongLine.scala", defaultOptions).expectFailure.checkExpectedErrors() - - @Test def negTooManyAnnots: Unit = - compileFile("tests/vulpix-tests/unit/negTooManyAnnots.scala", defaultOptions).expectFailure.checkExpectedErrors() - - @Test def negNoPositionAnnot: Unit = - compileFile("tests/vulpix-tests/unit/negNoPositionAnnots.scala", defaultOptions).expectFailure.checkExpectedErrors() - - @Test def negAnyPositionAnnot: Unit = - compileFile("tests/vulpix-tests/unit/negAnyPositionAnnots.scala", defaultOptions).checkExpectedErrors() - - @Test def runCompileFail: Unit = + @test def negMissingAnnot: Unit = + compileFile("tests/vulpix-tests/unit/negMissingAnnot.scala", defaultOptions) + .suppressAllOutput + .expectFailure + .checkExpectedErrors() + + @test def negAnnotWrongLine: Unit = + compileFile("tests/vulpix-tests/unit/negAnnotWrongLine.scala", defaultOptions) + .suppressAllOutput + .expectFailure + .checkExpectedErrors() + + @test def negTooManyAnnots: Unit = + compileFile("tests/vulpix-tests/unit/negTooManyAnnots.scala", defaultOptions) + .suppressAllOutput + .expectFailure + .checkExpectedErrors() + + @test def negNoPositionAnnot: Unit = + compileFile("tests/vulpix-tests/unit/negNoPositionAnnots.scala", defaultOptions) + .suppressAllOutput + .expectFailure + .checkExpectedErrors() + + @test def negAnyPositionAnnot: Unit = + compileFile("tests/vulpix-tests/unit/negAnyPositionAnnots.scala", defaultOptions) + .suppressAllOutput + .checkExpectedErrors() + + @test def runCompileFail: Unit = compileFile("tests/vulpix-tests/unit/posFail1Error.scala", defaultOptions).expectFailure.checkRuns() - @Test def runWrongOutput1: Unit = + @test def runWrongOutput1: Unit = compileFile("tests/vulpix-tests/unit/runWrongOutput1.scala", defaultOptions).expectFailure.checkRuns() - @Test def runWrongOutput2: Unit = + @test def runWrongOutput2: Unit = compileFile("tests/vulpix-tests/unit/runWrongOutput2.scala", defaultOptions).expectFailure.checkRuns() - @Test def runDiffOutput1: Unit = + @test def runDiffOutput1: Unit = compileFile("tests/vulpix-tests/unit/runDiffOutput1.scala", defaultOptions).expectFailure.checkRuns() - @Test def runStackOverflow: Unit = + @test def runStackOverflow: Unit = compileFile("tests/vulpix-tests/unit/stackOverflow.scala", defaultOptions).expectFailure.checkRuns() - @Test def runOutRedirects: Unit = + @test def runOutRedirects: Unit = compileFile("tests/vulpix-tests/unit/i2147.scala", defaultOptions).expectFailure.checkRuns() - @Test def infiteNonRec: Unit = + @test def infiniteNonRec: Unit = compileFile("tests/vulpix-tests/unit/infinite.scala", defaultOptions).expectFailure.checkRuns() - @Test def infiteTailRec: Unit = + @test def infiniteTailRec: Unit = compileFile("tests/vulpix-tests/unit/infiniteTail.scala", defaultOptions).expectFailure.checkRuns() - @Test def infiniteAlloc: Unit = + @test def infiniteAlloc: Unit = compileFile("tests/vulpix-tests/unit/infiniteAlloc.scala", defaultOptions).expectFailure.checkRuns() - @Test def deadlock: Unit = + @test def deadlock: Unit = compileFile("tests/vulpix-tests/unit/deadlock.scala", defaultOptions).expectFailure.checkRuns() - @Test def badJava: Unit = - try { - compileFile("tests/vulpix-tests/unit/BadJava.java", defaultOptions).suppressAllOutput.checkCompile() - fail() - } catch { - case ae: AssertionError => assertTrue(ae.getMessage.contains("java compilation failed")) - } + @test def badJava: Unit = + assertThrows[AssertionError](_.getMessage.contains("java compilation failed")): + compileFile("tests/vulpix-tests/unit/BadJava.java", defaultOptions) + .suppressAllOutput + .checkCompile() - @Test def runTimeout: Unit = { + @test def runTimeout: Unit = val fileName = s"tests/vulpix-tests/unit/timeout.scala" - try { - compileFile(fileName, defaultOptions).checkRuns() - fail() - } catch { - case ae: AssertionError => - val expect = """(?m).*test '.+' timed out.*""" - val actual = ae.getMessage.linesIterator.toList.last - assert(actual.matches(expect), "actual = " + actual) - } - } -} - - -object VulpixUnitTests extends ParallelTesting { + val expect = """(?m).*test '.+' timed out.*""" + assertThrows[AssertionError](_.getMessage.linesIterator.toList.last.matches(expect)): + compileFile(fileName, defaultOptions) + .suppressAllOutput + .checkRuns() + +object VulpixUnitTests extends ParallelTesting: + import scala.concurrent.duration.* def maxDuration = 3.seconds def numberOfSlaves = 5 def safeMode = sys.env.get("SAFEMODE").isDefined @@ -110,6 +102,5 @@ object VulpixUnitTests extends ParallelTesting { def updateCheckFiles: Boolean = false def failedTests = None - @AfterClass - def tearDown() = this.cleanup() -} \ No newline at end of file + @tearDown + def tearDown() = cleanup()