diff --git a/filecheck/FileCheck.py b/filecheck/FileCheck.py index d648aa6..6f6a8c7 100755 --- a/filecheck/FileCheck.py +++ b/filecheck/FileCheck.py @@ -306,7 +306,14 @@ def main(): stdin_input_iter = enumerate(sys.stdin) try: - for line_idx, line in stdin_input_iter: + line_idx, line = next(stdin_input_iter) + except StopIteration: + print("CHECK: FileCheck error: '-' is empty.") + print("FileCheck command line: {}".format(check_file)) + exit(2) + + try: + while True: line = line.rstrip() if not args.strict_whitespace: line = canonicalize_whitespace(line) @@ -319,16 +326,19 @@ def main(): if check_result == CheckResult.PASS: try: current_check = next(check_iterator) - current_scan_base = line_idx + 1 except StopIteration: exit(0) - break + try: + line_idx, line = next(stdin_input_iter) + current_scan_base = line_idx + break + except StopIteration: + raise CheckFailedException() elif check_result == CheckResult.CHECK_NOT_WITHOUT_MATCH: try: current_check = next(check_iterator) - current_scan_base = line_idx + 1 except StopIteration: exit(0) @@ -336,18 +346,16 @@ def main(): raise CheckFailedException() elif check_result == CheckResult.FAIL_SKIP_LINE: - break - + try: + line_idx, line = next(stdin_input_iter) + break + except StopIteration: + raise CheckFailedException() else: assert 0 except CheckFailedException: pass - if not input_lines: - print("CHECK: FileCheck error: '-' is empty.") - print("FileCheck command line: {}".format(check_file)) - exit(2) - if current_check.check_type == CheckType.CHECK_EMPTY: if check_result == CheckResult.PASS: exit(0) @@ -367,6 +375,8 @@ def main(): if current_check.check_type == CheckType.CHECK: if current_check.match_type == MatchType.SUBSTRING: + assert current_scan_base < len(input_lines) + last_read_line = input_lines[current_scan_base] print("{}:{}:{}: error: CHECK: expected string not found in input" diff --git a/tests/integration/tests/check_commands/CHECK/one_string/negative-match/04-negative_match_no_input_lines_anymore/filecheck.check b/tests/integration/tests/check_commands/CHECK/one_string/negative-match/04-negative_match_no_input_lines_anymore/filecheck.check new file mode 100644 index 0000000..21e1a79 --- /dev/null +++ b/tests/integration/tests/check_commands/CHECK/one_string/negative-match/04-negative_match_no_input_lines_anymore/filecheck.check @@ -0,0 +1,2 @@ +; CHECK: String1 +; CHECK: String2 diff --git a/tests/integration/tests/check_commands/CHECK/one_string/negative-match/04-negative_match_no_input_lines_anymore/filecheck.input b/tests/integration/tests/check_commands/CHECK/one_string/negative-match/04-negative_match_no_input_lines_anymore/filecheck.input new file mode 100644 index 0000000..1451763 --- /dev/null +++ b/tests/integration/tests/check_commands/CHECK/one_string/negative-match/04-negative_match_no_input_lines_anymore/filecheck.input @@ -0,0 +1 @@ +String1 \ No newline at end of file diff --git a/tests/integration/tests/check_commands/CHECK/one_string/negative-match/04-negative_match_no_input_lines_anymore/sample.itest b/tests/integration/tests/check_commands/CHECK/one_string/negative-match/04-negative_match_no_input_lines_anymore/sample.itest new file mode 100644 index 0000000..b4f7838 --- /dev/null +++ b/tests/integration/tests/check_commands/CHECK/one_string/negative-match/04-negative_match_no_input_lines_anymore/sample.itest @@ -0,0 +1,9 @@ +; 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{{(\.py)?$}} +; CHECK:{{^.*}}filecheck.check:2:10: error: CHECK: expected string not found in input{{$}} +; CHECK:; CHECK: String2 +; CHECK: ^ +; TODO::1:8: note: scanning from here +; TODO:String1 +; TODO: ^ +; TODO-EMPTY: