Skip to content

Commit dd396ea

Browse files
committed
tests/run-tests: Make test output directory configurable.
A configurable result directory is advantageous because it enables using a dedicated location, eventually outside of the source tree, instead of forcing the output files into a fixed directory which might also contain other files already. For that reason the default output directory also has been changed to tests/results/.
1 parent 9e02fca commit dd396ea

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ build-*/
2727

2828
# Test failure outputs
2929
######################
30-
tests/*.exp
31-
tests/*.out
30+
tests/results/*
3231

3332
# Python cache files
3433
######################

tests/run-tests

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def run_feature_check(pyb, args, base_path, test_file):
226226
return run_micropython(pyb, args, base_path("feature_check", test_file), is_special=True)
227227

228228

229-
def run_tests(pyb, tests, args):
229+
def run_tests(pyb, tests, args, result_dir):
230230
test_count = 0
231231
testcase_count = 0
232232
passed_count = 0
@@ -521,8 +521,8 @@ def run_tests(pyb, tests, args):
521521

522522
testcase_count += len(output_expected.splitlines())
523523

524-
filename_expected = base_path(test_basename + ".exp")
525-
filename_mupy = base_path(test_basename + ".out")
524+
filename_expected = os.path.join(result_dir, test_basename + ".exp")
525+
filename_mupy = os.path.join(result_dir, test_basename + ".out")
526526

527527
if output_expected == output_mupy:
528528
print("pass ", test_file)
@@ -584,7 +584,7 @@ this directory.
584584
When running tests, run-tests compares the MicroPython output of the test with the output
585585
produced by running the test through CPython unless a <test>.exp file is found, in which
586586
case it is used as comparison.
587-
If a test fails, run-tests produces a pair of <test>.out and <test>.exp files in the current
587+
If a test fails, run-tests produces a pair of <test>.out and <test>.exp files in the result
588588
directory with the MicroPython output and the expectations, respectively.
589589
''',
590590
epilog='''\
@@ -601,6 +601,7 @@ the last matching regex is used:
601601
cmd_parser.add_argument('-u', '--user', default='micro', help='the telnet login username')
602602
cmd_parser.add_argument('-p', '--password', default='python', help='the telnet login password')
603603
cmd_parser.add_argument('-d', '--test-dirs', nargs='*', help='input test directories (if no files given)')
604+
cmd_parser.add_argument('-r', '--result-dir', default=base_path('results'), help='directory for test results')
604605
cmd_parser.add_argument('-e', '--exclude', action=append_filter, metavar='REGEX', dest='filters', help='exclude test by regex on path/name.py')
605606
cmd_parser.add_argument('-i', '--include', action=append_filter, metavar='REGEX', dest='filters', help='include test by regex on path/name.py')
606607
cmd_parser.add_argument('--write-exp', action='store_true', help='use CPython to generate .exp files to run tests w/o CPython')
@@ -616,7 +617,7 @@ the last matching regex is used:
616617
args = cmd_parser.parse_args()
617618

618619
if args.print_failures:
619-
for exp in glob(base_path("*.exp")):
620+
for exp in glob(os.path.join(args.result_dir, "*.exp")):
620621
testbase = exp[:-4]
621622
print()
622623
print("FAILURE {0}".format(testbase))
@@ -625,7 +626,7 @@ the last matching regex is used:
625626
sys.exit(0)
626627

627628
if args.clean_failures:
628-
for f in glob(base_path("*.exp")) + glob(base_path("*.out")):
629+
for f in glob(os.path.join(args.result_dir, "*.exp")) + glob(os.path.join(args.result_dir, "*.out")):
629630
os.remove(f)
630631

631632
sys.exit(0)
@@ -676,7 +677,8 @@ the last matching regex is used:
676677
os.environ['MICROPYPATH'] = os.pathsep + base_path('../extmod')
677678

678679
try:
679-
res = run_tests(pyb, tests, args)
680+
os.makedirs(args.result_dir, exist_ok=True)
681+
res = run_tests(pyb, tests, args, args.result_dir)
680682
finally:
681683
if pyb:
682684
pyb.close()

0 commit comments

Comments
 (0)