@@ -81,6 +81,13 @@ trait ParallelTesting extends RunnerOrchestration { self =>
81
81
else self
82
82
}
83
83
84
+ def withoutFlags (flags1 : String * ): TestSource = self match {
85
+ case self : JointCompilationSource =>
86
+ self.copy(flags = flags.without(flags1 : _* ))
87
+ case self : SeparateCompilationSource =>
88
+ self.copy(flags = flags.without(flags1 : _* ))
89
+ }
90
+
84
91
/** Generate the instructions to redo the test from the command line */
85
92
def buildInstructions (errors : Int , warnings : Int ): String = {
86
93
val sb = new StringBuilder
@@ -582,6 +589,24 @@ trait ParallelTesting extends RunnerOrchestration { self =>
582
589
private final class PosTest (testSources : List [TestSource ], times : Int , threadLimit : Option [Int ], suppressAllOutput : Boolean )(implicit summaryReport : SummaryReporting )
583
590
extends Test (testSources, times, threadLimit, suppressAllOutput)
584
591
592
+ private final class RewriteTest (testSources : List [TestSource ], checkFiles : Map [JFile , JFile ], times : Int , threadLimit : Option [Int ], suppressAllOutput : Boolean )(implicit summaryReport : SummaryReporting )
593
+ extends Test (testSources, times, threadLimit, suppressAllOutput) {
594
+ private def verifyOutput (testSource : TestSource , reporters : Seq [TestReporter ], logger : LoggedRunnable ) = {
595
+ testSource.sourceFiles.foreach { file =>
596
+ if checkFiles.contains(file) then
597
+ val checkFile = checkFiles(file)
598
+ val actual = Source .fromFile(file, " UTF-8" ).getLines().toList
599
+ diffTest(testSource, checkFile, actual, reporters, logger)
600
+ }
601
+
602
+ // check that the rewritten code compiles
603
+ new CompilationTest (testSource).checkCompile()
604
+ }
605
+
606
+ override def onSuccess (testSource : TestSource , reporters : Seq [TestReporter ], logger : LoggedRunnable ) =
607
+ verifyOutput(testSource, reporters, logger)
608
+ }
609
+
585
610
private final class RunTest (testSources : List [TestSource ], times : Int , threadLimit : Option [Int ], suppressAllOutput : Boolean )(implicit summaryReport : SummaryReporting )
586
611
extends Test (testSources, times, threadLimit, suppressAllOutput) {
587
612
private var didAddNoRunWarning = false
@@ -917,6 +942,33 @@ trait ParallelTesting extends RunnerOrchestration { self =>
917
942
this
918
943
}
919
944
945
+ /** Tests `-rewrite`, which makes sure that the rewritten files still compile
946
+ * and agree with the expected result (if specified).
947
+ *
948
+ * Check files are only supported for joint compilation sources.
949
+ */
950
+ def checkRewrites ()(implicit summaryReport : SummaryReporting ): this .type = {
951
+ // use the original check file, to simplify update of check files
952
+ var checkFileMap = Map .empty[JFile , JFile ]
953
+
954
+ // copy source file to targets, as they will be changed
955
+ val copiedTargets = targets.map {
956
+ case target @ JointCompilationSource (_, files, _, outDir, _, _) =>
957
+ val files2 = files.map { f =>
958
+ val dest = copyToDir(outDir, f)
959
+ val checkFile = new JFile (f.getPath.replaceFirst(" \\ .scala$" , " .check" ))
960
+ if (checkFile.exists) checkFileMap = checkFileMap.updated(dest, checkFile)
961
+ dest
962
+ }
963
+ target.copy(files = files2)
964
+ case target @ SeparateCompilationSource (_, dir, _, outDir) =>
965
+ target.copy(dir = copyToDir(outDir, dir))
966
+ }
967
+
968
+ val test = new RewriteTest (copiedTargets, checkFileMap, times, threadLimit, shouldFail || shouldSuppressOutput).executeTestSuite()
969
+ this
970
+ }
971
+
920
972
/** Deletes output directories and files */
921
973
private def cleanup (): this .type = {
922
974
if (shouldDelete) delete()
@@ -947,20 +999,6 @@ trait ParallelTesting extends RunnerOrchestration { self =>
947
999
target.toFile
948
1000
}
949
1001
950
- /** 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
952
- * source, such as `-rewrite` tests
953
- */
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
- )
963
-
964
1002
/** Builds a `CompilationTest` which performs the compilation `i` times on
965
1003
* each target
966
1004
*/
0 commit comments