summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorTom Soulanille <soul@prama.com>2015-07-23 12:05:30 -0700
committerDamien George <damien.p.george@gmail.com>2015-07-26 15:23:11 +0100
commit3dd0b69e467fd89e5113dbc5ee43f33282a66c91 (patch)
tree24ea8fa66bf9f4e58947f5bbd4d85a0eb2c7e6bc
parent7d588b0c7c9698d23b1e5e7b54e0e2094ad8f464 (diff)
downloadmicropython-3dd0b69e467fd89e5113dbc5ee43f33282a66c91.tar.gz
micropython-3dd0b69e467fd89e5113dbc5ee43f33282a66c91.zip
run-tests: Use PTY when running REPL tests.
-rw-r--r--tests/cmdline/repl_cont.py.exp6
-rwxr-xr-xtests/run-tests40
2 files changed, 36 insertions, 10 deletions
diff --git a/tests/cmdline/repl_cont.py.exp b/tests/cmdline/repl_cont.py.exp
index 2405e601cb..b24e67017d 100644
--- a/tests/cmdline/repl_cont.py.exp
+++ b/tests/cmdline/repl_cont.py.exp
@@ -1,6 +1,6 @@
Micro Python \.\+ linux version
>>> # check REPL allows to continue input
->>> 1 \
+>>> 1 \\\\
... + 2
3
>>> 'abc'
@@ -9,10 +9,10 @@ Micro Python \.\+ linux version
'abc'
>>> '''abc
... def'''
-'abc\ndef'
+'abc\\\\ndef'
>>> """ABC
... DEF"""
-'ABC\nDEF'
+'ABC\\\\nDEF'
>>> print(
... 1 + 2)
3
diff --git a/tests/run-tests b/tests/run-tests
index b4baff2b83..e65c1d2612 100755
--- a/tests/run-tests
+++ b/tests/run-tests
@@ -42,9 +42,33 @@ def run_micropython(pyb, args, test_file):
# run the test, possibly with redirected input
try:
if test_file.startswith('cmdline/repl_'):
- f = open(test_file, 'rb')
- output_mupy = subprocess.check_output(args, stdin=f)
- f.close()
+ # Need to use a PTY to test command line editing
+ import pty
+ 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:
output_mupy = subprocess.check_output(args + [test_file])
except subprocess.CalledProcessError:
@@ -64,6 +88,9 @@ def run_micropython(pyb, args, test_file):
cs.append('\\' + c)
else:
cs.append(c)
+ # accept carriage-return(s) before final newline
+ if cs[-1] == '\n':
+ cs[-1] = '\r*\n'
return bytes(''.join(cs), 'utf8')
# convert parts of the output that are not stable across runs
@@ -96,6 +123,9 @@ def run_micropython(pyb, args, test_file):
# a regex
if lines_exp[i][1].match(lines_mupy[i_mupy]):
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
if i_mupy >= len(lines_mupy):
break
@@ -133,10 +163,6 @@ def run_tests(pyb, tests, args):
if native == b'CRASH':
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
if os.getenv('TRAVIS') == 'true':
skip_tests.add('basics/memoryerror.py')