@@ -40,6 +40,18 @@ class SemanticdbTests with
40
40
val target = generateSemanticdb()
41
41
val errors = mutable.ArrayBuffer .empty[Path ]
42
42
val metacSb : StringBuilder = StringBuilder (5000 )
43
+ def collectErrorOrUpdate (expectPath : Path , obtained : String ) =
44
+ if updateExpectFiles
45
+ Files .write(expectPath, obtained.getBytes(StandardCharsets .UTF_8 ))
46
+ println(" updated: " + expectPath)
47
+ else
48
+ val expected = new String (Files .readAllBytes(expectPath), StandardCharsets .UTF_8 )
49
+ val expectName = expectPath.getFileName
50
+ val relExpect = rootSrc.relativize(expectPath)
51
+ collectFailingDiff(expected, obtained, s " a/ $relExpect" , s " b/ $relExpect" ) {
52
+ Files .write(expectPath.resolveSibling(" " + expectName + " .out" ), obtained.getBytes(StandardCharsets .UTF_8 ))
53
+ errors += expectPath
54
+ }
43
55
for source <- inputFiles().sorted do
44
56
val filename = source.getFileName.toString
45
57
val relpath = expectSrc.relativize(source)
@@ -52,38 +64,16 @@ class SemanticdbTests with
52
64
val doc = Tools .loadTextDocument(source, relpath, semanticdbPath)
53
65
Tools .metac(doc, rootSrc.relativize(source))(given metacSb )
54
66
val obtained = trimTrailingWhitespace(SemanticdbTests .printTextDocument(doc))
55
- if updateExpectFiles
56
- Files .write(expectPath, obtained.getBytes(StandardCharsets .UTF_8 ))
57
- println(" updated: " + expectPath)
58
- else
59
- val expected = new String (Files .readAllBytes(expectPath), StandardCharsets .UTF_8 )
60
- val expectName = expectPath.getFileName
61
- val relExpect = rootSrc.relativize(expectPath)
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
67
- Files .write(metacExpectFile, metacSb.toString.getBytes)
68
- println(" updated: " + metacExpectFile)
69
- else
70
- val expected = new String (Files .readAllBytes(metacExpectFile), StandardCharsets .UTF_8 )
71
- val expectName = metacExpectFile.getFileName
72
- val relExpect = rootSrc.relativize(metacExpectFile)
73
- val obtained = metacSb.toString
74
- collectFailingDiff(expected, obtained, s " a/ $relExpect" , s " b/ $relExpect" ) {
75
- Files .write(metacExpectFile.resolveSibling(" " + expectName + " .out" ), obtained.getBytes(StandardCharsets .UTF_8 ))
76
- errors += metacExpectFile
77
- }
78
- errors.foreach { expect =>
67
+ collectErrorOrUpdate(expectPath, obtained)
68
+ collectErrorOrUpdate(metacExpectFile, metacSb.toString)
69
+ for expect <- errors do
79
70
def red (msg : String ) = Console .RED + msg + Console .RESET
80
71
def blue (msg : String ) = Console .BLUE + msg + Console .RESET
81
72
println(s """ [ ${red(" error" )}] check file ${blue(expect.toString)} does not match generated.
82
73
|If you meant to make a change, replace the expect file by:
83
74
| mv ${expect.resolveSibling(" " + expect.getFileName + " .out" )} $expect
84
75
|Or else update all expect files with
85
76
| sbt 'dotty-compiler-bootstrapped/test:runMain dotty.tools.dotc.semanticdb.updateExpect' """ .stripMargin)
86
- }
87
77
Files .walk(target).sorted(Comparator .reverseOrder).forEach(Files .delete)
88
78
if errors.nonEmpty
89
79
fail(s " ${errors.size} errors in expect test. " )
0 commit comments