Skip to content

Commit

Permalink
CHECK-NEXT: fix edge case when on the first line without a match (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislaw committed Feb 16, 2020
1 parent 72a0804 commit 27c26e8
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
35 changes: 19 additions & 16 deletions filecheck/FileCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,29 +602,32 @@ def main():

exit(1)
else:
assert current_scan_base > 0
previous_matched_line = input_lines[current_scan_base - 1].rstrip()

print("{}:{}:{}: error: CHECK-NEXT: is not on the line after the previous match"
.format(check_file,
current_check.check_line_idx + 1,
current_check.start_index + 1))
print(current_check.source_line.rstrip())
print("^".rjust(current_check.start_index + 1))

matching_line = input_lines[matching_line_idx].rstrip()
print("<stdin>:{}:1: note: 'next' match was here".format(matching_line_idx + 1))
print(matching_line)
print("^")

print("<stdin>:{}:{}: note: previous match ended here".format(current_scan_base, len(previous_matched_line) + 1))
print(previous_matched_line)
print("^".rjust(len(previous_matched_line) + 1))
print("<stdin>:{}:{}: note: non-matching line after previous match is here".format(current_scan_base + 1, 1))
print(last_read_line)
print("^")

exit(1)
# It is very weird that exit code can be both 1 and 2 in the
# "CHECK-NEXT: is not on the line" scenario.
if current_scan_base > 0:
matching_line = input_lines[matching_line_idx].rstrip()
print("<stdin>:{}:1: note: 'next' match was here".format(matching_line_idx + 1))
print(matching_line)
print("^")

previous_matched_line = input_lines[current_scan_base - 1].rstrip()
print("<stdin>:{}:{}: note: previous match ended here".format(current_scan_base, len(previous_matched_line) + 1))
print(previous_matched_line)
print("^".rjust(len(previous_matched_line) + 1))
print("<stdin>:{}:{}: note: non-matching line after previous match is here".format(current_scan_base + 1, 1))
print(last_read_line)
print("^")

exit(1)
else:
exit(2)

raise NotImplementedError()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// CHECK-NEXT: 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
3
[2]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
; RUN: cat %S/filecheck.input | (%FILECHECK_EXEC %S/filecheck.check; test $? = 2;) | %FILECHECK_TESTER_EXEC %s --strict-whitespace --match-full-lines
; CHECK:{{^.*}}FileCheck{{(\.py)?$}}
; CHECK-EMPTY

0 comments on commit 27c26e8

Please sign in to comment.