diff --git a/src/FileCheck b/src/FileCheck index 304d7a2..2e5ddda 100755 --- a/src/FileCheck +++ b/src/FileCheck @@ -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) @@ -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(":{}:{}: 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(":{}:{}: 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(":{}:1: note: 'next' match was here".format(matching_line_idx + 1)) + print(matching_line) + print("^") + + print(":{}:{}: 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(":{}:{}: 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" diff --git a/tests/integration/tests/check_commands/CHECK-NEXT/01-negative_match/filecheck.check b/tests/integration/tests/check_commands/CHECK-NEXT/01-negative_match_line_does_not_exist/filecheck.check similarity index 100% rename from tests/integration/tests/check_commands/CHECK-NEXT/01-negative_match/filecheck.check rename to tests/integration/tests/check_commands/CHECK-NEXT/01-negative_match_line_does_not_exist/filecheck.check diff --git a/tests/integration/tests/check_commands/CHECK-NEXT/01-negative_match/filecheck.input b/tests/integration/tests/check_commands/CHECK-NEXT/01-negative_match_line_does_not_exist/filecheck.input similarity index 100% rename from tests/integration/tests/check_commands/CHECK-NEXT/01-negative_match/filecheck.input rename to tests/integration/tests/check_commands/CHECK-NEXT/01-negative_match_line_does_not_exist/filecheck.input diff --git a/tests/integration/tests/check_commands/CHECK-NEXT/01-negative_match/sample.itest b/tests/integration/tests/check_commands/CHECK-NEXT/01-negative_match_line_does_not_exist/sample.itest similarity index 100% rename from tests/integration/tests/check_commands/CHECK-NEXT/01-negative_match/sample.itest rename to tests/integration/tests/check_commands/CHECK-NEXT/01-negative_match_line_does_not_exist/sample.itest diff --git a/tests/integration/tests/check_commands/CHECK-NEXT/02-negative_match_line_exist_but_later/filecheck.check b/tests/integration/tests/check_commands/CHECK-NEXT/02-negative_match_line_exist_but_later/filecheck.check new file mode 100644 index 0000000..746947a --- /dev/null +++ b/tests/integration/tests/check_commands/CHECK-NEXT/02-negative_match_line_exist_but_later/filecheck.check @@ -0,0 +1,2 @@ +; CHECK: string 1 +; CHECK-NEXT: string 3 diff --git a/tests/integration/tests/check_commands/CHECK-NEXT/02-negative_match_line_exist_but_later/filecheck.input b/tests/integration/tests/check_commands/CHECK-NEXT/02-negative_match_line_exist_but_later/filecheck.input new file mode 100644 index 0000000..a4031bf --- /dev/null +++ b/tests/integration/tests/check_commands/CHECK-NEXT/02-negative_match_line_exist_but_later/filecheck.input @@ -0,0 +1,3 @@ +string 1 +string 2 +string 3 diff --git a/tests/integration/tests/check_commands/CHECK-NEXT/02-negative_match_line_exist_but_later/sample.itest b/tests/integration/tests/check_commands/CHECK-NEXT/02-negative_match_line_exist_but_later/sample.itest new file mode 100644 index 0000000..b7ab47f --- /dev/null +++ b/tests/integration/tests/check_commands/CHECK-NEXT/02-negative_match_line_exist_but_later/sample.itest @@ -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::3:1: note: 'next' match was here +; CHECK-NEXT:string 3 +; CHECK-NEXT:^ +; CHECK-NEXT::1:9: note: previous match ended here +; CHECK-NEXT:string 1 +; CHECK-NEXT: ^ +; CHECK-NEXT::2:1: note: non-matching line after previous match is here +; CHECK-NEXT:string 2 +; CHECK-NEXT:^