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
56 changes: 52 additions & 4 deletions src/FileCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class CheckType(Enum):

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

def dump_check(check):
print("check dump")
print("\tcheck_type: {}".format(check.check_type))
print("\tmatch_type: {}".format(check.match_type))
print("\texpression: {}".format(check.expression))
print("\tsource_line: {}".format(check.source_line))
print("\tstart_index: {}".format(check.start_index))

# FileCheck always prints its first argument.
print(sys.argv[0])

Expand Down Expand Up @@ -63,18 +71,30 @@ class CheckType(Enum):
start_index=check_match.start(1))

checks.append(check)
continue

check_match = re.search('; CHECK-NOT: (.*)', line)
if check_match:
match_type = MatchType.SUBSTRING

check_expression = check_match.group(1)

regex_line = re.sub(r"\{\{(.*?)\}\}", r"\1", check_expression)

if check_expression != regex_line:
match_type = MatchType.REGEX
check_expression = regex_line
else:
check_expression = re.sub("\\s+", ' ', check_expression).strip()

check = Check(check_type=CheckType.CHECK_NOT,
match_type=MatchType.SUBSTRING,
match_type=match_type,
expression=check_expression,
source_line=line,
start_index=check_match.start(1))

checks.append(check)
continue

check_match = re.search('; CHECK-EMPTY:', line)
if check_match:
Expand All @@ -91,6 +111,7 @@ class CheckType(Enum):
exit(2)

checks.append(check)
continue

check_iterator = iter(checks)

Expand All @@ -103,7 +124,12 @@ class CheckType(Enum):
print("error: no check strings found with prefix 'CHECK:'", file=sys.stderr)
exit(2)

current_line = None
current_line_number = 0
for line in sys.stdin:
current_line = line
current_line_number += 1

line_counter = 1

if current_check.check_type == CheckType.CHECK_EMPTY:
Expand All @@ -117,10 +143,21 @@ class CheckType(Enum):
if current_check.expression not in line:
continue

if current_check.match_type == MatchType.REGEX:
elif current_check.match_type == MatchType.REGEX:
if not re.search(current_check.expression, line):
continue

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

if current_check.expression in line:
break

elif current_check.match_type == MatchType.REGEX:
if re.search(current_check.expression, line):
break

try:
current_check = next(check_iterator)
except StopIteration:
Expand Down Expand Up @@ -156,10 +193,21 @@ class CheckType(Enum):
print(current_check.source_line.rstrip())
print(" ^")
print("<stdin>:?:?: note: scanning from here")
print("TODO")
print(line)
print("^")
exit(1)

# print("foo: {}".format(line == "\n"))
if current_check.check_type == CheckType.CHECK_NOT:
if current_check.match_type == MatchType.SUBSTRING:
print("{}:{}:{}: error: CHECK-NOT: excluded string found in input"
.format(check_file, line_counter, current_check.start_index + 1))

print(current_check.source_line.rstrip())
print("^".rjust(current_check.start_index + 1))
print("<stdin>:?:?: note: found here")
print(current_line)
print("^".ljust(len(current_line), '~'))
exit(1)

if current_check.match_type == MatchType.REGEX:
assert 0, "Not implemented"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
; CHECK-NOT: hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
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
; CHECK: {{^.*}}FileCheck
; CHECK-NEXT: {{^.*}}filecheck.check:1:14: error: CHECK-NOT: excluded string found in input{{$}}
; CHECK-NEXT: {{^}}; CHECK-NOT: hello{{$}}
; CHECK-NEXT: {{^}} ^{{$}}
; CHECK-NEXT: {{^<stdin>:.*:.*: note: found here$}}
; CHECK-NEXT: {{^}}hello{{$}}
; CHECK-NEXT: {{^}}^~~~~{{$}}
; CHECK-EMPTY: