Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: check_commands/CHECK-NEXT and main tests #24

Merged
merged 1 commit into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 48 additions & 22 deletions src/FileCheck
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ input_lines = []

current_scan_base = 0

for line_idx, line in enumerate(sys.stdin):
stdin_input_iter = enumerate(sys.stdin)
for line_idx, line in stdin_input_iter:
line = line.rstrip()

input_lines.append(line)
Expand Down Expand Up @@ -319,28 +320,53 @@ if current_check.check_type == CheckType.CHECK_NOT:
assert 0, "Not implemented"

if current_check.check_type == CheckType.CHECK_NEXT:
last_read_line = input_lines[current_scan_base]

if current_check.match_type == MatchType.SUBSTRING:
last_read_line = input_lines[current_scan_base]
# candidate_line = None
# current_best_ratio = 0
# for read_line in input_lines[current_scan_base:]:
# similar_ratio = similar(last_read_line, current_check.expression)
# if current_best_ratio < similar_ratio:
# candidate_line = read_line
# current_best_ratio = similar_ratio
# assert candidate_line

print("{}:{}:{}: error: CHECK-NEXT: expected string not found in input"
.format(check_file,
current_check.check_line_idx + 1,
current_check.start_index + 1))
matching_line_idx = -1
for line_idx, line in stdin_input_iter:
line = line.rstrip()
input_lines.append(line)

print(current_check.source_line.rstrip())
print("^".rjust(current_check.start_index + 1))
print("<stdin>:{}:{}: note: scanning from here".format(current_scan_base + 1, 1))
print(last_read_line)
print("^")
if current_check.expression in line:
matching_line_idx = line_idx

exit(1)
if matching_line_idx == -1:
print("{}:{}:{}: error: CHECK-NEXT: expected string not found in input"
.format(check_file,
current_check.check_line_idx + 1,
current_check.start_index + 1))

assert 0
print(current_check.source_line.rstrip())
print("^".rjust(current_check.start_index + 1))
print("<stdin>:{}:{}: note: scanning from here".format(current_scan_base + 1, 1))
print(last_read_line)
print("^")

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

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]
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)

assert 0, "Not implemented"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
; CHECK: string 1
; CHECK-NEXT: string 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
string 1
string 2
string 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; RUN: cat %S/filecheck.input | (%FILECHECK_EXEC %S/filecheck.check 2>&1; test $? = 1;) | %FILECHECK_TESTER_EXEC %s --strict-whitespace --match-full-lines
; CHECK:{{^.*}}FileCheck{{$}}
; CHECK-NEXT:{{.*}}filecheck.check:2:15: error: CHECK-NEXT: is not on the line after the previous match{{$}}
; CHECK-NEXT:; CHECK-NEXT: string 3
; CHECK-NEXT: ^
; CHECK-NEXT:<stdin>:3:1: note: 'next' match was here
; CHECK-NEXT:string 3
; CHECK-NEXT:^
; CHECK-NEXT:<stdin>:1:9: note: previous match ended here
; CHECK-NEXT:string 1
; CHECK-NEXT: ^
; CHECK-NEXT:<stdin>:2:1: note: non-matching line after previous match is here
; CHECK-NEXT:string 2
; CHECK-NEXT:^