Skip to content

Commit 9a4a5b6

Browse files
committed
Support copyToDir for tests that mutate original source
1 parent 5611456 commit 9a4a5b6

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ class CompilationTests extends ParallelTesting {
2020

2121
@Test def compilePosMixedFlags: Unit = {
2222
compileFile("../tests/pos/nullarify.scala", defaultOptions.and("-Ycheck:nullarify")) +
23-
// this guy sucks, he changes the sourcefile itself:
24-
// compileFile("../tests/pos-scala2/rewrites.scala", scala2Mode.and("-rewrite")) +
23+
compileFile("../tests/pos-scala2/rewrites.scala", scala2Mode.and("-rewrite")).copyToTarget() +
2524
compileFile("../tests/pos-special/t8146a.scala", allowDeepSubtypes) +
2625
compileFile("../tests/pos-special/utf8encoded.scala", explicitUTF8) +
2726
compileFile("../tests/pos-special/utf16encoded.scala", explicitUTF16) +

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,23 @@ trait ParallelTesting {
479479
this
480480
}
481481

482+
private def copyToDir(dir: JFile, file: JFile): JFile = {
483+
val target = Paths.get(dir.getAbsolutePath, file.getName)
484+
Files.copy(file.toPath, target, REPLACE_EXISTING)
485+
if (file.isDirectory) file.listFiles.map(copyToDir(target.toFile, _))
486+
target.toFile
487+
}
488+
489+
def copyToTarget(): CompilationTest = new CompilationTest (
490+
targets.map {
491+
case target @ ConcurrentCompilationTarget(files, _, outDir) =>
492+
target.copy(files = files.map(copyToDir(outDir,_)))
493+
case target @ SeparateCompilationTarget(dir, _, outDir) =>
494+
target.copy(dir = copyToDir(outDir, dir))
495+
},
496+
times, shouldDelete, threadLimit
497+
)
498+
482499
def times(i: Int): CompilationTest =
483500
new CompilationTest(targets, i, shouldDelete, threadLimit)
484501

@@ -521,12 +538,6 @@ trait ParallelTesting {
521538
targetDir
522539
}
523540

524-
private def copyToDir(dir: JFile, file: JFile): Unit = {
525-
val target = Paths.get(dir.getAbsolutePath, file.getName)
526-
Files.copy(file.toPath, target, REPLACE_EXISTING)
527-
if (file.isDirectory) file.listFiles.map(copyToDir(target.toFile, _))
528-
}
529-
530541
private def requirements(f: String, sourceDir: JFile, outDir: String): Unit = {
531542
require(sourceDir.isDirectory && sourceDir.exists, "passed non-directory to `compileFilesInDir`")
532543
require(outDir.last == '/', "please specify an `outDir` with a trailing slash")

0 commit comments

Comments
 (0)