mirror of
https://github.com/kanaka/mal.git
synced 2024-10-26 22:28:26 +03:00
Merge pull request #510 from bjh21/bjh21-runtest-simpler
Simplify runtest.py's input handling
This commit is contained in:
commit
805ae7b280
29
runtest.py
29
runtest.py
@ -28,8 +28,7 @@ def log(data, end='\n'):
|
||||
print(data, end=end)
|
||||
sys.stdout.flush()
|
||||
|
||||
# TODO: do we need to support '\n' too
|
||||
sep = "\r\n"
|
||||
sep = "\n"
|
||||
rundir = None
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
@ -127,18 +126,7 @@ class Runner():
|
||||
#print("new_data: '%s'" % new_data)
|
||||
debug(new_data)
|
||||
# Perform newline cleanup
|
||||
if self.no_pty:
|
||||
self.buf += new_data.replace("\n", "\r\n")
|
||||
else:
|
||||
self.buf += new_data
|
||||
self.buf = self.buf.replace("\r\r", "\r")
|
||||
# Remove ANSI codes generally
|
||||
#ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')
|
||||
# Remove rustyline ANSI CSI codes:
|
||||
# - [6C - CR + cursor forward
|
||||
# - [6K - CR + erase in line
|
||||
ansi_escape = re.compile(r'\r\x1B\[[0-9]*[CK]')
|
||||
self.buf = ansi_escape.sub('', self.buf)
|
||||
self.buf += new_data.replace("\r", "")
|
||||
for prompt in prompts:
|
||||
regexp = re.compile(prompt)
|
||||
match = regexp.search(self.buf)
|
||||
@ -147,7 +135,7 @@ class Runner():
|
||||
buf = self.buf[0:match.start()]
|
||||
self.buf = self.buf[end:]
|
||||
self.last_prompt = prompt
|
||||
return buf.replace("^M", "\r")
|
||||
return buf
|
||||
return None
|
||||
|
||||
def writeline(self, str):
|
||||
@ -223,10 +211,10 @@ class TestReader:
|
||||
break
|
||||
if self.ret != None: break
|
||||
|
||||
if self.out[-2:] == sep and not self.ret:
|
||||
if self.out[-1:] == sep and not self.ret:
|
||||
# If there is no return value, output should not end in
|
||||
# separator
|
||||
self.out = self.out[0:-2]
|
||||
self.out = self.out[0:-1]
|
||||
return self.form
|
||||
|
||||
args = parser.parse_args(sys.argv[1:])
|
||||
@ -296,11 +284,8 @@ while t.next():
|
||||
# The repeated form is to get around an occasional OS X issue
|
||||
# where the form is repeated.
|
||||
# https://github.com/kanaka/mal/issues/30
|
||||
expects = ["%s%s%s%s" % (re.escape(t.form), sep,
|
||||
t.out, re.escape(t.ret)),
|
||||
"%s%s%s%s%s%s" % (re.escape(t.form), sep,
|
||||
re.escape(t.form), sep,
|
||||
t.out, re.escape(t.ret))]
|
||||
expects = [".*%s%s%s" % (sep, t.out, re.escape(t.ret)),
|
||||
".*%s.*%s%s%s" % (sep, sep, t.out, re.escape(t.ret))]
|
||||
|
||||
r.writeline(t.form)
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user