Skip to content

Commit 90825c7

Browse files
committed
output whole file and not diff in failure case
1 parent e349a3a commit 90825c7

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

compiler/test/dotty/tools/dotc/semanticdb/DiffAssertions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package dotty.tools.dotc.semanticdb
33
import scala.collection.JavaConverters._
44

55
object DiffAssertions {
6-
def collectFailingDiff(obtained: String, expected: String, obtainedPath: String, expectedPath: String)(onFail: String => Unit): Unit =
6+
def collectFailingDiff(obtained: String, expected: String, obtainedPath: String, expectedPath: String)(onFail: => Unit): Unit =
77
val diff = compareContents(obtained, expected, obtainedPath, expectedPath)
88
if diff.nonEmpty then
9-
onFail(diff)
9+
onFail
1010

1111
private def stripTrailingWhitespace(str: String): String = str.replaceAll(" \n", "\n")
1212

compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ class SemanticdbTests with
3838

3939
def runExpectTest(updateExpectFiles: Boolean): Unit =
4040
val target = generateSemanticdb()
41-
val errors = mutable.ArrayBuffer.empty[(Path, String)]
41+
val errors = mutable.ArrayBuffer.empty[Path]
4242
given metacSb: StringBuilder = StringBuilder(5000)
43-
inputFiles().sorted.foreach { source =>
43+
for source <- inputFiles().sorted do
4444
val filename = source.getFileName.toString
4545
val relpath = expectSrc.relativize(source)
4646
val semanticdbPath = target
@@ -59,20 +59,31 @@ class SemanticdbTests with
5959
val expected = new String(Files.readAllBytes(expectPath), StandardCharsets.UTF_8)
6060
val expectName = expectPath.getFileName
6161
val relExpect = rootSrc.relativize(expectPath)
62-
collectFailingDiff(expected, obtained, s"a/$relExpect", s"b/$relExpect")(errors += expectName -> _)
63-
}
64-
if updateExpectFiles
62+
collectFailingDiff(expected, obtained, s"a/$relExpect", s"b/$relExpect") {
63+
Files.write(expectPath.resolveSibling("" + expectName + ".out"), obtained.getBytes(StandardCharsets.UTF_8))
64+
errors += expectPath
65+
}
66+
if updateExpectFiles then
6567
Files.write(metacExpectFile, metacSb.toString.getBytes)
6668
println("updated: " + metacExpectFile)
6769
else
6870
val expected = new String(Files.readAllBytes(metacExpectFile), StandardCharsets.UTF_8)
6971
val expectName = metacExpectFile.getFileName
7072
val relExpect = rootSrc.relativize(metacExpectFile)
71-
collectFailingDiff(expected, metacSb.toString, s"a/$relExpect", s"b/$relExpect")(errors += expectName -> _)
72-
errors.foreach { (source, diff) =>
73+
val obtained = metacSb.toString
74+
def writeOut =
75+
collectFailingDiff(expected, obtained, s"a/$relExpect", s"b/$relExpect") {
76+
Files.write(metacExpectFile.resolveSibling("" + expectName + ".out"), obtained.getBytes(StandardCharsets.UTF_8));
77+
errors += metacExpectFile
78+
}
79+
errors.foreach { expect =>
7380
def red(msg: String) = Console.RED + msg + Console.RESET
7481
def blue(msg: String) = Console.BLUE + msg + Console.RESET
75-
println(s"[${red("error")}] check file ${blue(source.toString)} does not match generated:\n${red(diff)}")
82+
println(s"""[${red("error")}] check file ${blue(expect.toString)} does not match generated.
83+
|If you meant to make a change, replace the expect file by:
84+
| mv ${expect.resolveSibling("" + expect.getFileName + ".out")} $expect
85+
|Or else update all expect files with
86+
| sbt 'dotty-compiler-bootstrapped/test:runMain dotty.tools.dotc.semanticdb.updateExpect'""".stripMargin)
7687
}
7788
Files.walk(target).sorted(Comparator.reverseOrder).forEach(Files.delete)
7889
if errors.nonEmpty

0 commit comments

Comments
 (0)