diff --git a/filecheck/FileCheck.py b/filecheck/FileCheck.py index 6c5bcd0..d7ca42d 100755 --- a/filecheck/FileCheck.py +++ b/filecheck/FileCheck.py @@ -283,7 +283,7 @@ def exit_handler(code): line = canonicalize_whitespace(line) # CHECK and CHECK-NEXT - strict_whitespace_match = "" if args.strict_whitespace and args.match_full_lines else " *" + strict_whitespace_match = "" if strict_mode else " *" check_regex = "{}({}):{}(.*)".format(before_prefix, check_prefix, strict_whitespace_match) check_match = re.search(check_regex, line) @@ -296,7 +296,7 @@ def exit_handler(code): if check_match: check_keyword = check_match.group(2) check_expression = check_match.group(3) - if not (args.strict_whitespace and args.match_full_lines): + if not strict_mode: check_expression = check_expression.strip(' ') match_type = MatchType.SUBSTRING @@ -306,6 +306,11 @@ def exit_handler(code): regex_line = re.sub(r"\{\{(.*?)\}\}", r"\1", regex_line) match_type = MatchType.REGEX check_expression = regex_line + if strict_mode: + if check_expression[0] != "^": + check_expression = "^" + check_expression + if check_expression[-1] != "$": + check_expression = check_expression + "$" check = Check(check_type=check_type, match_type=match_type, @@ -325,7 +330,7 @@ def exit_handler(code): check_keyword = check_match.group(2) check_expression = check_match.group(3) - if not (args.strict_whitespace and args.match_full_lines): + if not strict_mode: check_expression = check_expression.strip(' ') if re.search(r"\{\{.*\}\}", check_expression): diff --git a/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/03_negative_regex_substring_begin/filecheck.check b/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/03_negative_regex_substring_begin/filecheck.check new file mode 100644 index 0000000..7766435 --- /dev/null +++ b/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/03_negative_regex_substring_begin/filecheck.check @@ -0,0 +1 @@ +CHECK:Substring2{{.*}}Substring3 diff --git a/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/03_negative_regex_substring_begin/filecheck.input b/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/03_negative_regex_substring_begin/filecheck.input new file mode 100644 index 0000000..ebd7468 --- /dev/null +++ b/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/03_negative_regex_substring_begin/filecheck.input @@ -0,0 +1 @@ +Substring1 Substring2 Substring3 \ No newline at end of file diff --git a/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/03_negative_regex_substring_begin/sample.itest b/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/03_negative_regex_substring_begin/sample.itest new file mode 100644 index 0000000..3d379eb --- /dev/null +++ b/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/03_negative_regex_substring_begin/sample.itest @@ -0,0 +1,7 @@ +RUN: %cat "%S/filecheck.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" --match-full-lines --strict-whitespace +CHECK:{{.*}}filecheck.check:1:7: error: CHECK: expected string not found in input +CHECK:CHECK:Substring2{{.*}}Substring3 +CHECK: ^ +CHECK::1:1: note: scanning from here +CHECK:Substring1 Substring2 Substring3 +CHECK:^ diff --git a/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/04_negative_regex_substring_end/filecheck.check b/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/04_negative_regex_substring_end/filecheck.check new file mode 100644 index 0000000..e54fd97 --- /dev/null +++ b/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/04_negative_regex_substring_end/filecheck.check @@ -0,0 +1 @@ +CHECK:Substring1{{.*}}Substring2 diff --git a/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/04_negative_regex_substring_end/filecheck.input b/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/04_negative_regex_substring_end/filecheck.input new file mode 100644 index 0000000..ebd7468 --- /dev/null +++ b/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/04_negative_regex_substring_end/filecheck.input @@ -0,0 +1 @@ +Substring1 Substring2 Substring3 \ No newline at end of file diff --git a/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/04_negative_regex_substring_end/sample.itest b/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/04_negative_regex_substring_end/sample.itest new file mode 100644 index 0000000..11a764a --- /dev/null +++ b/tests/integration/tests/options/--match-full-lines/CHECK/02_when_strict_whitespace_is_also_specified/04_negative_regex_substring_end/sample.itest @@ -0,0 +1,7 @@ +RUN: %cat "%S/filecheck.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" --match-full-lines --strict-whitespace +CHECK:{{.*}}filecheck.check:1:7: error: CHECK: expected string not found in input +CHECK:CHECK:Substring1{{.*}}Substring2 +CHECK: ^ +CHECK::1:1: note: scanning from here +CHECK:Substring1 Substring2 Substring3 +CHECK:^