diff --git a/compiler/test/dotc/comptest.scala b/compiler/test/dotc/comptest.scala index de9fb0b1e515..64caa6293f63 100644 --- a/compiler/test/dotc/comptest.scala +++ b/compiler/test/dotc/comptest.scala @@ -1,6 +1,6 @@ package dotc -import dotty.tools.vulpix.{ParallelTesting, TestFlags} +import dotty.tools.vulpix.{ParallelTesting, TestFlags, TestGroup} import scala.concurrent.duration._ @@ -24,7 +24,6 @@ object comptest extends ParallelTesting { dotcDir + "tools/dotc/core/Types.scala", dotcDir + "tools/dotc/ast/Trees.scala" ), - TestFlags("", Array("-Ylog:frontend", "-Xprompt")), - outDirectory = "." - ) + TestFlags("", Array("-Ylog:frontend", "-Xprompt")) + )(TestGroup("comptest")) } diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 53af559f0a86..cc69e927e26f 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -33,10 +33,12 @@ class CompilationTests extends ParallelTesting { // @Test // enable to test compileStdLib separately with detailed stats def compileStdLib: Unit = { + implicit val testGroup: TestGroup = TestGroup("compileStdLib") compileList("compileStdLib", StdLibSources.whitelisted, scala2Mode.and("-migration", "-Yno-inline", "-Ydetailed-stats")) }.checkCompile() @Test def compilePos: Unit = { + implicit val testGroup: TestGroup = TestGroup("compilePos") compileList("compileStdLib", StdLibSources.whitelisted, scala2Mode.and("-migration", "-Yno-inline")) + compileDir("../compiler/src/dotty/tools/dotc/ast", defaultOptions) + compileDir("../compiler/src/dotty/tools/dotc/config", defaultOptions) + @@ -102,6 +104,7 @@ class CompilationTests extends ParallelTesting { }.checkCompile() @Test def posTwice: Unit = { + implicit val testGroup: TestGroup = TestGroup("posTwice") compileFile("../tests/pos/Labels.scala", defaultOptions) + compileFilesInDir("../tests/pos-java-interop", defaultOptions) + compileFile("../tests/pos/t2168.scala", defaultOptions) + @@ -160,6 +163,7 @@ class CompilationTests extends ParallelTesting { // Negative tests ------------------------------------------------------------ @Test def compileNeg: Unit = { + implicit val testGroup: TestGroup = TestGroup("compileNeg") compileShallowFilesInDir("../tests/neg", defaultOptions) + compileShallowFilesInDir("../tests/neg/no-optimise", defaultOptions) + compileFile("../tests/neg/customArgs/typers.scala", allowDoubleBindings) + @@ -189,6 +193,7 @@ class CompilationTests extends ParallelTesting { // Run tests ----------------------------------------------------------------- @Test def runAll: Unit = { + implicit val testGroup: TestGroup = TestGroup("runAll") compileFilesInDir("../tests/run", defaultOptions) + compileFilesInDir("../tests/run-no-optimise", defaultOptions) }.checkRuns() @@ -196,6 +201,7 @@ class CompilationTests extends ParallelTesting { // Generic java signatures tests --------------------------------------------- @Test def genericJavaSignatures: Unit = { + implicit val testGroup: TestGroup = TestGroup("genericJavaSignatures") compileFilesInDir("../tests/generic-java-signatures", defaultOptions) }.checkRuns() @@ -205,6 +211,7 @@ class CompilationTests extends ParallelTesting { // lower level of concurrency as to not kill their running VMs @Test def testPickling: Unit = { + implicit val testGroup: TestGroup = TestGroup("testPickling") compileDir("../compiler/src/dotty/tools", picklingOptions) + compileDir("../compiler/src/dotty/tools/dotc", picklingOptions) + compileFilesInDir("../tests/new", picklingOptions) + @@ -233,18 +240,23 @@ class CompilationTests extends ParallelTesting { * version of Dotty */ @Test def tastyBootstrap: Unit = { + implicit val testGroup: TestGroup = TestGroup("tastyBootstrap/tests") + val dotty1Group = TestGroup("tastyBootstrap/dotty1") + val dotty2Group = TestGroup("tastyBootstrap/dotty2") + val libGroup = TestGroup("tastyBootstrap/lib") + val opt = TestFlags( // compile with bootstrapped library on cp: - defaultOutputDir + "lib/src/:" + + defaultOutputDir + libGroup + "/src/:" + // as well as bootstrapped compiler: - defaultOutputDir + "dotty1/dotty/:" + + defaultOutputDir + dotty1Group + "/dotty/:" + Jars.dottyInterfaces, Array("-Ycheck-reentrant") ) - def lib = + val lib = compileDir("../library/src", - defaultOptions.and("-Ycheck-reentrant", "-strict", "-priorityclasspath", defaultOutputDir)) + defaultOptions.and("-Ycheck-reentrant", "-strict", "-priorityclasspath", defaultOutputDir))(libGroup) val compilerDir = Paths.get("../compiler/src") val compilerSources = sources(Files.walk(compilerDir)) @@ -263,19 +275,8 @@ class CompilationTests extends ParallelTesting { val backendJvmSources = sources(Files.list(backendJvmDir), excludedFiles = backendJvmExcluded) - def dotty1 = { - compileList( - "dotty", - compilerSources ++ backendSources ++ backendJvmSources, - opt) - } - - def dotty2 = { - compileList( - "dotty", - compilerSources ++ backendSources ++ backendJvmSources, - opt) - } + val dotty1 = compileList("dotty", compilerSources ++ backendSources ++ backendJvmSources, opt)(dotty1Group) + val dotty2 = compileList("dotty", compilerSources ++ backendSources ++ backendJvmSources, opt)(dotty2Group) val tests = { lib.keepOutput :: dotty1.keepOutput :: { @@ -296,8 +297,9 @@ class CompilationTests extends ParallelTesting { }.keepOutput :: Nil }.map(_.checkCompile()) - assert(new java.io.File("../out/dotty1/dotty/").exists) - assert(new java.io.File("../out/dotty2/dotty/").exists) + assert(new java.io.File(s"../out/$dotty1Group/dotty/").exists) + assert(new java.io.File(s"../out/$dotty2Group/dotty/").exists) + assert(new java.io.File(s"../out/$libGroup/src/").exists) compileList("idempotency", List("../tests/idempotency/BootstrapChecker.scala", "../tests/idempotency/IdempotencyCheck.scala"), defaultOptions).checkRuns() tests.foreach(_.delete()) @@ -305,10 +307,10 @@ class CompilationTests extends ParallelTesting { @Category(Array(classOf[SlowTests])) @Test def testOptimised: Unit = { - val outputDir = defaultOutputDir + "optimised/" - compileFilesInDir("../tests/pos", defaultOptimised, outputDir).checkCompile() - compileFilesInDir("../tests/run", defaultOptimised, outputDir).checkRuns() - compileShallowFilesInDir("../tests/neg", defaultOptimised, outputDir).checkExpectedErrors() + implicit val testGroup: TestGroup = TestGroup("optimised/testOptimised") + compileFilesInDir("../tests/pos", defaultOptimised).checkCompile() + compileFilesInDir("../tests/run", defaultOptimised).checkRuns() + compileShallowFilesInDir("../tests/neg", defaultOptimised).checkExpectedErrors() } private val (compilerSources, backendSources, backendJvmSources) = { diff --git a/compiler/test/dotty/tools/dotc/IdempotencyTests.scala b/compiler/test/dotty/tools/dotc/IdempotencyTests.scala index 5515e005b564..cd80f4e744c6 100644 --- a/compiler/test/dotty/tools/dotc/IdempotencyTests.scala +++ b/compiler/test/dotty/tools/dotc/IdempotencyTests.scala @@ -10,7 +10,7 @@ import org.junit.{AfterClass, Test} import org.junit.experimental.categories.Category import scala.concurrent.duration._ -import vulpix.{ParallelTesting, SummaryReport, SummaryReporting, TestConfiguration} +import vulpix._ class IdempotencyTests extends ParallelTesting { @@ -27,7 +27,7 @@ class IdempotencyTests extends ParallelTesting { @Category(Array(classOf[SlowTests])) @Test def idempotency: Unit = { - + implicit val testGroup: TestGroup = TestGroup("idempotency") val opt = defaultOptions.and("-YemitTasty") def sourcesFrom(dir: Path) = CompilationTests.sources(Files.walk(dir)) @@ -37,9 +37,8 @@ class IdempotencyTests extends ParallelTesting { val strawmanSourcesRevSorted = strawmanSourcesSorted.reverse val posIdempotency = { - def posIdempotency1 = compileFilesInDir("../tests/pos", opt) - def posIdempotency2 = compileFilesInDir("../tests/pos", opt) - posIdempotency1 + posIdempotency2 + compileFilesInDir("../tests/pos", opt)(TestGroup("idempotency/posIdempotency1")) + + compileFilesInDir("../tests/pos", opt)(TestGroup("idempotency/posIdempotency2")) } val orderIdempotency = { @@ -47,9 +46,8 @@ class IdempotencyTests extends ParallelTesting { testDir <- new JFile("../tests/order-idempotency").listFiles() if testDir.isDirectory } yield { val sources = sourcesFrom(testDir.toPath) - def orderIdempotency1 = compileList(testDir.getName, sources, opt) - def orderIdempotency2 = compileList(testDir.getName, sources.reverse, opt) - orderIdempotency1 + orderIdempotency2 + compileList(testDir.getName, sources, opt)(TestGroup("idempotency/orderIdempotency1")) + + compileList(testDir.getName, sources.reverse, opt)(TestGroup("idempotency/orderIdempotency2")) }).reduce(_ + _) } @@ -62,7 +60,7 @@ class IdempotencyTests extends ParallelTesting { def check(name: String) = { val files = List(s"../tests/idempotency/$name.scala", "../tests/idempotency/IdempotencyCheck.scala") - compileList(name, files, defaultOptions) + compileList(name, files, defaultOptions)(TestGroup("idempotency/check")) } val allChecks = { check("CheckOrderIdempotency") + diff --git a/compiler/test/dotty/tools/dotc/LinkOptimiseTests.scala b/compiler/test/dotty/tools/dotc/LinkTests.scala similarity index 69% rename from compiler/test/dotty/tools/dotc/LinkOptimiseTests.scala rename to compiler/test/dotty/tools/dotc/LinkTests.scala index f01582eaf32b..d2c613341b6a 100644 --- a/compiler/test/dotty/tools/dotc/LinkOptimiseTests.scala +++ b/compiler/test/dotty/tools/dotc/LinkTests.scala @@ -12,10 +12,10 @@ import vulpix._ import scala.concurrent.duration._ import scala.collection.JavaConverters._ -class LinkOptimiseTests extends ParallelTesting { +class LinkTests extends ParallelTesting { import ParallelTesting._ import TestConfiguration._ - import LinkOptimiseTests._ + import LinkTests._ // Test suite configuration -------------------------------------------------- @@ -26,12 +26,16 @@ class LinkOptimiseTests extends ParallelTesting { def testFilter = Properties.testsFilter - @Test def linkOptimise: Unit = { + @Test def linkTest: Unit = { // Setup and compile libraries - def strawmanLibrary = - compileDir("../collection-strawman/collections/src/main", defaultOptions) - def linkCustomLib = - compileDir("../tests/link/custom-lib", defaultOptions) + val strawmanLibGroup = TestGroup("linkTest/strawmanLibrary") + val strawmanLibTestGroup = TestGroup(strawmanLibGroup + "/tests") + + val linkCustomLibGroup = TestGroup("linkTest/linkCustomLib") + val linkCustomLibTestGroup = TestGroup(linkCustomLibGroup + "/tests") + + val strawmanLibrary = compileDir("../collection-strawman/collections/src/main", defaultOptions)(strawmanLibGroup) + val linkCustomLib = compileDir("../tests/link/custom-lib", defaultOptions)(linkCustomLibGroup) val libraries = { strawmanLibrary + @@ -41,15 +45,16 @@ class LinkOptimiseTests extends ParallelTesting { // Setup class paths def mkLinkClassFlags(libPath: String) = TestFlags(mkClassPath(libPath :: Jars.dottyTestDeps), mkClassPath(Jars.dottyTestDeps), basicDefaultOptions :+ "-Xlink-optimise") - val strawmanClassPath = mkLinkClassFlags(defaultOutputDir + "strawmanLibrary/main/") - val customLibClassFlags = mkLinkClassFlags(defaultOutputDir + "linkCustomLib/custom-lib") + val strawmanClassPath = mkLinkClassFlags(defaultOutputDir + strawmanLibGroup + "/main/") + val customLibClassFlags = mkLinkClassFlags(defaultOutputDir + linkCustomLibGroup + "/custom-lib") // Link tests val linkDir = "../tests/link" val linkStramanDir = linkDir + "/strawman" val linkCustomLibDir = linkDir + "/on-custom-lib" - def linkStrawmanTest = compileFilesInDir(linkStramanDir, strawmanClassPath) - def linkCustomLibTest = compileFilesInDir(linkCustomLibDir, customLibClassFlags) + + val linkStrawmanTest = compileFilesInDir(linkStramanDir, strawmanClassPath)(strawmanLibTestGroup) + val linkCustomLibTest = compileFilesInDir(linkCustomLibDir, customLibClassFlags)(linkCustomLibTestGroup) def classFileChecks(sourceDir: String, testName: String) = { val checkExt = ".classcheck" @@ -73,8 +78,8 @@ class LinkOptimiseTests extends ParallelTesting { }.keepOutput.checkRuns() try { - classFileChecks(linkStramanDir, "linkStrawmanTest") - classFileChecks(linkCustomLibDir, "linkCustomLibTest") + classFileChecks(linkStramanDir, strawmanLibTestGroup.name) + classFileChecks(linkCustomLibDir, linkCustomLibTestGroup.name) } finally { (libraries + tests).delete() } @@ -82,7 +87,7 @@ class LinkOptimiseTests extends ParallelTesting { } -object LinkOptimiseTests { +object LinkTests { implicit val summaryReport: SummaryReporting = new SummaryReport @AfterClass def cleanup(): Unit = summaryReport.echoSummary() } diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index 13de0f45d7c0..1fc22e843c52 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -1033,39 +1033,12 @@ trait ParallelTesting extends RunnerOrchestration { self => else (dirs, files) } - /** Gets the name of the calling method via reflection. - * - * It does this in a way that needs to work both with the bootstrapped dotty - * and the non-bootstrapped version. Since the two compilers generate - * different bridges, we first need to filter out methods with the same name - * (bridges) - and then find the `@Test` method in our extending class - */ - private def getCallingMethod(): String = { - val seen = mutable.Set.empty[String] - Thread.currentThread.getStackTrace - .filter { elem => - if (seen.contains(elem.getMethodName)) false - else { seen += elem.getMethodName; true } - } - .find { elem => - val callingClass = Class.forName(elem.getClassName) - classOf[ParallelTesting].isAssignableFrom(callingClass) && - elem.getFileName != "ParallelTesting.scala" - } - .map(_.getMethodName) - .getOrElse { - throw new IllegalStateException("Unable to reflectively find calling method") - } - .takeWhile(_ != '$') - } - /** Compiles a single file from the string path `f` using the supplied flags */ - def compileFile(f: String, flags: TestFlags, outDirectory: String = defaultOutputDir): CompilationTest = { - val callingMethod = getCallingMethod() + def compileFile(f: String, flags: TestFlags)(implicit testGroup: TestGroup): CompilationTest = { val sourceFile = new JFile(f) val parent = sourceFile.getParentFile val outDir = - outDirectory + callingMethod + "/" + + defaultOutputDir + testGroup + "/" + sourceFile.getName.substring(0, sourceFile.getName.lastIndexOf('.')) + "/" require( @@ -1075,7 +1048,7 @@ trait ParallelTesting extends RunnerOrchestration { self => ) val target = JointCompilationSource( - callingMethod, + testGroup.name, Array(sourceFile), flags, createOutputDirsForFile(sourceFile, parent, outDir) @@ -1090,9 +1063,8 @@ trait ParallelTesting extends RunnerOrchestration { self => * By default, files are compiled in alphabetical order. An optional seed * can be used for randomization. */ - def compileDir(f: String, flags: TestFlags, randomOrder: Option[Int] = None, outDirectory: String = defaultOutputDir): CompilationTest = { - val callingMethod = getCallingMethod() - val outDir = outDirectory + callingMethod + "/" + def compileDir(f: String, flags: TestFlags, randomOrder: Option[Int] = None)(implicit testGroup: TestGroup): CompilationTest = { + val outDir = defaultOutputDir + testGroup + "/" val sourceDir = new JFile(f) checkRequirements(f, sourceDir, outDir) @@ -1111,7 +1083,7 @@ trait ParallelTesting extends RunnerOrchestration { self => val targetDir = new JFile(outDir + "/" + sourceDir.getName + "/") targetDir.mkdirs() - val target = JointCompilationSource(s"compiling '$f' in test '$callingMethod'", randomized, flags, targetDir) + val target = JointCompilationSource(s"compiling '$f' in test '$testGroup'", randomized, flags, targetDir) new CompilationTest(target) } @@ -1119,15 +1091,15 @@ trait ParallelTesting extends RunnerOrchestration { self => * `testName` since files can be in separate directories and or be otherwise * dissociated */ - def compileList(testName: String, files: List[String], flags: TestFlags, callingMethod: String = getCallingMethod(), outDirectory: String = defaultOutputDir): CompilationTest = { - val outDir = outDirectory + callingMethod + "/" + testName + "/" + def compileList(testName: String, files: List[String], flags: TestFlags)(implicit testGroup: TestGroup): CompilationTest = { + val outDir = defaultOutputDir + testGroup + "/" + testName + "/" // Directories in which to compile all containing files with `flags`: val targetDir = new JFile(outDir) targetDir.mkdirs() assert(targetDir.exists, s"couldn't create target directory: $targetDir") - val target = JointCompilationSource(s"$testName from $callingMethod", files.map(new JFile(_)).toArray, flags, targetDir) + val target = JointCompilationSource(s"$testName from $testGroup", files.map(new JFile(_)).toArray, flags, targetDir) // Create a CompilationTest and let the user decide whether to execute a pos or a neg test new CompilationTest(target) @@ -1150,17 +1122,16 @@ trait ParallelTesting extends RunnerOrchestration { self => * - Directories can have an associated check-file, where the check file has * the same name as the directory (with the file extension `.check`) */ - def compileFilesInDir(f: String, flags: TestFlags, outDirectory: String = defaultOutputDir): CompilationTest = { - val callingMethod = getCallingMethod() - val outDir = outDirectory + callingMethod + "/" + def compileFilesInDir(f: String, flags: TestFlags)(implicit testGroup: TestGroup): CompilationTest = { + val outDir = defaultOutputDir + testGroup + "/" val sourceDir = new JFile(f) checkRequirements(f, sourceDir, outDir) val (dirs, files) = compilationTargets(sourceDir) val targets = - files.map(f => JointCompilationSource(callingMethod, Array(f), flags, createOutputDirsForFile(f, sourceDir, outDir))) ++ - dirs.map(dir => SeparateCompilationSource(callingMethod, dir, flags, createOutputDirsForDir(dir, sourceDir, outDir))) + files.map(f => JointCompilationSource(testGroup.name, Array(f), flags, createOutputDirsForFile(f, sourceDir, outDir))) ++ + dirs.map(dir => SeparateCompilationSource(testGroup.name, dir, flags, createOutputDirsForDir(dir, sourceDir, outDir))) // Create a CompilationTest and let the user decide whether to execute a pos or a neg test new CompilationTest(targets) @@ -1170,16 +1141,15 @@ trait ParallelTesting extends RunnerOrchestration { self => * sub-directories and as such, does **not** perform separate compilation * tests. */ - def compileShallowFilesInDir(f: String, flags: TestFlags, outDirectory: String = defaultOutputDir): CompilationTest = { - val callingMethod = getCallingMethod() - val outDir = outDirectory + callingMethod + "/" + def compileShallowFilesInDir(f: String, flags: TestFlags)(implicit testGroup: TestGroup): CompilationTest = { + val outDir = defaultOutputDir + testGroup + "/" val sourceDir = new JFile(f) checkRequirements(f, sourceDir, outDir) val (_, files) = compilationTargets(sourceDir) val targets = files.map { file => - JointCompilationSource(callingMethod, Array(file), flags, createOutputDirsForFile(file, sourceDir, outDir)) + JointCompilationSource(testGroup.name, Array(file), flags, createOutputDirsForFile(file, sourceDir, outDir)) } // Create a CompilationTest and let the user decide whether to execute a pos or a neg test diff --git a/compiler/test/dotty/tools/vulpix/TestGroup.scala b/compiler/test/dotty/tools/vulpix/TestGroup.scala new file mode 100644 index 000000000000..2e95583a3fd7 --- /dev/null +++ b/compiler/test/dotty/tools/vulpix/TestGroup.scala @@ -0,0 +1,15 @@ +package dotty.tools.vulpix + +/** Test groups are used to ensure that the ouput of tests do not overlap. + * + * It can be used to disambiguate ouputs of tests that test the same file but with different options as shown in the following example. + * compileFilesInDir("../tests/pos", defaultOptions)(TestGroup("compileStdLib")) // will output in ./out/compileStdLib/... + * compileFilesInDir("../tests/pos", defaultOptimised)(TestGroup("optimised/testOptimised")) // will output in ./out/optimised/testOptimised/... + */ +class TestGroup(val name: String) extends AnyVal { + override def toString: String = name +} + +object TestGroup { + def apply(name: String): TestGroup = new TestGroup(name) +} diff --git a/compiler/test/dotty/tools/vulpix/VulpixTests.scala b/compiler/test/dotty/tools/vulpix/VulpixTests.scala index 1c9c4f1f75e6..3adb7b6dcc9a 100644 --- a/compiler/test/dotty/tools/vulpix/VulpixTests.scala +++ b/compiler/test/dotty/tools/vulpix/VulpixTests.scala @@ -13,6 +13,8 @@ class VulpixTests extends ParallelTesting { implicit val _: SummaryReporting = new NoSummaryReport + implicit def testGroup: TestGroup = TestGroup("VulpixTests") + def maxDuration = 3.seconds def numberOfSlaves = 5 def safeMode = sys.env.get("SAFEMODE").isDefined diff --git a/tests/idempotency/BootstrapChecker.scala b/tests/idempotency/BootstrapChecker.scala index 681172fec6d2..1ce18d1b0c38 100644 --- a/tests/idempotency/BootstrapChecker.scala +++ b/tests/idempotency/BootstrapChecker.scala @@ -1,5 +1,5 @@ object Test { def main(args: Array[String]): Unit = - IdempotencyCheck.checkIdempotency("../out/dotty1", "../out/dotty2") + IdempotencyCheck.checkIdempotency("../out/tastyBootstrap/dotty1", "../out/tastyBootstrap/dotty2") } diff --git a/tests/idempotency/CheckOrderIdempotency.scala b/tests/idempotency/CheckOrderIdempotency.scala index 9445565ba9cb..e9e05f526ace 100644 --- a/tests/idempotency/CheckOrderIdempotency.scala +++ b/tests/idempotency/CheckOrderIdempotency.scala @@ -1,5 +1,5 @@ object Test { def main(args: Array[String]): Unit = - IdempotencyCheck.checkIdempotency("../out/orderIdempotency1", "../out/orderIdempotency2") + IdempotencyCheck.checkIdempotency("../out/idempotency/orderIdempotency1", "../out/idempotency/orderIdempotency2") } diff --git a/tests/idempotency/CheckPosIdempotency.scala b/tests/idempotency/CheckPosIdempotency.scala index a40c2c579fc9..e07781db76c9 100644 --- a/tests/idempotency/CheckPosIdempotency.scala +++ b/tests/idempotency/CheckPosIdempotency.scala @@ -1,5 +1,5 @@ object Test { def main(args: Array[String]): Unit = - IdempotencyCheck.checkIdempotency("../out/posIdempotency1", "../out/posIdempotency2") + IdempotencyCheck.checkIdempotency("../out/idempotency/posIdempotency1", "../out/idempotency/posIdempotency2") }