Skip to content

Commit

Permalink
Merge pull request #58 from stanislaw/check-empty-negative
Browse files Browse the repository at this point in the history
CHECK-EMPTY: consistent behavior when followed by normal CHECKS
  • Loading branch information
stanislaw authored Dec 12, 2019
2 parents ee75882 + fec0c0b commit f8871ba
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 25 deletions.
76 changes: 51 additions & 25 deletions filecheck/FileCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
__version__ = '0.0.4'


class CheckFailedException(Exception):
pass


class MatchType(Enum):
SUBSTRING = 1
EXACT_STRING = 2
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
; CHECK: string1
; CHECK-NOT: hello
; CHECK: string2
; CHECK: string3
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
string1
string2
string3
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit f8871ba

Please sign in to comment.