@@ -2,27 +2,27 @@ package dotty
22package tools
33package vulpix
44
5- import java .io .{ File => JFile }
5+ import java .io .{File => JFile }
66import java .text .SimpleDateFormat
77import java .util .HashMap
88import java .nio .file .StandardCopyOption .REPLACE_EXISTING
9- import java .nio .file .{ Files , Path , Paths , NoSuchFileException }
10- import java .util .concurrent .{ Executors => JExecutors , TimeUnit , TimeoutException }
9+ import java .nio .file .{Files , NoSuchFileException , Path , Paths }
10+ import java .util .concurrent .{TimeUnit , TimeoutException , Executors => JExecutors }
1111
1212import scala .io .Source
1313import scala .util .control .NonFatal
1414import scala .util .Try
1515import scala .collection .mutable
1616import scala .util .matching .Regex
1717import scala .util .Random
18-
1918import dotc .core .Contexts ._
20- import dotc .reporting .{ Reporter , TestReporter }
19+ import dotc .reporting .{Reporter , TestReporter }
2120import dotc .reporting .diagnostic .MessageContainer
2221import dotc .interfaces .Diagnostic .ERROR
2322import dotc .util .DiffUtil
24- import dotc .{ Driver , Compiler }
23+ import dotc .{Compiler , Driver }
2524import dotc .decompiler
25+ import dotty .tools .vulpix .TestConfiguration .defaultOptions
2626
2727/** A parallel testing suite whose goal is to integrate nicely with JUnit
2828 *
@@ -425,16 +425,17 @@ trait ParallelTesting extends RunnerOrchestration { self =>
425425 reporter
426426 }
427427
428- protected def decompile (flags0 : TestFlags , suppressErrors : Boolean , targetDir : JFile ): TestReporter = {
429- val decompilationOutput = new JFile (targetDir.getPath)
430- decompilationOutput.mkdir()
428+ protected def decompile (flags0 : TestFlags , suppressErrors : Boolean , targetDir0 : JFile ): TestReporter = {
429+ val targetDir = new JFile (targetDir0.getParent + " _decompiled" )
430+ val decompilationOutput = new JFile (targetDir + " /" + targetDir0.getName)
431+ decompilationOutput.mkdirs()
431432 val flags =
432433 flags0 and (" -d" , decompilationOutput.getAbsolutePath) and
433434 " -decompile" and " -pagewidth" and " 80"
434435
435436 def hasTastyFileToClassName (f : JFile ): String =
436- targetDir .toPath.relativize(f.toPath).toString.dropRight(" .hasTasty" .length).replace('/' , '.' )
437- val classes = flattenFiles(targetDir ).filter(isHasTastyFile).map(hasTastyFileToClassName).sorted
437+ targetDir0 .toPath.relativize(f.toPath).toString.dropRight(" .hasTasty" .length).replace('/' , '.' )
438+ val classes = flattenFiles(targetDir0 ).filter(isHasTastyFile).map(hasTastyFileToClassName).sorted
438439
439440 val reporter =
440441 TestReporter .reporter(realStdout, logLevel =
@@ -522,7 +523,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
522523 checkFileOpt match {
523524 case Some (checkFile) =>
524525 val stripTrailingWhitespaces = " (.*\\ S|)\\ s+" .r
525- val output = Source .fromFile(outDir + " . decompiled" ).getLines().map {line =>
526+ val output = Source .fromFile(outDir.getParent + " _decompiled/ " + outDir.getName + " / decompiled.scala " ).getLines().map {line =>
526527 stripTrailingWhitespaces.unapplySeq(line).map(_.head).getOrElse(line)
527528 }.mkString(" \n " )
528529
@@ -1257,8 +1258,8 @@ trait ParallelTesting extends RunnerOrchestration { self =>
12571258 * Tests in the first part of the tuple must be executed before the second.
12581259 * Both testsRequires explicit delete().
12591260 */
1260- def compileTastyInDir (f : String , flags0 : TestFlags , blacklist : Set [String ] = Set .empty )(
1261- implicit testGroup : TestGroup ): ( CompilationTest , CompilationTest , CompilationTest ) = {
1261+ def compileTastyInDir (f : String , flags0 : TestFlags , blacklist : Set [String ], recompilationBlacklist : Set [ String ] )(
1262+ implicit testGroup : TestGroup ): TastyCompilationTest = {
12621263 val outDir = defaultOutputDir + testGroup + " /"
12631264 val flags = flags0 and " -Yretain-trees"
12641265 val sourceDir = new JFile (f)
@@ -1284,13 +1285,52 @@ trait ParallelTesting extends RunnerOrchestration { self =>
12841285 // Create a CompilationTest and let the user decide whether to execute a pos or a neg test
12851286 val generateClassFiles = compileFilesInDir(f, flags0, blacklist)
12861287
1287- (
1288+ val decompilationDir = outDir + sourceDir.getName + " _decompiled"
1289+
1290+ new TastyCompilationTest (
12881291 generateClassFiles.keepOutput,
12891292 new CompilationTest (targets).keepOutput,
1290- new CompilationTest (targets2).keepOutput
1293+ new CompilationTest (targets2).keepOutput,
1294+ recompilationBlacklist,
1295+ decompilationDir,
1296+ shouldDelete = true
12911297 )
12921298 }
12931299
1300+ class TastyCompilationTest (step1 : CompilationTest , step2 : CompilationTest , step3 : CompilationTest ,
1301+ recompilationBlacklist : Set [String ], decompilationDir : String , shouldDelete : Boolean )(implicit testGroup : TestGroup ) {
1302+
1303+ def keepOutput : TastyCompilationTest =
1304+ new TastyCompilationTest (step1, step2, step3, recompilationBlacklist, decompilationDir, shouldDelete)
1305+
1306+ def checkCompile ()(implicit summaryReport : SummaryReporting ): this .type = {
1307+ step1.checkCompile() // Compile all files to generate the class files with tasty
1308+ step2.checkCompile() // Compile from tasty
1309+ step3.checkCompile() // Decompile from tasty
1310+
1311+ val step4 = compileFilesInDir(decompilationDir, defaultOptions, recompilationBlacklist).keepOutput
1312+ step4.checkCompile() // Recompile decompiled code
1313+
1314+ if (shouldDelete)
1315+ (step1 + step2 + step3 + step4).delete()
1316+
1317+ this
1318+ }
1319+
1320+ def checkRuns ()(implicit summaryReport : SummaryReporting ): this .type = {
1321+ step1.checkCompile() // Compile all files to generate the class files with tasty
1322+ step2.checkRuns() // Compile from tasty
1323+ step3.checkCompile() // Decompile from tasty
1324+
1325+ val step4 = compileFilesInDir(decompilationDir, defaultOptions, recompilationBlacklist).keepOutput
1326+ step4.checkRuns() // Recompile decompiled code
1327+
1328+ if (shouldDelete)
1329+ (step1 + step2 + step3 + step4).delete()
1330+
1331+ this
1332+ }
1333+ }
12941334
12951335 /** This function behaves similar to `compileFilesInDir` but it ignores
12961336 * sub-directories and as such, does **not** perform separate compilation
0 commit comments