@@ -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