@@ -582,6 +582,24 @@ trait ParallelTesting extends RunnerOrchestration { self =>
582
582
private final class PosTest (testSources : List [TestSource ], times : Int , threadLimit : Option [Int ], suppressAllOutput : Boolean )(implicit summaryReport : SummaryReporting )
583
583
extends Test (testSources, times, threadLimit, suppressAllOutput)
584
584
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
+
585
603
private final class RunTest (testSources : List [TestSource ], times : Int , threadLimit : Option [Int ], suppressAllOutput : Boolean )(implicit summaryReport : SummaryReporting )
586
604
extends Test (testSources, times, threadLimit, suppressAllOutput) {
587
605
private var didAddNoRunWarning = false
@@ -917,6 +935,22 @@ trait ParallelTesting extends RunnerOrchestration { self =>
917
935
this
918
936
}
919
937
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
+
920
954
/** Deletes output directories and files */
921
955
private def cleanup (): this .type = {
922
956
if (shouldDelete) delete()
@@ -948,18 +982,19 @@ trait ParallelTesting extends RunnerOrchestration { self =>
948
982
}
949
983
950
984
/** 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
952
986
* source, such as `-rewrite` tests
953
987
*/
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
+ )
963
998
964
999
/** Builds a `CompilationTest` which performs the compilation `i` times on
965
1000
* each target
0 commit comments