@@ -38,9 +38,9 @@ class SemanticdbTests with
38
38
39
39
def runExpectTest (updateExpectFiles : Boolean ): Unit =
40
40
val target = generateSemanticdb()
41
- val errors = mutable.ArrayBuffer .empty[( Path , String ) ]
41
+ val errors = mutable.ArrayBuffer .empty[Path ]
42
42
given metacSb : StringBuilder = StringBuilder (5000 )
43
- inputFiles().sorted.foreach { source =>
43
+ for source <- inputFiles().sorted do
44
44
val filename = source.getFileName.toString
45
45
val relpath = expectSrc.relativize(source)
46
46
val semanticdbPath = target
@@ -59,20 +59,31 @@ class SemanticdbTests with
59
59
val expected = new String (Files .readAllBytes(expectPath), StandardCharsets .UTF_8 )
60
60
val expectName = expectPath.getFileName
61
61
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
65
67
Files .write(metacExpectFile, metacSb.toString.getBytes)
66
68
println(" updated: " + metacExpectFile)
67
69
else
68
70
val expected = new String (Files .readAllBytes(metacExpectFile), StandardCharsets .UTF_8 )
69
71
val expectName = metacExpectFile.getFileName
70
72
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 =>
73
80
def red (msg : String ) = Console .RED + msg + Console .RESET
74
81
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)
76
87
}
77
88
Files .walk(target).sorted(Comparator .reverseOrder).forEach(Files .delete)
78
89
if errors.nonEmpty
0 commit comments