Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: initial options/--strict-whitespace #16

Merged
merged 1 commit into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/FileCheck
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

import argparse
import os
import re
import sys
Expand Down Expand Up @@ -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):
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
; CHECK: hello world hello world
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world hello world
Original file line number Diff line number Diff line change
@@ -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: {{^<stdin>:.*:.*: 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