From e5760771c8806942f676ac002d0b2207557fa878 Mon Sep 17 00:00:00 2001 From: Stanislav Pankevich Date: Wed, 20 Nov 2019 21:04:16 +0100 Subject: [PATCH] Feature: initial options/--strict-whitespace --- src/FileCheck | 14 ++++++++++++-- .../02-positive_match/filecheck.check | 1 + .../02-positive_match/filecheck.input | 1 + .../02-positive_match/sample.itest | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tests/integration/tests/options/--strict-whitespace/02-positive_match/filecheck.check create mode 100644 tests/integration/tests/options/--strict-whitespace/02-positive_match/filecheck.input create mode 100644 tests/integration/tests/options/--strict-whitespace/02-positive_match/sample.itest diff --git a/src/FileCheck b/src/FileCheck index a030e90..7ef1819 100755 --- a/src/FileCheck +++ b/src/FileCheck @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import argparse import os import re import sys @@ -57,6 +58,13 @@ if os.path.getsize(check_file) == 0: print("error: no check strings found with prefix 'CHECK:'", file=sys.stderr) exit(2) +parser = argparse.ArgumentParser() + +parser.add_argument('check_file_arg', type=str, help='TODO') +parser.add_argument('--strict-whitespace', action='store_true', help='TODO') + +args = parser.parse_args() + checks = [] with open(check_file) as f: for line_idx, line in enumerate(f): @@ -73,7 +81,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, match_type=match_type, @@ -154,7 +163,8 @@ for line_idx, line in enumerate(sys.stdin): elif current_check.check_type == CheckType.CHECK: 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 not in line: continue diff --git a/tests/integration/tests/options/--strict-whitespace/02-positive_match/filecheck.check b/tests/integration/tests/options/--strict-whitespace/02-positive_match/filecheck.check new file mode 100644 index 0000000..477cd33 --- /dev/null +++ b/tests/integration/tests/options/--strict-whitespace/02-positive_match/filecheck.check @@ -0,0 +1 @@ +; CHECK: hello world hello world diff --git a/tests/integration/tests/options/--strict-whitespace/02-positive_match/filecheck.input b/tests/integration/tests/options/--strict-whitespace/02-positive_match/filecheck.input new file mode 100644 index 0000000..2e126aa --- /dev/null +++ b/tests/integration/tests/options/--strict-whitespace/02-positive_match/filecheck.input @@ -0,0 +1 @@ +hello world hello world diff --git a/tests/integration/tests/options/--strict-whitespace/02-positive_match/sample.itest b/tests/integration/tests/options/--strict-whitespace/02-positive_match/sample.itest new file mode 100644 index 0000000..54e47f5 --- /dev/null +++ b/tests/integration/tests/options/--strict-whitespace/02-positive_match/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 --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