@@ -28,10 +28,46 @@ def rm_f(fname):
2828def run_micropython (pyb , args , test_file ):
2929 if pyb is None :
3030 # run on PC
31- try :
32- output_mupy = subprocess .check_output ([MICROPYTHON , '-X' , 'emit=' + args .emit , test_file ])
33- except subprocess .CalledProcessError :
34- output_mupy = b'CRASH'
31+ if test_file .startswith ('cmdline/' ):
32+ # special handling for tests of the unix cmdline program
33+
34+ # check for any cmdline options needed for this test
35+ args = [MICROPYTHON ]
36+ with open (test_file , 'rb' ) as f :
37+ line = f .readline ()
38+ if line .startswith (b'# cmdline:' ):
39+ args += line [10 :].strip ().split ()
40+
41+ # run the test, possibly with redirected input
42+ try :
43+ if test_file .startswith ('cmdline/repl_' ):
44+ f = open (test_file , 'rb' )
45+ output_mupy = subprocess .check_output (args , stdin = f )
46+ f .close ()
47+ else :
48+ output_mupy = subprocess .check_output (args + [test_file ])
49+ except subprocess .CalledProcessError :
50+ output_mupy = b'CRASH'
51+
52+ # erase parts of the output that are not stable across runs
53+ with open (test_file + '.exp' , 'rb' ) as f :
54+ lines_exp = f .readlines ()
55+ lines_mupy = [line + b'\n ' for line in output_mupy .split (b'\n ' )]
56+ if output_mupy .endswith (b'\n ' ):
57+ lines_mupy = lines_mupy [:- 1 ] # remove erroneous last empty line
58+ if len (lines_mupy ) == len (lines_exp ):
59+ for i in range (len (lines_mupy )):
60+ pos = lines_exp [i ].find (b'######' )
61+ if pos != - 1 and len (lines_mupy [i ]) >= pos :
62+ lines_mupy [i ] = lines_mupy [i ][:pos ] + b'######\n '
63+ output_mupy = b'' .join (lines_mupy )
64+
65+ else :
66+ # a standard test
67+ try :
68+ output_mupy = subprocess .check_output ([MICROPYTHON , '-X' , 'emit=' + args .emit , test_file ])
69+ except subprocess .CalledProcessError :
70+ output_mupy = b'CRASH'
3571 else :
3672 # run on pyboard
3773 import pyboard
@@ -186,7 +222,7 @@ def main():
186222 if args .test_dirs is None :
187223 if pyb is None :
188224 # run PC tests
189- test_dirs = ('basics' , 'micropython' , 'float' , 'import' , 'io' , 'misc' , 'unicode' , 'extmod' , 'unix' )
225+ test_dirs = ('basics' , 'micropython' , 'float' , 'import' , 'io' , 'misc' , 'unicode' , 'extmod' , 'unix' , 'cmdline' )
190226 else :
191227 # run pyboard tests
192228 test_dirs = ('basics' , 'micropython' , 'float' , 'misc' , 'extmod' , 'pyb' , 'pybnative' , 'inlineasm' )
0 commit comments