Skip to content

Commit d79ccab

Browse files
authored
Merge pull request #10 from llvm-swift/scanl
Improve failure message with location of last scan
2 parents 89b8480 + 04659ef commit d79ccab

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Sources/FileCheck/CheckString.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ struct CheckString {
301301
}
302302
}
303303

304+
private let whitespaceCharacterSet: Set<Character> = [" ", "\t", "\n", "\r"]
305+
306+
304307
private func diagnoseFailedCheck(
305308
_ pattern: Pattern, _ loc: CheckLocation, _ prefix: String,
306309
_ variableTable: [String : String], _ options: FileCheckOptions,
@@ -334,6 +337,12 @@ private func diagnoseFailedCheck(
334337
)
335338
}
336339

340+
let bufferPrefix = buffer.firstIndex { !whitespaceCharacterSet.contains($0) } ?? buffer.startIndex
341+
diagnose(.note,
342+
at: .string(String(buffer[bufferPrefix...])),
343+
with: "scanning from here",
344+
options: options)
345+
337346
// Note any variables used by the pattern
338347
for (varName, _) in pattern.variableUses {
339348
if varName.first == "@" {

Tests/FileCheckTests/FileCheckSpec.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ class FileCheckSpec : XCTestCase {
151151
XCTAssert(fileCheckOutput(of: .stdout, withPrefixes: ["CHECK-NEAREST-PATTERN-MSG"]) {
152152
// CHECK-NEAREST-PATTERN-MSG: error: {{.*}}: could not find 'Once more into the beach' in input
153153
// CHECK-NEAREST-PATTERN-MSG-NEXT: // {{.*}}: Once more into the beach
154-
// CHECK-NEAREST-PATTERN-MSG-NEXT: note: possible intended match here
154+
// CHECK-NEAREST-PATTERN-MSG-NEXT: note: scanning from here
155+
// CHECK-NEAREST-PATTERN-MSG-NEXT: Once more into the breach
156+
// CHECK-NEAREST-PATTERN-MSG: note: possible intended match here
155157
// CHECK-NEAREST-PATTERN-MSG-NEXT: Once more into the breach
156158
XCTAssertFalse(fileCheckOutput(of: .stdout, withPrefixes: ["CHECK-NEAREST-PATTERN"], options: [.disableColors]) {
157159
// CHECK-NEAREST-PATTERN: Once more into the beach

0 commit comments

Comments
 (0)