Skip to content

Commit 324fcea

Browse files
committed
Add updateCheckFiles to override tests check files with output
Also updated `testFromTasty` checkfiles using it to remove first comment line which cannot be tested on Windows adn added missing EOLs.
1 parent 7ff971f commit 324fcea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+63
-127
lines changed

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ class CompilationTests extends ParallelTesting {
303303
}
304304

305305
object CompilationTests {
306-
implicit val summaryReport: SummaryReporting = new SummaryReport
306+
implicit val summaryReport: SummaryReporting = new SummaryReport(updateCheckFiles = false)
307307
@AfterClass def cleanup(): Unit = summaryReport.echoSummary()
308308

309309
def sources(paths: JStream[Path], excludedFiles: List[String] = Nil): List[String] = {

compiler/test/dotty/tools/dotc/FromTastyTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ class FromTastyTests extends ParallelTesting {
5151
}
5252

5353
object FromTastyTests {
54-
implicit val summaryReport: SummaryReporting = new SummaryReport
54+
implicit val summaryReport: SummaryReporting = new SummaryReport(updateCheckFiles = false)
5555
@AfterClass def cleanup(): Unit = summaryReport.echoSummary()
5656
}

compiler/test/dotty/tools/dotc/IdempotencyTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ class IdempotencyTests extends ParallelTesting {
7272
}
7373

7474
object IdempotencyTests {
75-
implicit val summaryReport: SummaryReporting = new SummaryReport
75+
implicit val summaryReport: SummaryReporting = new SummaryReport(updateCheckFiles = false)
7676
@AfterClass def cleanup(): Unit = summaryReport.echoSummary()
7777
}

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,12 @@ trait ParallelTesting extends RunnerOrchestration { self =>
505505
this
506506
}
507507

508+
protected def updateCheckFile(checkFile: JFile, lines: Seq[String]): Unit = {
509+
val outFile = dotty.tools.io.File(checkFile.toPath)
510+
outFile.writeAll(lines.mkString("", EOL, EOL))
511+
echo("Updated checkfile: " + checkFile.getPath)
512+
}
513+
508514
/** Returns all files in directory or the file if not a directory */
509515
private def flattenFiles(f: JFile): Array[JFile] =
510516
if (f.isDirectory) f.listFiles.flatMap(flattenFiles)
@@ -537,28 +543,32 @@ trait ParallelTesting extends RunnerOrchestration { self =>
537543
val output = Source.fromFile(outDir.getParent + "_decompiled" + JFile.separator + outDir.getName
538544
+ JFile.separator + "decompiled.scala", "UTF-8").getLines().map {line =>
539545
stripTrailingWhitespaces.unapplySeq(line).map(_.head).getOrElse(line)
540-
}.toList
546+
}.filter(!_.startsWith(ignoredFilePathLine)).toList
541547

542-
val check: String = Source.fromFile(checkFile, "UTF-8").getLines().filter(!_.startsWith(ignoredFilePathLine))
548+
val check: String = Source.fromFile(checkFile, "UTF-8").getLines()
543549
.mkString(EOL)
544550

545-
if (output.filter(!_.startsWith(ignoredFilePathLine)).mkString(EOL) != check) {
551+
if (output.mkString(EOL) != check) {
546552
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
553+
if (summaryReport.updateCheckFiles) {
554+
updateCheckFile(checkFile, output)
555+
} else {
556+
outFile.writeAll(output.mkString("", EOL, ""))
557+
val msg =
558+
s"""Output differed for test $name, use the following command to see the diff:
559+
| > diff $checkFile $outFile
551560
""".stripMargin
552561

553-
echo(msg)
554-
addFailureInstruction(msg)
562+
echo(msg)
563+
addFailureInstruction(msg)
555564

556-
// Print build instructions to file and summary:
557-
val buildInstr = testSource.buildInstructions(0, rep.warningCount)
558-
addFailureInstruction(buildInstr)
565+
// Print build instructions to file and summary:
566+
val buildInstr = testSource.buildInstructions(0, rep.warningCount)
567+
addFailureInstruction(buildInstr)
559568

560-
// Fail target:
561-
failTestSource(testSource)
569+
// Fail target:
570+
failTestSource(testSource)
571+
}
562572
}
563573
case _ =>
564574
}
@@ -631,6 +641,9 @@ trait ParallelTesting extends RunnerOrchestration { self =>
631641

632642
// Fail target:
633643
failTestSource(testSource)
644+
645+
if (summaryReport.updateCheckFiles)
646+
updateCheckFile(checkFile.get, outputLines)
634647
}
635648
}
636649

@@ -766,7 +779,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
766779
}
767780
def checkFileTest(sourceName: String, checkFile: JFile, actual: List[String]) = {
768781
val expexted = Source.fromFile(checkFile, "UTF-8").getLines().toList
769-
diffMessage(sourceName, actual, expexted).foreach(fail)
782+
for (msg <- diffMessage(sourceName, actual, expexted)) {
783+
fail(msg)
784+
if (summaryReport.updateCheckFiles)
785+
updateCheckFile(checkFile, actual)
786+
}
770787
}
771788

