diff --git a/filecheck/FileCheck.py b/filecheck/FileCheck.py index a43a028..d648aa6 100755 --- a/filecheck/FileCheck.py +++ b/filecheck/FileCheck.py @@ -12,6 +12,10 @@ __version__ = '0.0.4' +class CheckFailedException(Exception): + pass + + class MatchType(Enum): SUBSTRING = 1 EXACT_STRING = 2 @@ -97,8 +101,9 @@ def dump_check(check): class CheckResult(Enum): PASS = 1 - FAIL_SKIP = 2 + FAIL_SKIP_LINE = 2 FAIL_FATAL = 3 + CHECK_NOT_WITHOUT_MATCH = 4 def check_line(line, current_check, match_full_lines): @@ -110,14 +115,14 @@ def check_line(line, current_check, match_full_lines): if current_check.match_type == MatchType.SUBSTRING: if match_full_lines: if current_check.expression != line: - return CheckResult.FAIL_SKIP + return CheckResult.FAIL_SKIP_LINE else: if current_check.expression not in line: - return CheckResult.FAIL_SKIP + return CheckResult.FAIL_SKIP_LINE elif current_check.match_type == MatchType.REGEX: if not re.search(current_check.expression, line): - return CheckResult.FAIL_SKIP + return CheckResult.FAIL_SKIP_LINE elif current_check.check_type == CheckType.CHECK_NEXT: if current_check.match_type == MatchType.SUBSTRING: @@ -136,10 +141,14 @@ def check_line(line, current_check, match_full_lines): if current_check.match_type == MatchType.SUBSTRING: if current_check.expression in line: return CheckResult.FAIL_FATAL + else: + return CheckResult.CHECK_NOT_WITHOUT_MATCH elif current_check.match_type == MatchType.REGEX: if re.search(current_check.expression, line): return CheckResult.FAIL_FATAL + else: + return CheckResult.CHECK_NOT_WITHOUT_MATCH return CheckResult.PASS @@ -295,27 +304,44 @@ def main(): check_result = None stdin_input_iter = enumerate(sys.stdin) - for line_idx, line in stdin_input_iter: - line = line.rstrip() - if not args.strict_whitespace: - line = canonicalize_whitespace(line) - - input_lines.append(line) - - check_result = check_line(line, current_check, args.match_full_lines) - - if check_result == CheckResult.FAIL_FATAL: - break - elif check_result == CheckResult.FAIL_SKIP: - continue - else: - pass - - try: - current_check = next(check_iterator) - current_scan_base = line_idx + 1 - except StopIteration: - exit(0) + + try: + for line_idx, line in stdin_input_iter: + line = line.rstrip() + if not args.strict_whitespace: + line = canonicalize_whitespace(line) + + input_lines.append(line) + + while True: + check_result = check_line(line, current_check, args.match_full_lines) + + if check_result == CheckResult.PASS: + try: + current_check = next(check_iterator) + current_scan_base = line_idx + 1 + except StopIteration: + exit(0) + + break + + elif check_result == CheckResult.CHECK_NOT_WITHOUT_MATCH: + try: + current_check = next(check_iterator) + current_scan_base = line_idx + 1 + except StopIteration: + exit(0) + + elif check_result == CheckResult.FAIL_FATAL: + raise CheckFailedException() + + elif check_result == CheckResult.FAIL_SKIP_LINE: + break + + else: + assert 0 + except CheckFailedException: + pass if not input_lines: print("CHECK: FileCheck error: '-' is empty.") diff --git a/tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/02-positive_check_effective_only_one_line_before_next_check/filecheck.check b/tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/02-positive_check_effective_only_one_line_before_next_check/filecheck.check new file mode 100644 index 0000000..4e146d9 --- /dev/null +++ b/tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/02-positive_check_effective_only_one_line_before_next_check/filecheck.check @@ -0,0 +1,4 @@ +; CHECK: string1 +; CHECK-NOT: hello +; CHECK: string2 +; CHECK: string3 diff --git a/tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/02-positive_check_effective_only_one_line_before_next_check/filecheck.input b/tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/02-positive_check_effective_only_one_line_before_next_check/filecheck.input new file mode 100644 index 0000000..f3abf7f --- /dev/null +++ b/tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/02-positive_check_effective_only_one_line_before_next_check/filecheck.input @@ -0,0 +1,3 @@ +string1 +string2 +string3 diff --git a/tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/02-positive_match_regex/sample.itest b/tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/02-positive_check_effective_only_one_line_before_next_check/sample.itest similarity index 100% rename from tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/02-positive_match_regex/sample.itest rename to tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/02-positive_check_effective_only_one_line_before_next_check/sample.itest diff --git a/tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/02-positive_match_regex/filecheck.check b/tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/03-positive_match_regex/filecheck.check similarity index 100% rename from tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/02-positive_match_regex/filecheck.check rename to tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/03-positive_match_regex/filecheck.check diff --git a/tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/02-positive_match_regex/filecheck.input b/tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/03-positive_match_regex/filecheck.input similarity index 100% rename from tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/02-positive_match_regex/filecheck.input rename to tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/03-positive_match_regex/filecheck.input diff --git a/tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/03-positive_match_regex/sample.itest b/tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/03-positive_match_regex/sample.itest new file mode 100644 index 0000000..60c6bf2 --- /dev/null +++ b/tests/integration/tests/check_commands/CHECK-NOT/one_string/positive/03-positive_match_regex/sample.itest @@ -0,0 +1,3 @@ +; RUN: cat %S/filecheck.input | (%FILECHECK_EXEC %S/filecheck.check 2>&1; test $? == 0;) | %FILECHECK_TESTER_EXEC %s --match-full-lines +; CHECK: {{^.*}}FileCheck{{(\.py)?$}} +; CHECK-EMPTY: