diff --git a/src/FileCheck b/src/FileCheck index 7ef1819..e88cc1d 100755 --- a/src/FileCheck +++ b/src/FileCheck @@ -106,7 +106,8 @@ with open(check_file) as f: match_type = MatchType.REGEX check_expression = regex_line else: - check_expression = re.sub("\\s+", ' ', check_expression).strip() + if not args.strict_whitespace: + check_expression = re.sub("\\s+", ' ', check_expression).strip() check = Check(check_type=CheckType.CHECK_NOT, match_type=match_type, @@ -175,7 +176,8 @@ for line_idx, line in enumerate(sys.stdin): elif current_check.check_type == CheckType.CHECK_NOT: if current_check.match_type == MatchType.SUBSTRING: - line = re.sub("\\s+", ' ', line).strip() + if not args.strict_whitespace: + line = re.sub("\\s+", ' ', line).strip() if current_check.expression in line: break @@ -243,6 +245,9 @@ if current_check.check_type == CheckType.CHECK_NOT: if (current_check.match_type == MatchType.SUBSTRING or current_check.match_type == MatchType.REGEX): last_read_line = input_lines[-1] + if not args.strict_whitespace: + last_read_line = re.sub("\\s+", ' ', last_read_line).strip() + print("{}:{}:{}: error: CHECK-NOT: excluded string found in input" .format(check_file, current_check.check_line_idx + 1, diff --git a/tests/integration/tests/options/--strict-whitespace/01_input_has_mixed_spaces_and_tabs/filecheck.check b/tests/integration/tests/options/--strict-whitespace/CHECK/01_input_has_mixed_spaces_and_tabs/filecheck.check similarity index 100% rename from tests/integration/tests/options/--strict-whitespace/01_input_has_mixed_spaces_and_tabs/filecheck.check rename to tests/integration/tests/options/--strict-whitespace/CHECK/01_input_has_mixed_spaces_and_tabs/filecheck.check diff --git a/tests/integration/tests/options/--strict-whitespace/01_input_has_mixed_spaces_and_tabs/filecheck.input b/tests/integration/tests/options/--strict-whitespace/CHECK/01_input_has_mixed_spaces_and_tabs/filecheck.input similarity index 100% rename from tests/integration/tests/options/--strict-whitespace/01_input_has_mixed_spaces_and_tabs/filecheck.input rename to tests/integration/tests/options/--strict-whitespace/CHECK/01_input_has_mixed_spaces_and_tabs/filecheck.input diff --git a/tests/integration/tests/options/--strict-whitespace/01_input_has_mixed_spaces_and_tabs/sample.itest b/tests/integration/tests/options/--strict-whitespace/CHECK/01_input_has_mixed_spaces_and_tabs/sample.itest similarity index 100% rename from tests/integration/tests/options/--strict-whitespace/01_input_has_mixed_spaces_and_tabs/sample.itest rename to tests/integration/tests/options/--strict-whitespace/CHECK/01_input_has_mixed_spaces_and_tabs/sample.itest diff --git a/tests/integration/tests/options/--strict-whitespace/02_check_has_mixed_spaces_and_tabs/filecheck.check b/tests/integration/tests/options/--strict-whitespace/CHECK/02_check_has_mixed_spaces_and_tabs/filecheck.check similarity index 100% rename from tests/integration/tests/options/--strict-whitespace/02_check_has_mixed_spaces_and_tabs/filecheck.check rename to tests/integration/tests/options/--strict-whitespace/CHECK/02_check_has_mixed_spaces_and_tabs/filecheck.check diff --git a/tests/integration/tests/options/--strict-whitespace/02_check_has_mixed_spaces_and_tabs/filecheck.input b/tests/integration/tests/options/--strict-whitespace/CHECK/02_check_has_mixed_spaces_and_tabs/filecheck.input similarity index 100% rename from tests/integration/tests/options/--strict-whitespace/02_check_has_mixed_spaces_and_tabs/filecheck.input rename to tests/integration/tests/options/--strict-whitespace/CHECK/02_check_has_mixed_spaces_and_tabs/filecheck.input diff --git a/tests/integration/tests/options/--strict-whitespace/02_check_has_mixed_spaces_and_tabs/sample.itest b/tests/integration/tests/options/--strict-whitespace/CHECK/02_check_has_mixed_spaces_and_tabs/sample.itest similarity index 100% rename from tests/integration/tests/options/--strict-whitespace/02_check_has_mixed_spaces_and_tabs/sample.itest rename to tests/integration/tests/options/--strict-whitespace/CHECK/02_check_has_mixed_spaces_and_tabs/sample.itest diff --git a/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/01_input_has_mixed_spaces_and_tabs/filecheck.check b/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/01_input_has_mixed_spaces_and_tabs/filecheck.check new file mode 100644 index 0000000..a43cced --- /dev/null +++ b/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/01_input_has_mixed_spaces_and_tabs/filecheck.check @@ -0,0 +1 @@ +; CHECK-NOT: hello world hello world diff --git a/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/01_input_has_mixed_spaces_and_tabs/filecheck.input b/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/01_input_has_mixed_spaces_and_tabs/filecheck.input new file mode 100644 index 0000000..2e126aa --- /dev/null +++ b/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/01_input_has_mixed_spaces_and_tabs/filecheck.input @@ -0,0 +1 @@ +hello world hello world diff --git a/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/01_input_has_mixed_spaces_and_tabs/sample.itest b/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/01_input_has_mixed_spaces_and_tabs/sample.itest new file mode 100644 index 0000000..5444cee --- /dev/null +++ b/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/01_input_has_mixed_spaces_and_tabs/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-prefix=NO_OPTION +; RUN: cat %S/filecheck.input | (%FILECHECK_EXEC %S/filecheck.check --strict-whitespace 2>&1; test $? = 0) | %FILECHECK_TESTER_EXEC %s --match-full-lines -check-prefix=OPTION + +; NO_OPTION:{{^.*}}FileCheck{{$}} +; NO_OPTION:{{^.*}}filecheck.check:1:14: error: CHECK-NOT: excluded string found in input{{$}} +; NO_OPTION:; CHECK-NOT: hello world hello world +; NO_OPTION: ^ +; NO_OPTION:{{^:.:.: note: found here$}} +; NO_OPTION:hello world hello world +; NO_OPTION:^~~~~~~~~~~~~~~~~~~~~~~ +; NO_OPTION-EMPTY: + +; OPTION: {{^.*}}FileCheck{{$}} +; OPTION-EMPTY: diff --git a/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/02_check_has_mixed_spaces_and_tabs/filecheck.check b/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/02_check_has_mixed_spaces_and_tabs/filecheck.check new file mode 100644 index 0000000..0b8daea --- /dev/null +++ b/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/02_check_has_mixed_spaces_and_tabs/filecheck.check @@ -0,0 +1 @@ +; CHECK: hello world hello world diff --git a/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/02_check_has_mixed_spaces_and_tabs/filecheck.input b/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/02_check_has_mixed_spaces_and_tabs/filecheck.input new file mode 100644 index 0000000..235735d --- /dev/null +++ b/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/02_check_has_mixed_spaces_and_tabs/filecheck.input @@ -0,0 +1 @@ +hello world hello world diff --git a/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/02_check_has_mixed_spaces_and_tabs/sample.itest b/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/02_check_has_mixed_spaces_and_tabs/sample.itest new file mode 100644 index 0000000..da30e46 --- /dev/null +++ b/tests/integration/tests/options/--strict-whitespace/CHECK_NOT/02_check_has_mixed_spaces_and_tabs/sample.itest @@ -0,0 +1,15 @@ +; RUN: cat %S/filecheck.input | %FILECHECK_EXEC %S/filecheck.check | %FILECHECK_TESTER_EXEC %s --match-full-lines -check-prefix=NO_OPTION +; RUN: cat %S/filecheck.input | (%FILECHECK_EXEC %S/filecheck.check --strict-whitespace 2>&1; test $? = 1) | %FILECHECK_TESTER_EXEC %s --strict-whitespace --match-full-lines -check-prefix=OPTION + +; NO_OPTION: {{^.*}}FileCheck{{$}} +; NO_OPTION-EMPTY: + +; OPTION:{{^.*}}FileCheck{{$}} +; OPTION:{{^.*}}filecheck.check:1:10: error: CHECK: expected string not found in input{{$}} +; OPTION:; CHECK: hello world hello world +; OPTION: ^ +; OPTION:{{^:.*:.*: note: scanning from here$}} +; OPTION:hello world hello world +; OPTION:^ +; TODO: error: OPTION-EMPTY is not on the line after the previous match +; OPTION-EMPTY