Skip to content

Commit 49576ee

Browse files
committed
Check that self-parsing does not produce any diagnostics
1 parent 856a350 commit 49576ee

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Tests/SwiftParserTest/ParserTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ public class ParserTests: XCTestCase {
1818
let fileContents = try String(contentsOf: fileURL)
1919
let parsed = try Parser.parse(source: fileContents)
2020
AssertStringsEqualWithDiff("\(parsed)", fileContents)
21+
let diagnostics = ParseDiagnosticsGenerator.diagnostics(for: parsed)
22+
if !diagnostics.isEmpty {
23+
var locationAndDiagnostics: [String] = []
24+
let locationConverter = SourceLocationConverter(file: fileURL.lastPathComponent, tree: parsed)
25+
for diag in diagnostics {
26+
let location = diag.location(converter: locationConverter)
27+
let message = diag.message
28+
locationAndDiagnostics.append("\(location): \(message)")
29+
}
30+
XCTFail("""
31+
Received the following diagnostics while parsing \(fileURL)
32+
\(locationAndDiagnostics.joined(separator: "\n"))
33+
""")
34+
}
2135
}())
2236
}
2337
}

0 commit comments

Comments
 (0)