mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 14:03:58 +00:00
Update littlecheck
Now featuring Context display on error, which should make it a bit easier to make out any problems.
This commit is contained in:
parent
e49b4df562
commit
edad6aa607
1 changed files with 32 additions and 2 deletions
|
@ -6,6 +6,7 @@ from __future__ import unicode_literals
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
from collections import deque
|
||||||
import datetime
|
import datetime
|
||||||
import io
|
import io
|
||||||
import re
|
import re
|
||||||
|
@ -33,6 +34,8 @@ class Config(object):
|
||||||
self.progress = False
|
self.progress = False
|
||||||
# How many after lines to print
|
# How many after lines to print
|
||||||
self.after = 5
|
self.after = 5
|
||||||
|
# How many before lines to print
|
||||||
|
self.before = 5
|
||||||
|
|
||||||
def colors(self):
|
def colors(self):
|
||||||
""" Return a dictionary mapping color names to ANSI escapes """
|
""" Return a dictionary mapping color names to ANSI escapes """
|
||||||
|
@ -118,13 +121,14 @@ class RunCmd(object):
|
||||||
|
|
||||||
|
|
||||||
class TestFailure(object):
|
class TestFailure(object):
|
||||||
def __init__(self, line, check, testrun, after=None):
|
def __init__(self, line, check, testrun, before=None, after=None):
|
||||||
self.line = line
|
self.line = line
|
||||||
self.check = check
|
self.check = check
|
||||||
self.testrun = testrun
|
self.testrun = testrun
|
||||||
self.error_annotation_line = None
|
self.error_annotation_line = None
|
||||||
# The output that comes *after* the failure.
|
# The output that comes *after* the failure.
|
||||||
self.after = after
|
self.after = after
|
||||||
|
self.before = before
|
||||||
|
|
||||||
def message(self):
|
def message(self):
|
||||||
afterlines = self.testrun.config.after
|
afterlines = self.testrun.config.after
|
||||||
|
@ -181,7 +185,15 @@ class TestFailure(object):
|
||||||
" additional output on stderr:{error_annotation_lineno}:",
|
" additional output on stderr:{error_annotation_lineno}:",
|
||||||
" {BOLD}{error_annotation}{RESET}",
|
" {BOLD}{error_annotation}{RESET}",
|
||||||
]
|
]
|
||||||
if self.after:
|
if self.before:
|
||||||
|
fields["before_output"] = " ".join(self.before)
|
||||||
|
fields["additional_output"] = " ".join(self.after[:afterlines])
|
||||||
|
fmtstrs += [
|
||||||
|
" Context:",
|
||||||
|
" {BOLD}{before_output} {RED}{output_line}{RESET} <= does not match '{LIGHTBLUE}{input_line}{RESET}'",
|
||||||
|
" {BOLD}{additional_output}{RESET}",
|
||||||
|
]
|
||||||
|
elif self.after:
|
||||||
fields["additional_output"] = " ".join(self.after[:afterlines])
|
fields["additional_output"] = " ".join(self.after[:afterlines])
|
||||||
fmtstrs += [" additional output:", " {BOLD}{additional_output}{RESET}"]
|
fmtstrs += [" additional output:", " {BOLD}{additional_output}{RESET}"]
|
||||||
fmtstrs += [" when running command:", " {subbed_command}"]
|
fmtstrs += [" when running command:", " {subbed_command}"]
|
||||||
|
@ -227,6 +239,8 @@ class TestRun(object):
|
||||||
# Reverse our lines and checks so we can pop off the end.
|
# Reverse our lines and checks so we can pop off the end.
|
||||||
lineq = lines[::-1]
|
lineq = lines[::-1]
|
||||||
checkq = checks[::-1]
|
checkq = checks[::-1]
|
||||||
|
# We keep the last couple of lines in a deque so we can show context.
|
||||||
|
before = deque(maxlen=self.config.before)
|
||||||
while lineq and checkq:
|
while lineq and checkq:
|
||||||
line = lineq[-1]
|
line = lineq[-1]
|
||||||
check = checkq[-1]
|
check = checkq[-1]
|
||||||
|
@ -234,6 +248,7 @@ class TestRun(object):
|
||||||
# This line matched this checker, continue on.
|
# This line matched this checker, continue on.
|
||||||
lineq.pop()
|
lineq.pop()
|
||||||
checkq.pop()
|
checkq.pop()
|
||||||
|
before.append(line.text)
|
||||||
elif line.is_empty_space():
|
elif line.is_empty_space():
|
||||||
# Skip all whitespace input lines.
|
# Skip all whitespace input lines.
|
||||||
lineq.pop()
|
lineq.pop()
|
||||||
|
@ -245,6 +260,7 @@ class TestRun(object):
|
||||||
line,
|
line,
|
||||||
check,
|
check,
|
||||||
self,
|
self,
|
||||||
|
before=before,
|
||||||
after=[
|
after=[
|
||||||
line.text for line in lineq[::-1] if not line.is_empty_space()
|
line.text for line in lineq[::-1] if not line.is_empty_space()
|
||||||
],
|
],
|
||||||
|
@ -459,6 +475,14 @@ def get_argparse():
|
||||||
action="store",
|
action="store",
|
||||||
default=5,
|
default=5,
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-B",
|
||||||
|
"--before",
|
||||||
|
type=int,
|
||||||
|
help="How many non-empty lines of output before a failure to print (default: 5)",
|
||||||
|
action="store",
|
||||||
|
default=5,
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
@ -474,6 +498,12 @@ def main():
|
||||||
config.progress = args.progress
|
config.progress = args.progress
|
||||||
fields = config.colors()
|
fields = config.colors()
|
||||||
config.after = args.after
|
config.after = args.after
|
||||||
|
config.before = args.before
|
||||||
|
if config.before < 0:
|
||||||
|
raise ValueError("Before must be at least 0")
|
||||||
|
if config.after < 0:
|
||||||
|
raise ValueError("After must be at least 0")
|
||||||
|
|
||||||
for path in args.file:
|
for path in args.file:
|
||||||
fields["path"] = path
|
fields["path"] = path
|
||||||
if config.progress:
|
if config.progress:
|
||||||
|
|
Loading…
Reference in a new issue