@@ -20,7 +20,7 @@ def rm_f(fname):
2020 if os .path .exists (fname ):
2121 os .remove (fname )
2222
23- def run_tests (pyb , tests ):
23+ def run_tests (pyb , tests , args ):
2424 test_count = 0
2525 testcase_count = 0
2626 passed_count = 0
@@ -54,9 +54,15 @@ def run_tests(pyb, tests):
5454 # run CPython to work out expected output
5555 try :
5656 output_expected = subprocess .check_output ([CPYTHON3 , '-B' , test_file ])
57+ if args .write_exp :
58+ with open (test_file_expected , 'wb' ) as f :
59+ f .write (output_expected )
5760 except subprocess .CalledProcessError :
5861 output_expected = b'CPYTHON3 CRASH'
5962
63+ if args .write_exp :
64+ continue
65+
6066 # run Micro Python
6167 if pyb is None :
6268 # run on PC
@@ -113,6 +119,7 @@ def main():
113119 cmd_parser = argparse .ArgumentParser (description = 'Run tests for Micro Python.' )
114120 cmd_parser .add_argument ('--pyboard' , action = 'store_true' , help = 'run the tests on the pyboard' )
115121 cmd_parser .add_argument ('-d' , '--test-dirs' , nargs = '*' , help = 'input test directories (if no files given)' )
122+ cmd_parser .add_argument ('--write-exp' , action = 'store_true' , help = 'save .exp files to run tests w/o CPython' )
116123 cmd_parser .add_argument ('files' , nargs = '*' , help = 'input test files' )
117124 args = cmd_parser .parse_args ()
118125
@@ -139,7 +146,7 @@ def main():
139146 # tests explicitly given
140147 tests = args .files
141148
142- if not run_tests (pyb , tests ):
149+ if not run_tests (pyb , tests , args ):
143150 sys .exit (1 )
144151
145152if __name__ == "__main__" :
0 commit comments