Skip to content

Commit 6143745

Browse files
committed
Add checkRewrites
1 parent 222d323 commit 6143745

File tree

2 files changed

+54
-12
lines changed

2 files changed

+54
-12
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ class CompilationTests extends ParallelTesting {
3737
implicit val testGroup: TestGroup = TestGroup("compilePos")
3838
aggregateTests(
3939
compileFile("tests/pos/nullarify.scala", defaultOptions.and("-Ycheck:nullarify")),
40-
compileFile("tests/pos-scala2/rewrites.scala", scala2CompatMode.and("-rewrite")).copyToTarget(),
41-
compileFile("tests/pos/i8982.scala", defaultOptions.and("-indent").and("-rewrite")).copyToTarget(),
4240
compileFile("tests/pos-special/utf8encoded.scala", explicitUTF8),
4341
compileFile("tests/pos-special/utf16encoded.scala", explicitUTF16),
4442
compileFilesInDir("tests/pos-special/sourcepath/outer", defaultOptions.and("-sourcepath", "tests/pos-special/sourcepath")),
@@ -69,6 +67,15 @@ class CompilationTests extends ParallelTesting {
6967
).checkCompile()
7068
}
7169

70+
@Test def rewrites: Unit = {
71+
implicit val testGroup: TestGroup = TestGroup("rewrites")
72+
73+
aggregateTests(
74+
compileFile("tests/pos-scala2/rewrites.scala", scala2CompatMode.and("-rewrite")),
75+
compileFile("tests/pos/i8982.scala", defaultOptions.and("-indent").and("-rewrite"))
76+
).checkRewrites()
77+
}
78+
7279
@Test def posTwice: Unit = {
7380
implicit val testGroup: TestGroup = TestGroup("posTwice")
7481
aggregateTests(

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

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,24 @@ trait ParallelTesting extends RunnerOrchestration { self =>
582582
private final class PosTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)(implicit summaryReport: SummaryReporting)
583583
extends Test(testSources, times, threadLimit, suppressAllOutput)
584584

585+
private final class RewriteTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)(implicit summaryReport: SummaryReporting)
586+
extends Test(testSources, times, threadLimit, suppressAllOutput) {
587+
private def verifyOutput(testSource: TestSource, reporters: Seq[TestReporter], logger: LoggedRunnable) = {
588+
testSource.sourceFiles.foreach { file =>
589+
val checkFile = new JFile(file.getPath.replaceFirst("\\.scala$", ".check"))
590+
if checkFile.exists then
591+
val actual = Source.fromFile(file, "UTF-8").getLines().toList
592+
diffTest(testSource, checkFile, actual, reporters, logger)
593+
}
594+
595+
// check that the rewritten code compiles
596+
new CompilationTest(testSource).checkCompile()
597+
}
598+
599+
override def onSuccess(testSource: TestSource, reporters: Seq[TestReporter], logger: LoggedRunnable) =
600+
verifyOutput(testSource, reporters, logger)
601+
}
602+
585603
private final class RunTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)(implicit summaryReport: SummaryReporting)
586604
extends Test(testSources, times, threadLimit, suppressAllOutput) {
587605
private var didAddNoRunWarning = false
@@ -917,6 +935,22 @@ trait ParallelTesting extends RunnerOrchestration { self =>
917935
this
918936
}
919937

938+
/** Tests `-rewrite`, which makes sure that the rewritten files still compile
939+
* and agree with the expected result (if specified).
940+
*/
941+
def checkRewrites()(implicit summaryReport: SummaryReporting): this.type = {
942+
// copy source file to targets, as they will be changed
943+
val copiedTargets = targets.map {
944+
case target @ JointCompilationSource(_, files, _, outDir, _, _) =>
945+
target.copy(files = files.map(copyToDir(outDir,_)))
946+
case target @ SeparateCompilationSource(_, dir, _, outDir) =>
947+
target.copy(dir = copyToDir(outDir, dir))
948+
}
949+
950+
val test = new RewriteTest(copiedTargets, times, threadLimit, shouldFail || shouldSuppressOutput).executeTestSuite()
951+
this
952+
}
953+
920954
/** Deletes output directories and files */
921955
private def cleanup(): this.type = {
922956
if (shouldDelete) delete()
@@ -948,18 +982,19 @@ trait ParallelTesting extends RunnerOrchestration { self =>
948982
}
949983

950984
/** Builds a new `CompilationTest` where we have copied the target files to
951-
* the out directory. This is needed for tests that modify the original
985+
* the out directory. This is needed for tests that modify the
952986
* source, such as `-rewrite` tests
953987
*/
954-
def copyToTarget(): CompilationTest = new CompilationTest (
955-
targets.map {
956-
case target @ JointCompilationSource(_, files, _, outDir, _, _) =>
957-
target.copy(files = files.map(copyToDir(outDir,_)))
958-
case target @ SeparateCompilationSource(_, dir, _, outDir) =>
959-
target.copy(dir = copyToDir(outDir, dir))
960-
},
961-
times, shouldDelete, threadLimit, shouldFail, shouldSuppressOutput
962-
)
988+
def copyToTarget()(implicit summary: SummaryReporting): CompilationTest =
989+
new CompilationTest (
990+
targets.map {
991+
case target @ JointCompilationSource(_, files, _, outDir, _, _) =>
992+
target.copy(files = files.map(copyToDir(outDir,_)))
993+
case target @ SeparateCompilationSource(_, dir, _, outDir) =>
994+
target.copy(dir = copyToDir(outDir, dir))
995+
},
996+
times, shouldDelete, threadLimit, shouldFail, shouldSuppressOutput
997+
)
963998

964999
/** Builds a `CompilationTest` which performs the compilation `i` times on
9651000
* each target

0 commit comments

Comments
 (0)