Skip to content

Commit f04b2ea

Browse files
Merge pull request #5894 from dotty-staging/add-update-checkfiles
Add `updateCheckFiles` to override tests check files with output
2 parents 51853d6 + 7076c74 commit f04b2ea

File tree

63 files changed

+99
-144
lines changed

Some content is hidden

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

63 files changed

+99
-144
lines changed

compiler/test/dotc/comptest.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ object comptest extends ParallelTesting {
1111
def safeMode = false
1212
def isInteractive = true
1313
def testFilter = None
14+
def updateCheckFiles: Boolean = false
1415

1516
val posDir = "./tests/pos/"
1617
val negDir = "./tests/neg/"

compiler/test/dotty/Properties.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ object Properties {
2020
*/
2121
val testsFilter: Option[String] = sys.props.get("dotty.tests.filter")
2222

23+
/** Tests should override the checkfiles with the current output */
24+
val testsUpdateCheckfile: Boolean = propIsNullOrTrue("dotty.tests.updateCheckfiles")
25+
2326
/** When set, the run tests are only compiled - not run, a warning will be
2427
* issued
2528
*/

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@ import org.junit.Assert._
77
import org.junit.Assume._
88
import org.junit.experimental.categories.Category
99

10-
import java.nio.file._
11-
import java.util.stream.{ Stream => JStream }
12-
import scala.collection.JavaConverters._
13-
import scala.util.matching.Regex
1410
import scala.concurrent.duration._
1511
import vulpix._
16-
import dotty.tools.io.JFile
1712

1813
@Category(Array(classOf[BootstrappedOnlyTests]))
1914
class BootstrappedOnlyCompilationTests extends ParallelTesting {
@@ -28,6 +23,7 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting {
2823
def safeMode = Properties.testsSafeMode
2924
def isInteractive = SummaryReport.isInteractive
3025
def testFilter = Properties.testsFilter
26+
def updateCheckFiles: Boolean = Properties.testsUpdateCheckfile
3127

3228
// Positive tests ------------------------------------------------------------
3329

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class CompilationTests extends ParallelTesting {
2727
def safeMode = Properties.testsSafeMode
2828
def isInteractive = SummaryReport.isInteractive
2929
def testFilter = Properties.testsFilter
30+
def updateCheckFiles: Boolean = Properties.testsUpdateCheckfile
3031

3132
// Positive tests ------------------------------------------------------------
3233

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class FromTastyTests extends ParallelTesting {
2020
def safeMode = Properties.testsSafeMode
2121
def isInteractive = SummaryReport.isInteractive
2222
def testFilter = Properties.testsFilter
23-
23+
def updateCheckFiles: Boolean = Properties.testsUpdateCheckfile
2424

2525
@Test def posTestFromTasty: Unit = {
2626
// Can be reproduced with

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class IdempotencyTests extends ParallelTesting {
2424
def safeMode = Properties.testsSafeMode
2525
def isInteractive = SummaryReport.isInteractive
2626
def testFilter = Properties.testsFilter
27+
def updateCheckFiles: Boolean = Properties.testsUpdateCheckfile
2728

2829
@Category(Array(classOf[SlowTests]))
2930
@Test def idempotency: Unit = {

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

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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
|

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ trait SummaryReporting {
4040

4141
/** Echoes contents of `it` to file *immediately* then flushes */
4242
def echoToLog(it: Iterator[String]): Unit
43+
4344
}
4445

4546
/** A summary report that doesn't do anything */
@@ -53,6 +54,7 @@ final class NoSummaryReport extends SummaryReporting {
5354
def echoSummary(): Unit = ()
5455
def echoToLog(msg: String): Unit = ()
5556
def echoToLog(it: Iterator[String]): Unit = ()
57+
def updateCheckFiles: Boolean = false
5658
}
5759

5860
/** A summary report that logs to both stdout and the `TestReporter.logWriter`

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package vulpix
44
import org.junit.Test
55
import org.junit.experimental.categories.Category
66
import scala.concurrent.duration._
7-
import dotty.Properties
87
import TestConfiguration._
98

109
/** Meta tests for the Vulpix test suite. This test follows the structure of
@@ -19,6 +18,7 @@ class VulpixMetaTests extends ParallelTesting {
1918
def safeMode = false // Don't fork a new VM after each run test
2019
def isInteractive = false // Don't beautify output for interactive use.
2120
def testFilter = None // Run all the tests.
21+
def updateCheckFiles: Boolean = false
2222

2323
implicit val summaryReport: SummaryReporting = new SummaryReport
2424
implicit def testGroup: TestGroup = TestGroup("VulpixMetaTests")

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class VulpixUnitTests extends ParallelTesting {
2121
def safeMode = sys.env.get("SAFEMODE").isDefined
2222
def isInteractive = !sys.env.contains("DRONE")
2323
def testFilter = None
24+
def updateCheckFiles: Boolean = false
2425

2526
// To fail with something else than an AssertionError
2627
def fail(): Unit = throw new Exception("didn't fail properly")

0 commit comments

Comments
 (0)