Skip to content

Commit 67b2ffe

Browse files
committed
Remove vulpix test names dependence on reflection
1 parent 42577bb commit 67b2ffe

File tree

7 files changed

+44
-59
lines changed

7 files changed

+44
-59
lines changed

compiler/test/dotc/comptest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dotc
22

3-
import dotty.tools.vulpix.{ParallelTesting, TestFlags}
3+
import dotty.tools.vulpix.{ParallelTesting, TestFlags, TestGroup}
44

55
import scala.concurrent.duration._
66

@@ -26,5 +26,5 @@ object comptest extends ParallelTesting {
2626
),
2727
TestFlags("", Array("-Ylog:frontend", "-Xprompt")),
2828
outDirectory = "."
29-
)
29+
)(TestGroup("comptest"))
3030
}

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ class CompilationTests extends ParallelTesting {
3333

3434
// @Test // enable to test compileStdLib separately with detailed stats
3535
def compileStdLib: Unit = {
36+
implicit val testGroup: TestGroup = TestGroup("compileStdLib")
3637
compileList("compileStdLib", StdLibSources.whitelisted, scala2Mode.and("-migration", "-Yno-inline", "-Ydetailed-stats"))
3738
}.checkCompile()
3839

3940
@Test def compilePos: Unit = {
41+
implicit val testGroup: TestGroup = TestGroup("compilePos")
4042
compileList("compileStdLib", StdLibSources.whitelisted, scala2Mode.and("-migration", "-Yno-inline")) +
4143
compileDir("../compiler/src/dotty/tools/dotc/ast", defaultOptions) +
4244
compileDir("../compiler/src/dotty/tools/dotc/config", defaultOptions) +
@@ -102,6 +104,7 @@ class CompilationTests extends ParallelTesting {
102104
}.checkCompile()
103105

104106
@Test def posTwice: Unit = {
107+
implicit val testGroup: TestGroup = TestGroup("posTwice")
105108
compileFile("../tests/pos/Labels.scala", defaultOptions) +
106109
compileFilesInDir("../tests/pos-java-interop", defaultOptions) +
107110
compileFile("../tests/pos/t2168.scala", defaultOptions) +
@@ -160,6 +163,7 @@ class CompilationTests extends ParallelTesting {
160163
// Negative tests ------------------------------------------------------------
161164

162165
@Test def compileNeg: Unit = {
166+
implicit val testGroup: TestGroup = TestGroup("compileNeg")
163167
compileShallowFilesInDir("../tests/neg", defaultOptions) +
164168
compileShallowFilesInDir("../tests/neg/no-optimise", defaultOptions) +
165169
compileFile("../tests/neg/customArgs/typers.scala", allowDoubleBindings) +
@@ -189,13 +193,15 @@ class CompilationTests extends ParallelTesting {
189193
// Run tests -----------------------------------------------------------------
190194

191195
@Test def runAll: Unit = {
196+
implicit val testGroup: TestGroup = TestGroup("runAll")
192197
compileFilesInDir("../tests/run", defaultOptions) +
193198
compileFilesInDir("../tests/run-no-optimise", defaultOptions)
194199
}.checkRuns()
195200

196201
// Generic java signatures tests ---------------------------------------------
197202

198203
@Test def genericJavaSignatures: Unit = {
204+
implicit val testGroup: TestGroup = TestGroup("genericJavaSignatures")
199205
compileFilesInDir("../tests/generic-java-signatures", defaultOptions)
200206
}.checkRuns()
201207

@@ -205,6 +211,7 @@ class CompilationTests extends ParallelTesting {
205211
// lower level of concurrency as to not kill their running VMs
206212

207213
@Test def testPickling: Unit = {
214+
implicit val testGroup: TestGroup = TestGroup("testPickling")
208215
compileDir("../compiler/src/dotty/tools", picklingOptions) +
209216
compileDir("../compiler/src/dotty/tools/dotc", picklingOptions) +
210217
compileFilesInDir("../tests/new", picklingOptions) +
@@ -233,6 +240,8 @@ class CompilationTests extends ParallelTesting {
233240
* version of Dotty
234241
*/
235242
@Test def tastyBootstrap: Unit = {
243+
implicit val testGroup: TestGroup = TestGroup("tastyBootstrap")
244+
236245
val opt = TestFlags(
237246
// compile with bootstrapped library on cp:
238247
defaultOutputDir + "lib/src/:" +
@@ -267,14 +276,14 @@ class CompilationTests extends ParallelTesting {
267276
compileList(
268277
"dotty",
269278
compilerSources ++ backendSources ++ backendJvmSources,
270-
opt)
279+
opt)(TestGroup("dotty1"))
271280
}
272281

273282
def dotty2 = {
274283
compileList(
275284
"dotty",
276285
compilerSources ++ backendSources ++ backendJvmSources,
277-
opt)
286+
opt)(TestGroup("dotty2"))
278287
}
279288

280289
val tests = {
@@ -305,6 +314,7 @@ class CompilationTests extends ParallelTesting {
305314

306315
@Category(Array(classOf[SlowTests]))
307316
@Test def testOptimised: Unit = {
317+
implicit val testGroup: TestGroup = TestGroup("testOptimised")
308318
val outputDir = defaultOutputDir + "optimised/"
309319
compileFilesInDir("../tests/pos", defaultOptimised, outputDir).checkCompile()
310320
compileFilesInDir("../tests/run", defaultOptimised, outputDir).checkRuns()

compiler/test/dotty/tools/dotc/IdempotencyTests.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.junit.{AfterClass, Test}
1010
import org.junit.experimental.categories.Category
1111

1212
import scala.concurrent.duration._
13-
import vulpix.{ParallelTesting, SummaryReport, SummaryReporting, TestConfiguration}
13+
import vulpix._
1414

1515

1616
class IdempotencyTests extends ParallelTesting {
@@ -27,7 +27,7 @@ class IdempotencyTests extends ParallelTesting {
2727

2828
@Category(Array(classOf[SlowTests]))
2929
@Test def idempotency: Unit = {
30-
30+
implicit val testGroup: TestGroup = TestGroup("idempotency")
3131
val opt = defaultOptions.and("-YemitTasty")
3232

3333
def sourcesFrom(dir: Path) = CompilationTests.sources(Files.walk(dir))
@@ -47,8 +47,8 @@ class IdempotencyTests extends ParallelTesting {
4747
testDir <- new JFile("../tests/order-idempotency").listFiles() if testDir.isDirectory
4848
} yield {
4949
val sources = sourcesFrom(testDir.toPath)
50-
def orderIdempotency1 = compileList(testDir.getName, sources, opt)
51-
def orderIdempotency2 = compileList(testDir.getName, sources.reverse, opt)
50+
def orderIdempotency1 = compileList(testDir.getName, sources, opt)(TestGroup("orderIdempotency1"))
51+
def orderIdempotency2 = compileList(testDir.getName, sources.reverse, opt)(TestGroup("orderIdempotency2"))
5252
orderIdempotency1 + orderIdempotency2
5353
}).reduce(_ + _)
5454
}
@@ -62,7 +62,7 @@ class IdempotencyTests extends ParallelTesting {
6262

6363
def check(name: String) = {
6464
val files = List(s"../tests/idempotency/$name.scala", "../tests/idempotency/IdempotencyCheck.scala")
65-
compileList(name, files, defaultOptions)
65+
compileList(name, files, defaultOptions)(TestGroup("check"))
6666
}
6767
val allChecks = {
6868
check("CheckOrderIdempotency") +

compiler/test/dotty/tools/dotc/LinkOptimiseTests.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class LinkOptimiseTests extends ParallelTesting {
2929
@Test def linkOptimise: Unit = {
3030
// Setup and compile libraries
3131
def strawmanLibrary =
32-
compileDir("../collection-strawman/collections/src/main", defaultOptions)
32+
compileDir("../collection-strawman/collections/src/main", defaultOptions)(TestGroup("strawmanLibrary"))
3333
def linkCustomLib =
34-
compileDir("../tests/link/custom-lib", defaultOptions)
34+
compileDir("../tests/link/custom-lib", defaultOptions)(TestGroup("linkCustomLib"))
3535

3636
val libraries = {
3737
strawmanLibrary +
@@ -48,8 +48,8 @@ class LinkOptimiseTests extends ParallelTesting {
4848
val linkDir = "../tests/link"
4949
val linkStramanDir = linkDir + "/strawman"
5050
val linkCustomLibDir = linkDir + "/on-custom-lib"
51-
def linkStrawmanTest = compileFilesInDir(linkStramanDir, strawmanClassPath)
52-
def linkCustomLibTest = compileFilesInDir(linkCustomLibDir, customLibClassFlags)
51+
def linkStrawmanTest = compileFilesInDir(linkStramanDir, strawmanClassPath)(TestGroup("linkStrawmanTest"))
52+
def linkCustomLibTest = compileFilesInDir(linkCustomLibDir, customLibClassFlags)(TestGroup("linkCustomLibTest"))
5353

5454
def classFileChecks(sourceDir: String, testName: String) = {
5555
val checkExt = ".classcheck"

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

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,39 +1033,12 @@ trait ParallelTesting extends RunnerOrchestration { self =>
10331033
else (dirs, files)
10341034
}
10351035

1036-
/** Gets the name of the calling method via reflection.
1037-
*
1038-
* It does this in a way that needs to work both with the bootstrapped dotty
1039-
* and the non-bootstrapped version. Since the two compilers generate
1040-
* different bridges, we first need to filter out methods with the same name
1041-
* (bridges) - and then find the `@Test` method in our extending class
1042-
*/
1043-
private def getCallingMethod(): String = {
1044-
val seen = mutable.Set.empty[String]
1045-
Thread.currentThread.getStackTrace
1046-
.filter { elem =>
1047-
if (seen.contains(elem.getMethodName)) false
1048-
else { seen += elem.getMethodName; true }
1049-
}
1050-
.find { elem =>
1051-
val callingClass = Class.forName(elem.getClassName)
1052-
classOf[ParallelTesting].isAssignableFrom(callingClass) &&
1053-
elem.getFileName != "ParallelTesting.scala"
1054-
}
1055-
.map(_.getMethodName)
1056-
.getOrElse {
1057-
throw new IllegalStateException("Unable to reflectively find calling method")
1058-
}
1059-
.takeWhile(_ != '$')
1060-
}
1061-
10621036
/** Compiles a single file from the string path `f` using the supplied flags */
1063-
def compileFile(f: String, flags: TestFlags, outDirectory: String = defaultOutputDir): CompilationTest = {
1064-
val callingMethod = getCallingMethod()
1037+
def compileFile(f: String, flags: TestFlags, outDirectory: String = defaultOutputDir)(implicit testGroup: TestGroup): CompilationTest = {
10651038
val sourceFile = new JFile(f)
10661039
val parent = sourceFile.getParentFile
10671040
val outDir =
1068-
outDirectory + callingMethod + "/" +
1041+
outDirectory + testGroup.name + "/" +
10691042
sourceFile.getName.substring(0, sourceFile.getName.lastIndexOf('.')) + "/"
10701043

10711044
require(
@@ -1075,7 +1048,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
10751048
)
10761049

10771050
val target = JointCompilationSource(
1078-
callingMethod,
1051+
testGroup.name,
10791052
Array(sourceFile),
10801053
flags,
10811054
createOutputDirsForFile(sourceFile, parent, outDir)
@@ -1090,9 +1063,8 @@ trait ParallelTesting extends RunnerOrchestration { self =>
10901063
* By default, files are compiled in alphabetical order. An optional seed
10911064
* can be used for randomization.
10921065
*/
1093-
def compileDir(f: String, flags: TestFlags, randomOrder: Option[Int] = None, outDirectory: String = defaultOutputDir): CompilationTest = {
1094-
val callingMethod = getCallingMethod()
1095-
val outDir = outDirectory + callingMethod + "/"
1066+
def compileDir(f: String, flags: TestFlags, randomOrder: Option[Int] = None, outDirectory: String = defaultOutputDir)(implicit testGroup: TestGroup): CompilationTest = {
1067+
val outDir = outDirectory + testGroup.name + "/"
10961068
val sourceDir = new JFile(f)
10971069
checkRequirements(f, sourceDir, outDir)
10981070

@@ -1111,23 +1083,23 @@ trait ParallelTesting extends RunnerOrchestration { self =>
11111083
val targetDir = new JFile(outDir + "/" + sourceDir.getName + "/")
11121084
targetDir.mkdirs()
11131085

1114-
val target = JointCompilationSource(s"compiling '$f' in test '$callingMethod'", randomized, flags, targetDir)
1086+
val target = JointCompilationSource(s"compiling '$f' in test '${testGroup.name}'", randomized, flags, targetDir)
11151087
new CompilationTest(target)
11161088
}
11171089

11181090
/** Compiles all `files` together as a single compilation run. It is given a
11191091
* `testName` since files can be in separate directories and or be otherwise
11201092
* dissociated
11211093
*/
1122-
def compileList(testName: String, files: List[String], flags: TestFlags, callingMethod: String = getCallingMethod(), outDirectory: String = defaultOutputDir): CompilationTest = {
1123-
val outDir = outDirectory + callingMethod + "/" + testName + "/"
1094+
def compileList(testName: String, files: List[String], flags: TestFlags, outDirectory: String = defaultOutputDir)(implicit testGroup: TestGroup): CompilationTest = {
1095+
val outDir = outDirectory + testGroup.name + "/" + testName + "/"
11241096

11251097
// Directories in which to compile all containing files with `flags`:
11261098
val targetDir = new JFile(outDir)
11271099
targetDir.mkdirs()
11281100
assert(targetDir.exists, s"couldn't create target directory: $targetDir")
11291101

1130-
val target = JointCompilationSource(s"$testName from $callingMethod", files.map(new JFile(_)).toArray, flags, targetDir)
1102+
val target = JointCompilationSource(s"$testName from ${testGroup.name}", files.map(new JFile(_)).toArray, flags, targetDir)
11311103

11321104
// Create a CompilationTest and let the user decide whether to execute a pos or a neg test
11331105
new CompilationTest(target)
@@ -1150,17 +1122,16 @@ trait ParallelTesting extends RunnerOrchestration { self =>
11501122
* - Directories can have an associated check-file, where the check file has
11511123
* the same name as the directory (with the file extension `.check`)
11521124
*/
1153-
def compileFilesInDir(f: String, flags: TestFlags, outDirectory: String = defaultOutputDir): CompilationTest = {
1154-
val callingMethod = getCallingMethod()
1155-
val outDir = outDirectory + callingMethod + "/"
1125+
def compileFilesInDir(f: String, flags: TestFlags, outDirectory: String = defaultOutputDir)(implicit testGroup: TestGroup): CompilationTest = {
1126+
val outDir = outDirectory + testGroup.name + "/"
11561127
val sourceDir = new JFile(f)
11571128
checkRequirements(f, sourceDir, outDir)
11581129

11591130
val (dirs, files) = compilationTargets(sourceDir)
11601131

11611132
val targets =
1162-
files.map(f => JointCompilationSource(callingMethod, Array(f), flags, createOutputDirsForFile(f, sourceDir, outDir))) ++
1163-
dirs.map(dir => SeparateCompilationSource(callingMethod, dir, flags, createOutputDirsForDir(dir, sourceDir, outDir)))
1133+
files.map(f => JointCompilationSource(testGroup.name, Array(f), flags, createOutputDirsForFile(f, sourceDir, outDir))) ++
1134+
dirs.map(dir => SeparateCompilationSource(testGroup.name, dir, flags, createOutputDirsForDir(dir, sourceDir, outDir)))
11641135

11651136
// Create a CompilationTest and let the user decide whether to execute a pos or a neg test
11661137
new CompilationTest(targets)
@@ -1170,16 +1141,15 @@ trait ParallelTesting extends RunnerOrchestration { self =>
11701141
* sub-directories and as such, does **not** perform separate compilation
11711142
* tests.
11721143
*/
1173-
def compileShallowFilesInDir(f: String, flags: TestFlags, outDirectory: String = defaultOutputDir): CompilationTest = {
1174-
val callingMethod = getCallingMethod()
1175-
val outDir = outDirectory + callingMethod + "/"
1144+
def compileShallowFilesInDir(f: String, flags: TestFlags, outDirectory: String = defaultOutputDir)(implicit testGroup: TestGroup): CompilationTest = {
1145+
val outDir = outDirectory + testGroup.name + "/"
11761146
val sourceDir = new JFile(f)
11771147
checkRequirements(f, sourceDir, outDir)
11781148

11791149
val (_, files) = compilationTargets(sourceDir)
11801150

11811151
val targets = files.map { file =>
1182-
JointCompilationSource(callingMethod, Array(file), flags, createOutputDirsForFile(file, sourceDir, outDir))
1152+
JointCompilationSource(testGroup.name, Array(file), flags, createOutputDirsForFile(file, sourceDir, outDir))
11831153
}
11841154

11851155
// Create a CompilationTest and let the user decide whether to execute a pos or a neg test
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package dotty.tools.vulpix
2+
3+
case class TestGroup(name: String) extends AnyVal

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class VulpixTests extends ParallelTesting {
1313

1414
implicit val _: SummaryReporting = new NoSummaryReport
1515

16+
implicit def testGroup: TestGroup = TestGroup("VulpixTests")
17+
1618
def maxDuration = 3.seconds
1719
def numberOfSlaves = 5
1820
def safeMode = sys.env.get("SAFEMODE").isDefined

0 commit comments

Comments
 (0)