772789
val (compilerCrashed, expectedErrors, actualErrors, hasMissingAnnotations, errorMap) = testSource match {

compiler/test/dotty/tools/vulpix/SummaryReport.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ trait SummaryReporting {
4040

4141
/** Echoes contents of `it` to file *immediately* then flushes */
4242
def echoToLog(it: Iterator[String]): Unit
43+
44+
/** Echoes outputs of the test into the thier checkfiles */
45+
def updateCheckFiles: Boolean
4346
}
4447

4548
/** A summary report that doesn't do anything */
@@ -53,12 +56,13 @@ final class NoSummaryReport extends SummaryReporting {
5356
def echoSummary(): Unit = ()
5457
def echoToLog(msg: String): Unit = ()
5558
def echoToLog(it: Iterator[String]): Unit = ()
59+
def updateCheckFiles: Boolean = false
5660
}
5761

5862
/** A summary report that logs to both stdout and the `TestReporter.logWriter`
5963
* which outputs to a log file in `./testlogs/`
6064
*/
61-
final class SummaryReport extends SummaryReporting {
65+
final class SummaryReport(val updateCheckFiles: Boolean) extends SummaryReporting {
6266
import scala.collection.JavaConverters._
6367

6468
private val startingMessages = new java.util.concurrent.ConcurrentLinkedDeque[String]

compiler/test/dotty/tools/vulpix/VulpixMetaTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class VulpixMetaTests extends ParallelTesting {
2020
def isInteractive = false // Don't beautify output for interactive use.
2121
def testFilter = None // Run all the tests.
2222

23-
implicit val summaryReport: SummaryReporting = new SummaryReport
23+
implicit val summaryReport: SummaryReporting = new SummaryReport(updateCheckFiles = false)
2424
implicit def testGroup: TestGroup = TestGroup("VulpixMetaTests")
2525

2626
@Test def compilePos: Unit = compileFilesInDir("tests/vulpix-tests/meta/pos", defaultOptions).checkCompile()

tests/pos/classWithCompObj.decompiled

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
/** Decompiled from out/posTestFromTasty/pos/classWithCompObj/Foo.class */
21
class Foo()
3-
object Foo
2+
object Foo

tests/pos/conforms.decompiled

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/** Decompiled from out/posTestFromTasty/pos/conforms/Test.class */
21
object Test {
32
def f[A, B](x: A)(implicit e: scala.Predef.<:<[A, B]): B = e.apply(x)
4-
}
3+
}

tests/pos/i0306.decompiled

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/** Decompiled from out/posTestFromTasty/pos/i0306/bar.class */
21
object bar {
32
class C[T <: scala.Seq[_ >: scala.Nothing <: scala.Any]]()
43
val x: scala.AnyRef = new bar.C[scala.collection.Seq[_ >: scala.Nothing <: scala.Any]]()

tests/pos/i1181.decompiled

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/** Decompiled from out/posTestFromTasty/pos/i1181/Test.class */
21
object Test {
32
def foo[M[_$1]](x: M[scala.Int]): M[scala.Int] = x
43
type Alias[A] = scala.Tuple2[A, A]

0 commit comments

Comments
 (0)