2
0
Fork 0
mirror of https://github.com/fish-shell/fish-shell synced 2025-01-16 06:54:03 +00:00

Update littlecheck to escape output

This commit is contained in:
Fabian Homborg 2020-04-26 13:51:34 +02:00
parent ad677d388c
commit 34a82dbff9

View file

@ -70,6 +70,34 @@ def output(*args):
print("".join(args) + "\n") 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): class CheckerError(Exception):
"""Exception subclass for check line parsing. """Exception subclass for check line parsing.
@ -248,21 +276,24 @@ 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) before.append(line)
elif line.is_empty_space(): elif line.is_empty_space():
# Skip all whitespace input lines. # Skip all whitespace input lines.
lineq.pop() lineq.pop()
else: else:
# Failed to match. # Failed to match.
lineq.pop() lineq.pop()
line.text = escape_string(line.text.strip()) + "\n"
# Add context, ignoring empty lines. # Add context, ignoring empty lines.
return TestFailure( return TestFailure(
line, line,
check, check,
self, self,
before=before, before=[escape_string(line.text.strip()) + "\n" for line in before],
after=[ 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. # Drain empties.