@@ -42,9 +42,33 @@ def run_micropython(pyb, args, test_file):
4242 # run the test, possibly with redirected input
4343 try :
4444 if test_file .startswith ('cmdline/repl_' ):
45- f = open (test_file , 'rb' )
46- output_mupy = subprocess .check_output (args , stdin = f )
47- f .close ()
45+ # Need to use a PTY to test command line editing
46+ import pty
47+ import select
48+
49+ def get ():
50+ rv = b''
51+ while True :
52+ ready = select .select ([master ], [], [], 0.02 )
53+ if ready [0 ] == [master ]:
54+ rv += os .read (master , 1024 )
55+ else :
56+ return rv
57+
58+ def send_get (what ):
59+ os .write (master , what )
60+ return get ()
61+
62+ with open (test_file , 'rb' ) as f :
63+ # instead of: output_mupy = subprocess.check_output(args, stdin=f)
64+ master , slave = pty .openpty ()
65+ p = subprocess .Popen (args , stdin = slave , stdout = slave ,
66+ stderr = subprocess .STDOUT , bufsize = 0 )
67+ banner = get ()
68+ output_mupy = banner + b'' .join (send_get (line ) for line in f )
69+ p .kill ()
70+ os .close (master )
71+ os .close (slave )
4872 else :
4973 output_mupy = subprocess .check_output (args + [test_file ])
5074 except subprocess .CalledProcessError :
@@ -64,6 +88,9 @@ def run_micropython(pyb, args, test_file):
6488 cs .append ('\\ ' + c )
6589 else :
6690 cs .append (c )
91+ # accept carriage-return(s) before final newline
92+ if cs [- 1 ] == '\n ' :
93+ cs [- 1 ] = '\r *\n '
6794 return bytes ('' .join (cs ), 'utf8' )
6895
6996 # convert parts of the output that are not stable across runs
@@ -96,6 +123,9 @@ def run_micropython(pyb, args, test_file):
96123 # a regex
97124 if lines_exp [i ][1 ].match (lines_mupy [i_mupy ]):
98125 lines_mupy [i_mupy ] = lines_exp [i ][0 ]
126+ else :
127+ #print("don't match: %r %s" % (lines_exp[i][1], lines_mupy[i_mupy])) # DEBUG
128+ pass
99129 i_mupy += 1
100130 if i_mupy >= len (lines_mupy ):
101131 break
@@ -133,10 +163,6 @@ def run_tests(pyb, tests, args):
133163 if native == b'CRASH' :
134164 skip_native = True
135165
136- # These tests no longer work; TODO change them or remove them
137- skip_tests .add ('cmdline/repl_basic.py' )
138- skip_tests .add ('cmdline/repl_cont.py' )
139-
140166 # Some tests shouldn't be run under Travis CI
141167 if os .getenv ('TRAVIS' ) == 'true' :
142168 skip_tests .add ('basics/memoryerror.py' )
0 commit comments