run-tests: Use PTY when running REPL tests.

This commit is contained in:
Tom Soulanille 2015-07-23 12:05:30 -07:00 committed by Damien George
parent 7d588b0c7c
commit 3dd0b69e46
2 changed files with 36 additions and 10 deletions

View File

@ -1,6 +1,6 @@
Micro Python \.\+ linux version Micro Python \.\+ linux version
>>> # check REPL allows to continue input >>> # check REPL allows to continue input
>>> 1 \ >>> 1 \\\\
... + 2 ... + 2
3 3
>>> 'abc' >>> 'abc'
@ -9,10 +9,10 @@ Micro Python \.\+ linux version
'abc' 'abc'
>>> '''abc >>> '''abc
... def''' ... def'''
'abc\ndef' 'abc\\\\ndef'
>>> """ABC >>> """ABC
... DEF""" ... DEF"""
'ABC\nDEF' 'ABC\\\\nDEF'
>>> print( >>> print(
... 1 + 2) ... 1 + 2)
3 3

View File

@ -42,9 +42,33 @@ def run_micropython(pyb, args, test_file):
# run the test, possibly with redirected input # run the test, possibly with redirected input
try: try:
if test_file.startswith('cmdline/repl_'): if test_file.startswith('cmdline/repl_'):
f = open(test_file, 'rb') # Need to use a PTY to test command line editing
output_mupy = subprocess.check_output(args, stdin=f) import pty
f.close() import select
def get():
rv = b''
while True:
ready = select.select([master], [], [], 0.02)
if ready[0] == [master]:
rv += os.read(master, 1024)
else:
return rv
def send_get(what):
os.write(master, what)
return get()
with open(test_file, 'rb') as f:
# instead of: output_mupy = subprocess.check_output(args, stdin=f)
master, slave = pty.openpty()
p = subprocess.Popen(args, stdin=slave, stdout=slave,
stderr=subprocess.STDOUT, bufsize=0)
banner = get()
output_mupy = banner + b''.join(send_get(line) for line in f)
p.kill()
os.close(master)
os.close(slave)
else: else:
output_mupy = subprocess.check_output(args + [test_file]) output_mupy = subprocess.check_output(args + [test_file])
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
@ -64,6 +88,9 @@ def run_micropython(pyb, args, test_file):
cs.append('\\' + c) cs.append('\\' + c)
else: else:
cs.append(c) cs.append(c)
# accept carriage-return(s) before final newline
if cs[-1] == '\n':
cs[-1] = '\r*\n'
return bytes(''.join(cs), 'utf8') return bytes(''.join(cs), 'utf8')
# convert parts of the output that are not stable across runs # convert parts of the output that are not stable across runs
@ -96,6 +123,9 @@ def run_micropython(pyb, args, test_file):
# a regex # a regex
if lines_exp[i][1].match(lines_mupy[i_mupy]): if lines_exp[i][1].match(lines_mupy[i_mupy]):
lines_mupy[i_mupy] = lines_exp[i][0] lines_mupy[i_mupy] = lines_exp[i][0]
else:
#print("don't match: %r %s" % (lines_exp[i][1], lines_mupy[i_mupy])) # DEBUG
pass
i_mupy += 1 i_mupy += 1
if i_mupy >= len(lines_mupy): if i_mupy >= len(lines_mupy):
break break
@ -133,10 +163,6 @@ def run_tests(pyb, tests, args):
if native == b'CRASH': if native == b'CRASH':
skip_native = True skip_native = True
# These tests no longer work; TODO change them or remove them
skip_tests.add('cmdline/repl_basic.py')
skip_tests.add('cmdline/repl_cont.py')
# Some tests shouldn't be run under Travis CI # Some tests shouldn't be run under Travis CI
if os.getenv('TRAVIS') == 'true': if os.getenv('TRAVIS') == 'true':
skip_tests.add('basics/memoryerror.py') skip_tests.add('basics/memoryerror.py')