Skip to content

Commit

Permalink
Merge pull request #28 from stanislaw/develop-alt
Browse files Browse the repository at this point in the history
Refactoring: canonicalize_whitespace
  • Loading branch information
stanislaw authored Nov 23, 2019
2 parents 5951840 + e13ff7d commit f4086b0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/FileCheck
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ def escape_non_regex_parts(string):

return regex_line


# By default, FileCheck canonicalizes input horizontal whitespace (spaces and
# tabs) which causes it to ignore these differences (a space will match a tab).
# The --strict-whitespace argument disables this behavior.
# https://llvm.org/docs/CommandGuide/FileCheck.html#cmdoption-filecheck-strict-whitespace
def canonicalize_whitespace(input):
output = re.sub("\\s+", ' ', input)
return output


def dump_check(check):
print("check dump")
print("\tcheck_type: {}".format(check.check_type))
Expand Down Expand Up @@ -96,7 +106,7 @@ with open(check_file) as f:
line = line.rstrip()

if not args.strict_whitespace:
line = re.sub("\\s+", ' ', line)
line = canonicalize_whitespace(line)

# CHECK and CHECK-NEXT
strict_whitespace_match = "" if args.strict_whitespace and args.match_full_lines else " ?"
Expand Down Expand Up @@ -193,7 +203,7 @@ stdin_input_iter = enumerate(sys.stdin)
for line_idx, line in stdin_input_iter:
line = line.rstrip()
if not args.strict_whitespace:
line = re.sub("\\s+", ' ', line)
line = canonicalize_whitespace(line)

input_lines.append(line)

Expand Down

0 comments on commit f4086b0

Please sign in to comment.