Skip to content
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
32 changes: 21 additions & 11 deletions filecheck/FileCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,14 @@ def main():
stdin_input_iter = enumerate(sys.stdin)

try:
for line_idx, line in stdin_input_iter:
line_idx, line = next(stdin_input_iter)
except StopIteration:
print("CHECK: FileCheck error: '-' is empty.")
print("FileCheck command line: {}".format(check_file))
exit(2)

try:
while True:
line = line.rstrip()
if not args.strict_whitespace:
line = canonicalize_whitespace(line)
Expand All @@ -319,35 +326,36 @@ def main():
if check_result == CheckResult.PASS:
try:
current_check = next(check_iterator)
current_scan_base = line_idx + 1
except StopIteration:
exit(0)

break
try:
line_idx, line = next(stdin_input_iter)
current_scan_base = line_idx
break
except StopIteration:
raise CheckFailedException()

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

try:
line_idx, line = next(stdin_input_iter)
break
except StopIteration:
raise CheckFailedException()
else:
assert 0
except CheckFailedException:
pass

if not input_lines:
print("CHECK: FileCheck error: '-' is empty.")
print("FileCheck command line: {}".format(check_file))
exit(2)

if current_check.check_type == CheckType.CHECK_EMPTY:
if check_result == CheckResult.PASS:
exit(0)
Expand All @@ -367,6 +375,8 @@ def main():

if current_check.check_type == CheckType.CHECK:
if current_check.match_type == MatchType.SUBSTRING:
assert current_scan_base < len(input_lines)

last_read_line = input_lines[current_scan_base]

print("{}:{}:{}: error: CHECK: expected string not found in input"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
; CHECK: String1
; CHECK: String2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
String1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; RUN: cat %S/filecheck.input | (%FILECHECK_EXEC %S/filecheck.check 2>&1; test $? = 1;) | %FILECHECK_TESTER_EXEC %s --strict-whitespace --match-full-lines
; CHECK:{{^.*}}FileCheck{{(\.py)?$}}
; CHECK:{{^.*}}filecheck.check:2:10: error: CHECK: expected string not found in input{{$}}
; CHECK:; CHECK: String2
; CHECK: ^
; TODO:<stdin>:1:8: note: scanning from here
; TODO:String1
; TODO: ^
; TODO-EMPTY: