Skip to content

Commit

Permalink
add --match-full-lines flag
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLydike committed Jul 1, 2024
1 parent 212508b commit 1475b6a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ repos:
hooks:
- id: check-yaml
- id: end-of-file-fixer
exclude: "tests/filecheck/match-full-line.test"
- id: trailing-whitespace
exclude: "tests/filecheck"
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.2.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ There are some features that are left out for now (e.g. [pseudo-numeric variable
- [X] `--comment-prefixes`
- [ ] `--allow-unused-prefixes`
- [X] `--input-file`
- [ ] `--match-full-lines`
- [X] `--match-full-lines`
- [X] `--strict-whitespace` (Kinda? Seems to be working.)
- [ ] `--ignore-case`
- [ ] `--implicit-check-not`
Expand Down
12 changes: 12 additions & 0 deletions filecheck/finput.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,15 @@ def skip_to_end_of_line(self):
return
next_newline = self.content.find("\n", self.pos)
self.move_to(next_newline)

def is_end_of_line(self) -> bool:
"""
Check if line ending or EOF has been reached
"""
# line ending check
if self.content.startswith("\n", self.pos):
return True
# eof check
if self.pos == len(self.content) - 1:
return True
return False
18 changes: 10 additions & 8 deletions filecheck/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
usage: filecheck FLAGS check-file
FLAGS:
--input-file <file> : Specify an input file, default is stdin (-)
--check-prefix <prefix> : Check line prefix (default is CHECK)
--strict-whitespace : Don't ignore indentation
--comment-prefixes <a>,<b>,<c> : Ignore lines starting with these prefixes, even if
they contain check lines (default RUN,COM)
--enable-var-scope : Enables scope for regex variables.
Variables not starting with $ are deleted after
each CHECK-LABEL match.
--input-file <file> : Specify an input file, default is stdin (-)
--check-prefix <prefix> : Check line prefix (default is CHECK)
--strict-whitespace : Don't ignore indentation
--comment-prefixes <a>,<b>,<c> : Ignore lines starting with these prefixes, even if
they contain check lines (default RUN,COM)
--enable-var-scope : Enables scope for regex variables. Variables not
starting with $ are deleted after each CHECK-LABEL
match.
--match-full-lines : Expect every check line to match the whole line.
ARGUMENTS:
check-file : The file from which the check lines are to be read
Expand Down
3 changes: 3 additions & 0 deletions filecheck/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def _post_check(self, op: CheckOp):
if self.ctx.negative_matches_stack:
self.ctx.negative_matches_start = None
self.ctx.negative_matches_stack = []
elif self.opts.match_full_lines:
if not self.file.is_end_of_line():
raise CheckError("Didn't match whole line")

def check_dag(self, op: CheckOp) -> None:
raise NotImplementedError()
Expand Down
1 change: 1 addition & 0 deletions filecheck/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Options:
check_prefix: str = "CHECK"
strict_whitespace: bool = False
enable_var_scope: bool = False
match_full_lines: bool = False
comment_prefixes: list[str] = "COM,RUN" # type: ignore[reportAssignmentType]

def __post_init__(self):
Expand Down
19 changes: 19 additions & 0 deletions tests/filecheck/match-full-line.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: ./strip-comments.sh %s | filecheck %s --match-full-lines

label_a:
// CHECK-LABEL: label_a:
test 1
// CHECK-NEXT: test 1
test 2
// CHECK: test 1 2 3
test 1 2 3

label_b:
// CHECK-LABEL: label_b:
test 100
// CHECK-NEXT: test [[ARG:\d+]]
test 1 2 100
// CHECK-NEXT: test 1 2 [[ARG]]
test "very_long_arg_string"
// CHECK-NEXT: test "{{[a-z_]+}}"
// this file has no newline at the end of it on purpose.

0 comments on commit 1475b6a

Please sign in to comment.