From d42a28d07683d95e6dffd27cdb9078ebeb599c15 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Fri, 7 Apr 2017 14:46:17 +0200 Subject: Add ability to only compile run tests --- compiler/test/dotty/Properties.scala | 5 +++ .../test/dotty/tools/vulpix/ParallelTesting.scala | 38 +++++++++++++++------- .../test/dotty/tools/vulpix/SummaryReport.java | 19 +++++++++-- compiler/test/dotty/tools/vulpix/VulpixTests.scala | 3 -- tests/partest-test/forkbomb.scala | 7 ---- 5 files changed, 49 insertions(+), 23 deletions(-) delete mode 100644 tests/partest-test/forkbomb.scala diff --git a/compiler/test/dotty/Properties.scala b/compiler/test/dotty/Properties.scala index 6106c75b9..70db82092 100644 --- a/compiler/test/dotty/Properties.scala +++ b/compiler/test/dotty/Properties.scala @@ -20,6 +20,11 @@ object Properties { */ val testsFilter: Option[String] = sys.props.get("dotty.tests.filter") + /** When set, the run tests are only compiled - not run, a warning will be + * issued + */ + val testsNoRun: Boolean = sys.props.get("dotty.tests.norun").isDefined + /** Should Unit tests run in safe mode? * * For run tests this means that we respawn child JVM processes after each diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index 8cafd543b..e1babfb9c 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -426,8 +426,21 @@ trait ParallelTesting extends RunnerOrchestration { self => private final class RunTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean) extends Test(testSources, times, threadLimit, suppressAllOutput) { + private[this] var didAddNoRunWarning = false + private[this] def addNoRunWarning() = if (!didAddNoRunWarning) { + didAddNoRunWarning = true + SummaryReport.addStartingMessage { + """|WARNING + |------- + |Run tests were only compiled, not run - this is due to `dotty.tests.norun` + |property being set + |""".stripMargin + } + } + private def verifyOutput(checkFile: JFile, dir: JFile, testSource: TestSource, warnings: Int) = { - runMain(testSource.classPath) match { + if (Properties.testsNoRun) addNoRunWarning() + else runMain(testSource.classPath) match { case Success(output) => { val outputLines = output.lines.toArray val checkLines: Array[String] = Source.fromFile(checkFile).getLines.toArray @@ -511,16 +524,19 @@ trait ParallelTesting extends RunnerOrchestration { self => } if (errorCount == 0 && hasCheckFile) verifier() - else if (errorCount == 0) runMain(testSource.classPath) match { - case Success(_) => // success! - case Failure(output) => - echo(s" failed when running '${testSource.title}'") - echo(output) - failTestSource(testSource) - case Timeout => - echo(" failed because test " + testSource.title + " timed out") - failTestSource(testSource, Some("test timed out")) - } + else if (errorCount == 0) { + if (Properties.testsNoRun) addNoRunWarning() + else runMain(testSource.classPath) match { + case Success(_) => // success! + case Failure(output) => + echo(s" failed when running '${testSource.title}'") + echo(output) + failTestSource(testSource) + case Timeout => + echo(" failed because test " + testSource.title + " timed out") + failTestSource(testSource, Some("test timed out")) + } + } else if (errorCount > 0) { echo(s"\n Compilation failed for: '$testSource'") val buildInstr = testSource.buildInstructions(errorCount, warningCount) diff --git a/compiler/test/dotty/tools/vulpix/SummaryReport.java b/compiler/test/dotty/tools/vulpix/SummaryReport.java index 1a7fc2a61..23209eefc 100644 --- a/compiler/test/dotty/tools/vulpix/SummaryReport.java +++ b/compiler/test/dotty/tools/vulpix/SummaryReport.java @@ -10,8 +10,10 @@ import scala.Unit; import dotty.tools.dotc.reporting.TestReporter; import dotty.Properties; -/** Note that while `ParallelTesting` runs in parallel, JUnit tests cannot with - * this class +/** This class adds summary reports to `ParallelTesting` + * + * It is written in Java because we currently cannot explicitly write static + * methods in Scala without SIP-25 (`@static` fields and methods in Scala) */ public class SummaryReport { public final static boolean isInteractive = @@ -20,6 +22,7 @@ public class SummaryReport { private static TestReporter rep = TestReporter.reporter(System.out, -1); private static ArrayDeque failedTests = new ArrayDeque<>(); private static ArrayDeque reproduceInstructions = new ArrayDeque<>(); + private static ArrayDeque startingMessages = new ArrayDeque<>(); private static Supplier cleanup; private static int passed; private static int failed; @@ -40,6 +43,10 @@ public class SummaryReport { reproduceInstructions.offer(msg); } + public final static void addStartingMessage(String msg) { + startingMessages.offer(msg); + } + public final static void addCleanup(Function0 func) { // Wow, look at how neatly we - compose cleanup callbacks: if (cleanup == null) { @@ -61,6 +68,10 @@ public class SummaryReport { rep = TestReporter.reporter(System.out, -1); failedTests = new ArrayDeque<>(); reproduceInstructions = new ArrayDeque<>(); + startingMessages = new ArrayDeque<>(); + cleanup = null; + passed = 0; + failed = 0; } @AfterClass public final static void teardown() { @@ -73,6 +84,10 @@ public class SummaryReport { "\n" ); + startingMessages + .stream() + .forEach(rep::echo); + failedTests .stream() .map(x -> " " + x) diff --git a/compiler/test/dotty/tools/vulpix/VulpixTests.scala b/compiler/test/dotty/tools/vulpix/VulpixTests.scala index 2483bf6f0..646e1bb29 100644 --- a/compiler/test/dotty/tools/vulpix/VulpixTests.scala +++ b/compiler/test/dotty/tools/vulpix/VulpixTests.scala @@ -71,7 +71,4 @@ class VulpixTests extends ParallelTesting { @Test def deadlock: Unit = compileFile("../tests/partest-test/deadlock.scala", defaultOptions).expectFailure.checkRuns() - - @Test def forkbomb: Unit = - compileFile("../tests/partest-test/forkbomb.scala", defaultOptions).expectFailure.checkRuns() } diff --git a/tests/partest-test/forkbomb.scala b/tests/partest-test/forkbomb.scala deleted file mode 100644 index 1d3cda172..000000000 --- a/tests/partest-test/forkbomb.scala +++ /dev/null @@ -1,7 +0,0 @@ -object Test { - def main(args: Array[String]): Unit = - while(true) - Runtime - .getRuntime() - .exec(Array("java", "-cp", System.getProperty("java.class.path"), "Test")); -} -- cgit v1.2.3