@@ -46,6 +46,9 @@ trait ParallelTesting extends RunnerOrchestration { self =>
4646 */
4747 def testFilter : Option [String ]
4848
49+ /** Tests should override the checkfiles with the current output */
50+ def updateCheckFiles : Boolean
51+
4952 /** A test source whose files or directory of files is to be compiled
5053 * in a specific way defined by the `Test`
5154 */
@@ -505,6 +508,12 @@ trait ParallelTesting extends RunnerOrchestration { self =>
505508 this
506509 }
507510
511+ protected def updateCheckFile (checkFile : JFile , lines : Seq [String ]): Unit = {
512+ val outFile = dotty.tools.io.File (checkFile.toPath)
513+ outFile.writeAll(lines.mkString(" " , EOL , EOL ))
514+ echo(" Updated checkfile: " + checkFile.getPath)
515+ }
516+
508517 /** Returns all files in directory or the file if not a directory */
509518 private def flattenFiles (f : JFile ): Array [JFile ] =
510519 if (f.isDirectory) f.listFiles.flatMap(flattenFiles)
@@ -537,28 +546,32 @@ trait ParallelTesting extends RunnerOrchestration { self =>
537546 val output = Source .fromFile(outDir.getParent + " _decompiled" + JFile .separator + outDir.getName
538547 + JFile .separator + " decompiled.scala" , " UTF-8" ).getLines().map {line =>
539548 stripTrailingWhitespaces.unapplySeq(line).map(_.head).getOrElse(line)
540- }.toList
549+ }.filter( ! _.startsWith(ignoredFilePathLine)). toList
541550
542- val check : String = Source .fromFile(checkFile, " UTF-8" ).getLines().filter( ! _.startsWith(ignoredFilePathLine))
551+ val check : String = Source .fromFile(checkFile, " UTF-8" ).getLines()
543552 .mkString(EOL )
544553
545- if (output.filter( ! _.startsWith(ignoredFilePathLine)). mkString(EOL ) != check) {
554+ if (output.mkString(EOL ) != check) {
546555 val outFile = dotty.tools.io.File (checkFile.toPath).addExtension(" .out" )
547- outFile.writeAll(output.mkString(EOL ))
548- val msg =
549- s """ Output differed for test $name, use the following command to see the diff:
550- | > diff $checkFile $outFile
556+ if (updateCheckFiles) {
557+ updateCheckFile(checkFile, output)
558+ } else {
559+ outFile.writeAll(output.mkString(" " , EOL , " " ))
560+ val msg =
561+ s """ Output differed for test $name, use the following command to see the diff:
562+ | > diff $checkFile $outFile
551563 """ .stripMargin
552564
553- echo(msg)
554- addFailureInstruction(msg)
565+ echo(msg)
566+ addFailureInstruction(msg)
555567
556- // Print build instructions to file and summary:
557- val buildInstr = testSource.buildInstructions(0 , rep.warningCount)
558- addFailureInstruction(buildInstr)
568+ // Print build instructions to file and summary:
569+ val buildInstr = testSource.buildInstructions(0 , rep.warningCount)
570+ addFailureInstruction(buildInstr)
559571
560- // Fail target:
561- failTestSource(testSource)
572+ // Fail target:
573+ failTestSource(testSource)
574+ }
562575 }
563576 case _ =>
564577 }
@@ -631,6 +644,9 @@ trait ParallelTesting extends RunnerOrchestration { self =>
631644
632645 // Fail target:
633646 failTestSource(testSource)
647+
648+ if (updateCheckFiles)
649+ updateCheckFile(checkFile.get, outputLines)
634650 }
635651 }
636652
@@ -766,7 +782,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
766782 }
767783 def checkFileTest (sourceName : String , checkFile : JFile , actual : List [String ]) = {
768784 val expexted = Source .fromFile(checkFile, " UTF-8" ).getLines().toList
769- diffMessage(sourceName, actual, expexted).foreach(fail)
785+ for (msg <- diffMessage(sourceName, actual, expexted)) {
786+ fail(msg)
787+ if (updateCheckFiles)
788+ updateCheckFile(checkFile, actual)
789+ }
770790 }
771791
772792 val (compilerCrashed, expectedErrors, actualErrors, hasMissingAnnotations, errorMap) = testSource match {
@@ -1371,7 +1391,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
13711391 |Test ' $title' compiled with $errors error(s) and $warnings warning(s),
13721392 |the test can be reproduced by running:
13731393 |
1374- | sbt "testFromTasty $file"
1394+ | sbt "testCompilation --from-tasty $file"
13751395 |
13761396 |This tests can be disabled by adding ` ${file.getName}` to `compiler ${JFile .separator}test ${JFile .separator}dotc ${JFile .separator}$runOrPos- $listName.blacklist`
13771397 |
0 commit comments