-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from AntonLydike/anton/add-empty-capture-warning
core: Warn on empty captures instead of throwing errors
- Loading branch information
Showing
11 changed files
with
152 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import sys | ||
from enum import Flag, auto | ||
|
||
COLOR_SUPPORT = hasattr(sys.stdout, "isatty") and sys.stdout.isatty() | ||
|
||
|
||
class FMT(Flag): | ||
RED = auto() | ||
BLUE = auto() | ||
YELLOW = auto() | ||
GREEN = auto() | ||
ORANGE = auto() | ||
BOLD = auto() | ||
GRAY = auto() | ||
UNDERLINE = auto() | ||
RESET = auto() | ||
|
||
def __str__(self) -> str: | ||
if not COLOR_SUPPORT: | ||
return "" | ||
fmt_str: list[str] = [] | ||
|
||
if FMT.RED in self: | ||
fmt_str.append("\033[31m") | ||
if FMT.ORANGE in self: | ||
fmt_str.append("\033[33m") | ||
if FMT.GRAY in self: | ||
fmt_str.append("\033[37m") | ||
if FMT.GREEN in self: | ||
fmt_str.append("\033[32m") | ||
if FMT.BLUE in self: | ||
fmt_str.append("\033[34m") | ||
if FMT.YELLOW in self: | ||
fmt_str.append("\033[93m") | ||
if FMT.BOLD in self: | ||
fmt_str.append("\033[1m") | ||
if FMT.RESET in self: | ||
fmt_str.append("\033[0m") | ||
if FMT.UNDERLINE in self: | ||
fmt_str.append("\033[4m") | ||
|
||
return "".join(fmt_str) | ||
|
||
|
||
WARN = FMT.ORANGE | FMT.UNDERLINE | ||
ERR = FMT.RED | FMT.BOLD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import sys | ||
|
||
from filecheck.colors import WARN, FMT | ||
from filecheck.ops import CheckOp | ||
from filecheck.options import Options | ||
|
||
|
||
def warn( | ||
msg: str, | ||
*, | ||
op: CheckOp | None = None, | ||
input_loc: str | None = None, | ||
opts: Options, | ||
): | ||
print(f"{WARN}Warning: {msg}{FMT.RESET}", end="", file=sys.stderr) | ||
if input_loc: | ||
print(f" at {input_loc}", end="", file=sys.stderr) | ||
print("", file=sys.stderr) | ||
if op: | ||
print(op.source_repr(opts), file=sys.stderr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// RUN: strip-comments.sh %s | exfail filecheck %s --reject-empty-vars | filecheck %s --check-prefix DIAG | ||
|
||
test 123 | ||
// CHECK: test [[VAL:]] | ||
// CHECK-SAME: [[VAL]] | ||
|
||
// the warning printed: | ||
// DIAG: Warning: Empty pattern capture | ||
// DIAG-NEXT: Check rule at {{.*}}tests/filecheck/diagnostics/reject-empty-vars.test:4 | ||
// DIAG-NEXT: CHECK: test [[VAL:]] | ||
// the error printed: | ||
// DIAG-NEXT: tests/filecheck/diagnostics/reject-empty-vars.test:4: error: Empty value captured for variable "VAL" | ||
// DIAG-NEXT: Matching at <stdin>:1:6 | ||
// DIAG-NEXT: test 123 | ||
// DIAG-NEXT: {{ }}^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters