Skip to content

Commit

Permalink
Fix issue with windows newlines not being normalised (fixes #27) (#30)
Browse files Browse the repository at this point in the history
This PR fixes #27 

It also contains a small additonal fix for #29, where `_` and `-` are
also not allowed before a check prefix.
  • Loading branch information
AntonLydike authored Jul 30, 2024
1 parent ee8526c commit 237cd62
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion filecheck/finput.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class FInput:
range: InputRange = field(default_factory=lambda: InputRange(0, sys.maxsize))
ranges: list[InputRange] = field(default_factory=list)

@staticmethod
def canonicalize_line_ends(text: str) -> str:
return text.replace("\r\n", "\n")

@staticmethod
def from_opts(opts: Options) -> FInput:
"""
Expand All @@ -135,7 +139,7 @@ def from_opts(opts: Options) -> FInput:
f = sys.stdin
else:
f = open(opts.input_file, "r")
return FInput(opts.input_file, f.read())
return FInput(opts.input_file, FInput.canonicalize_line_ends(f.read()))

def advance_by(self, dist: int):
"""
Expand Down
2 changes: 1 addition & 1 deletion filecheck/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
def pattern_for_opts(opts: Options) -> tuple[re.Pattern[str], re.Pattern[str]]:
prefixes = f"({'|'.join(map(re.escape, opts.check_prefixes))})"
return re.compile(
r"(^|[^a-zA-Z])"
r"(^|[^a-zA-Z-_])"
+ prefixes
+ r"(-(DAG|COUNT-\d+|NOT|EMPTY|NEXT|SAME|LABEL))?(\{LITERAL})?:\s?([^\n]*)\n?"
), re.compile(f"({'|'.join(map(re.escape, opts.comment_prefixes))}).*{prefixes}")
Expand Down
5 changes: 5 additions & 0 deletions tests/filecheck/windows_line_endings.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: echo -e "1\r\n2\r\n\r\n3" | filecheck %s
CHECK: 1
CHECK-NEXT: 2
CHECK-EMPTY:
CHECK-NEXT: 3

0 comments on commit 237cd62

Please sign in to comment.