Skip to content

Commit 17141e8

Browse files
committed
Add filtering & checkfile update to PatmatExhaustivityTest
1 parent 094a3c5 commit 17141e8

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class PatmatExhaustivityTest {
4545
val baseFilePath = path.toString.stripSuffix(".scala")
4646
val checkFilePath = baseFilePath + ".check"
4747

48-
FileDiff.checkAndDump(path.toString, actualLines, checkFilePath)
48+
FileDiff.checkAndDumpOrUpdate(path.toString, actualLines, checkFilePath)
4949
}
5050

5151
/** A single test with multiple files grouped in a folder */
@@ -57,13 +57,17 @@ class PatmatExhaustivityTest {
5757
val actualLines = compile(files)
5858
val checkFilePath = s"${path}${File.separator}expected.check"
5959

60-
FileDiff.checkAndDump(path.toString, actualLines, checkFilePath)
60+
FileDiff.checkAndDumpOrUpdate(path.toString, actualLines, checkFilePath)
6161
}
6262

6363
@Test
6464
def patmatExhaustivity: Unit = {
6565
val res = Directory(testsDir).list.toList
6666
.filter(f => f.extension == "scala" || f.isDirectory)
67+
.filter { f =>
68+
val path = if f.isDirectory then f.path + "/" else f.path
69+
path.contains(Properties.testsFilter.getOrElse(""))
70+
}
6771
.map(f => if f.isDirectory then compileDir(f.jpath) else compileFile(f.jpath))
6872

6973
val failed = res.filter(!_)

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,21 @@ object FileDiff {
6363
}
6464
}
6565

66+
def checkAndDumpOrUpdate(sourceTitle: String, actualLines: Seq[String], checkFilePath: String): Boolean = {
67+
val outFilePath = checkFilePath + ".out"
68+
FileDiff.check(sourceTitle, actualLines, checkFilePath) match {
69+
case Some(msg) if dotty.Properties.testsUpdateCheckfile =>
70+
FileDiff.dump(checkFilePath, actualLines)
71+
println("Updated checkfile: " + checkFilePath)
72+
false
73+
case Some(msg) =>
74+
FileDiff.dump(outFilePath, actualLines)
75+
println(msg)
76+
println(FileDiff.diffMessage(checkFilePath, outFilePath))
77+
false
78+
case _ =>
79+
Files.deleteIfExists(Paths.get(outFilePath))
80+
true
81+
}
82+
}
6683
}

0 commit comments

Comments
 (0)