Skip to content

Commit 9efdc3f

Browse files
committed
Make filecheck die gracefully when regex search fails to find matches
1 parent 7dfc371 commit 9efdc3f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Tests/LLVMTests/FileCheck.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ private class Pattern {
674674

675675
// Successful regex match.
676676
guard let fullMatch = matchInfo.first else {
677-
fatalError("Didn't get any matches!")
677+
return nil
678678
}
679679

680680
// If this defines any variables, remember their values.
@@ -1014,7 +1014,13 @@ private struct CheckString {
10141014
// Match itself from the last position after matching CHECK-DAG.
10151015
let matchBuffer = buffer.substring(from: buffer.index(buffer.startIndex, offsetBy: lastPos))
10161016
guard let (matchPos, matchLen) = self.pattern.match(matchBuffer, variableTable) else {
1017-
diagnose(.error, self.loc, self.prefix + ": could not find '\(self.pattern.fixedString)' in input")
1017+
if self.pattern.fixedString.isEmpty {
1018+
diagnose(.error, self.loc, self.prefix + ": could not find a match for regex '\(self.pattern.regExPattern)' in input")
1019+
} else if self.pattern.regExPattern.isEmpty {
1020+
diagnose(.error, self.loc, self.prefix + ": could not find '\(self.pattern.fixedString)' in input")
1021+
} else {
1022+
diagnose(.error, self.loc, self.prefix + ": could not find '\(self.pattern.fixedString)' (with regex '\(self.pattern.regExPattern)') in input")
1023+
}
10181024
return nil
10191025
}
10201026

0 commit comments

Comments
 (0)