@@ -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