Skip to content

Commit c4545a6

Browse files
committed
Add --update-checkfiles to testCompilation
1 parent 324fcea commit c4545a6

File tree

12 files changed

+32
-21
lines changed

12 files changed

+32
-21
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: 2 additions & 1 deletion
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

@@ -303,7 +304,7 @@ class CompilationTests extends ParallelTesting {
303304
}
304305

305306
object CompilationTests {
306-
implicit val summaryReport: SummaryReporting = new SummaryReport(updateCheckFiles = false)
307+
implicit val summaryReport: SummaryReporting = new SummaryReport
307308
@AfterClass def cleanup(): Unit = summaryReport.echoSummary()
308309

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

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

Lines changed: 2 additions & 2 deletions
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
@@ -51,6 +51,6 @@ class FromTastyTests extends ParallelTesting {
5151
}
5252

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

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

Lines changed: 2 additions & 1 deletion
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 = {
@@ -72,6 +73,6 @@ class IdempotencyTests extends ParallelTesting {
7273
}
7374

7475
object IdempotencyTests {
75-
implicit val summaryReport: SummaryReporting = new SummaryReport(updateCheckFiles = false)
76+
implicit val summaryReport: SummaryReporting = new SummaryReport
7677
@AfterClass def cleanup(): Unit = summaryReport.echoSummary()
7778
}

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

Lines changed: 6 additions & 3 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
*/
@@ -550,7 +553,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
550553

551554
if (output.mkString(EOL) != check) {
552555
val outFile = dotty.tools.io.File(checkFile.toPath).addExtension(".out")
553-
if (summaryReport.updateCheckFiles) {
556+
if (updateCheckFiles) {
554557
updateCheckFile(checkFile, output)
555558
} else {
556559
outFile.writeAll(output.mkString("", EOL, ""))
@@ -642,7 +645,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
642645
// Fail target:
643646
failTestSource(testSource)
644647

645-
if (summaryReport.updateCheckFiles)
648+
if (updateCheckFiles)
646649
updateCheckFile(checkFile.get, outputLines)
647650
}
648651
}
@@ -781,7 +784,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
781784
val expexted = Source.fromFile(checkFile, "UTF-8").getLines().toList
782785
for (msg <- diffMessage(sourceName, actual, expexted)) {
783786
fail(msg)
784-
if (summaryReport.updateCheckFiles)
787+
if (updateCheckFiles)
785788
updateCheckFile(checkFile, actual)
786789
}
787790
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ trait SummaryReporting {
4141
/** Echoes contents of `it` to file *immediately* then flushes */
4242
def echoToLog(it: Iterator[String]): Unit
4343

44-
/** Echoes outputs of the test into the thier checkfiles */
45-
def updateCheckFiles: Boolean
4644
}
4745

4846
/** A summary report that doesn't do anything */
@@ -62,7 +60,7 @@ final class NoSummaryReport extends SummaryReporting {
6260
/** A summary report that logs to both stdout and the `TestReporter.logWriter`
6361
* which outputs to a log file in `./testlogs/`
6462
*/
65-
final class SummaryReport(val updateCheckFiles: Boolean) extends SummaryReporting {
63+
final class SummaryReport extends SummaryReporting {
6664
import scala.collection.JavaConverters._
6765

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

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

Lines changed: 2 additions & 2 deletions
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,8 +18,9 @@ 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

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

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

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")

docs/docs/contributing/testing.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ This will run both the test `./tests/pos/companions.scala` and
8080
`./tests/neg/companions.scala` since both of these match the given string.
8181
This also means that you could run `testCompilation` with no arguments to run all integration tests.
8282

83+
When complex checkfiles must be updated, `testCompilation` can run in a mode where it overrides the checkfiles with the test outputs.
84+
```bash
85+
$ sbt
86+
> testCompilation --update-checkfiles
87+
```
88+
8389
### Bootstrapped-only tests
8490

8591
To run `testCompilation` on a bootstrapped Dotty compiler, use

project/Build.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,11 @@ object Build {
440440

441441
def testOnlyFiltered(test: String, options: String) = Def.inputTaskDyn {
442442
val args = spaceDelimited("<arg>").parsed
443-
val cmd = s" $test -- $options" + {
444-
if (args.nonEmpty) " -Ddotty.tests.filter=" + args.mkString(" ")
445-
else ""
446-
}
443+
val updateCheckfile = args.contains("--update-checkfiles")
444+
val args1 = if (updateCheckfile) args.filter(_ != "--update-checkfiles") else args
445+
val cmd = s" $test -- $options" +
446+
(if (updateCheckfile) " -Ddotty.tests.updateCheckfiles=true" else "") +
447+
(if (args1.nonEmpty) " -Ddotty.tests.filter=" + args1.mkString(" ") else "")
447448
(testOnly in Test).toTask(cmd)
448449
}
449450

0 commit comments

Comments
 (0)