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
39 changes: 26 additions & 13 deletions src/FileCheck
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CheckType(Enum):
CHECK_EMPTY = 3


Check = namedtuple("Check", "check_type match_type expression source_line start_index")
Check = namedtuple("Check", "check_type match_type expression source_line check_line_idx start_index")


def dump_check(check):
Expand All @@ -29,6 +29,7 @@ def dump_check(check):
print("\tmatch_type: {}".format(check.match_type))
print("\texpression: {}".format(check.expression))
print("\tsource_line: {}".format(check.source_line))
print("\tcheck_line_idx: {}".format(check.check_line_idx))
print("\tstart_index: {}".format(check.start_index))


Expand All @@ -53,7 +54,7 @@ if os.path.getsize(check_file) == 0:

checks = []
with open(check_file) as f:
for line in f:
for line_idx, line in enumerate(f):
line = line.rstrip()
check_match = re.search('; CHECK: (.*)', line)
if check_match:
Expand All @@ -73,6 +74,7 @@ with open(check_file) as f:
match_type=match_type,
expression=check_expression,
source_line=line,
check_line_idx=line_idx,
start_index=check_match.start(1))

checks.append(check)
Expand All @@ -96,6 +98,7 @@ with open(check_file) as f:
match_type=match_type,
expression=check_expression,
source_line=line,
check_line_idx=line_idx,
start_index=check_match.start(1))

checks.append(check)
Expand All @@ -107,6 +110,7 @@ with open(check_file) as f:
match_type=MatchType.SUBSTRING,
expression=None,
source_line=line,
check_line_idx=line_idx,
start_index=-1)

if len(checks) == 0:
Expand All @@ -120,8 +124,6 @@ with open(check_file) as f:

check_iterator = iter(checks)

line_counter = 0

current_check = None
try:
current_check = next(check_iterator)
Expand All @@ -131,18 +133,23 @@ except StopIteration:
exit(2)

current_line = None
first_line = None
current_line_number = 0
line_counter = 0

for line in sys.stdin:
if line_counter == 0:
first_line = line.rstrip()
line_counter = line_counter + 1

current_line = line
current_line_number += 1

line_counter = 1

if current_check.check_type == CheckType.CHECK_EMPTY:
if line != '\n':
assert 0, "Not implemented"

if current_check.check_type == CheckType.CHECK:
elif current_check.check_type == CheckType.CHECK:
if current_check.match_type == MatchType.SUBSTRING:
line = re.sub("\\s+", ' ', line).strip()

Expand All @@ -153,7 +160,7 @@ for line in sys.stdin:
if not re.search(current_check.expression, line):
continue

if current_check.check_type == CheckType.CHECK_NOT:
elif current_check.check_type == CheckType.CHECK_NOT:
if current_check.match_type == MatchType.SUBSTRING:
line = re.sub("\\s+", ' ', line).strip()

Expand All @@ -180,21 +187,25 @@ if current_check.check_type == CheckType.CHECK_EMPTY:
if current_check.check_type == CheckType.CHECK:
if current_check.match_type == MatchType.SUBSTRING:
print("{}:{}:{}: error: CHECK: expected string not found in input"
.format(check_file, line_counter, current_check.start_index + 1))
.format(check_file,
current_check.check_line_idx + 1,
current_check.start_index + 1))

print(current_check.source_line.rstrip())
print("^".rjust(current_check.start_index + 1))
print("<stdin>:?:?: note: scanning from here")
print(current_line)
print(first_line)
print("^")
print("<stdin>:?:?: note: possible intended match here")
print("TODO")
print(" ^")
exit(2)
exit(1)

if current_check.match_type == MatchType.REGEX:
print("{}:{}:{}: error: CHECK: expected string not found in input"
.format(check_file, line_counter, current_check.start_index + 1))
.format(check_file,
current_check.check_line_idx + 1,
current_check.start_index + 1))

print(current_check.source_line.rstrip())
print(" ^")
Expand All @@ -207,7 +218,9 @@ if current_check.check_type == CheckType.CHECK_NOT:
if (current_check.match_type == MatchType.SUBSTRING or
current_check.match_type == MatchType.REGEX):
print("{}:{}:{}: error: CHECK-NOT: excluded string found in input"
.format(check_file, line_counter, current_check.start_index + 1))
.format(check_file,
current_check.check_line_idx + 1,
current_check.start_index + 1))

print(current_check.source_line.rstrip())
print("^".rjust(current_check.start_index + 1))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
; RUN: cat %S/filecheck.input | (%FILECHECK_EXEC %S/filecheck.check 2>&1 || true) | %FILECHECK_TESTER_EXEC %s
; RUN: cat %S/filecheck.input | (%FILECHECK_EXEC %S/filecheck.check 2>&1; test $? = 1) | %FILECHECK_TESTER_EXEC %s --match-full-lines
; CHECK: {{^.*}}FileCheck{{$}}
; CHECK {{.*}}filecheck.check:1:.*: error: CHECK: expected string not found in input{{$}}
; CHECK {{^}}; CHECK: foo{{$}}
; CHECK {{^}} ^{{$}}
; CHECK {{^}}<stdin>:.*:.*: note: scanning from here{{$}}
; CHECK {{^}}hello{{$}}
; CHECK {{^}}^{{$}}
; CHECK {{^}}<stdin>:.*:.*: note: possible intended match here{{$}}
; CHECK {{^}}hello{{$}}
; CHECK: {{^}} ^{{$}}
; CHECK-EMPTY
; CHECK-NEXT: {{.*filecheck.check:1:.*: error: CHECK: expected string not found in input$}}
; CHECK-NEXT: {{^}}; CHECK: foo{{$}}
; CHECK-NEXT: {{^}} ^{{$}}
; CHECK-NEXT: {{^<stdin>:.*:.*: note: scanning from here$}}
; CHECK-NEXT: hello1
; CHECK-NEXT: ^
; CHECK-NEXT: {{^<stdin>:.*:.*: note: possible intended match here$}}
; CHECK: {{^.*$}}
; CHECK: ^
; CHECK-EMPTY: