mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Update littlecheck to escape output
This commit is contained in:
parent
ad677d388c
commit
34a82dbff9
1 changed files with 34 additions and 3 deletions
|
@ -70,6 +70,34 @@ def output(*args):
|
|||
print("".join(args) + "\n")
|
||||
|
||||
|
||||
import unicodedata
|
||||
|
||||
|
||||
def esc(m):
|
||||
map = {
|
||||
"\n": "\\n",
|
||||
"\\": "\\\\",
|
||||
"'": "\\'",
|
||||
'"': '\\"',
|
||||
"\a": "\\a",
|
||||
"\b": "\\b",
|
||||
"\f": "\\f",
|
||||
"\r": "\\r",
|
||||
"\t": "\\t",
|
||||
"\v": "\\v",
|
||||
}
|
||||
if m in map:
|
||||
return map(m)
|
||||
if unicodedata.category(m)[0] == "C":
|
||||
return "\\x{:02x}".format(ord(m))
|
||||
else:
|
||||
return m
|
||||
|
||||
|
||||
def escape_string(s):
|
||||
return "".join(esc(ch) for ch in s)
|
||||
|
||||
|
||||
class CheckerError(Exception):
|
||||
"""Exception subclass for check line parsing.
|
||||
|
||||
|
@ -248,21 +276,24 @@ class TestRun(object):
|
|||
# This line matched this checker, continue on.
|
||||
lineq.pop()
|
||||
checkq.pop()
|
||||
before.append(line.text)
|
||||
before.append(line)
|
||||
elif line.is_empty_space():
|
||||
# Skip all whitespace input lines.
|
||||
lineq.pop()
|
||||
else:
|
||||
# Failed to match.
|
||||
lineq.pop()
|
||||
line.text = escape_string(line.text.strip()) + "\n"
|
||||
# Add context, ignoring empty lines.
|
||||
return TestFailure(
|
||||
line,
|
||||
check,
|
||||
self,
|
||||
before=before,
|
||||
before=[escape_string(line.text.strip()) + "\n" for line in before],
|
||||
after=[
|
||||
line.text for line in lineq[::-1] if not line.is_empty_space()
|
||||
escape_string(line.text.strip()) + "\n"
|
||||
for line in lineq[::-1]
|
||||
if not line.is_empty_space()
|
||||
],
|
||||
)
|
||||
# Drain empties.
|
||||
|
|
Loading…
Reference in a new issue