Skip to content

Commit 93a7340

Browse files
dhalbertdpgeorge
authored andcommitted
tests/run-tests.py: Allow .native.exp files to contain regexs.
Signed-off-by: Dan Halbert <halbert@halwitz.org>
1 parent 9b36eed commit 93a7340

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

tests/run-tests.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,12 @@ def run_micropython(pyb, args, test_file, test_file_abspath, is_special=False):
456456

457457
if is_special:
458458
# check for any cmdline options needed for this test
459-
args = [MICROPYTHON]
459+
cmdlist = [MICROPYTHON]
460460
with open(test_file, "rb") as f:
461461
line = f.readline()
462462
if line.startswith(b"# cmdline:"):
463463
# subprocess.check_output on Windows only accepts strings, not bytes
464-
args += [str(c, "utf-8") for c in line[10:].strip().split()]
464+
cmdlist += [str(c, "utf-8") for c in line[10:].strip().split()]
465465

466466
# run the test, possibly with redirected input
467467
try:
@@ -497,10 +497,10 @@ def send_get(what):
497497
return get()
498498

499499
with open(test_file, "rb") as f:
500-
# instead of: output_mupy = subprocess.check_output(args, stdin=f)
500+
# instead of: output_mupy = subprocess.check_output(cmdlist, stdin=f)
501501
master, slave = pty.openpty()
502502
p = subprocess.Popen(
503-
args, stdin=slave, stdout=slave, stderr=subprocess.STDOUT, bufsize=0
503+
cmdlist, stdin=slave, stdout=slave, stderr=subprocess.STDOUT, bufsize=0
504504
)
505505
banner = get(True)
506506
output_mupy = banner + b"".join(send_get(line) for line in f)
@@ -519,7 +519,7 @@ def send_get(what):
519519
os.close(slave)
520520
else:
521521
output_mupy = subprocess.check_output(
522-
args + [test_file], stderr=subprocess.STDOUT
522+
cmdlist + [test_file], stderr=subprocess.STDOUT
523523
)
524524
except subprocess.CalledProcessError:
525525
return b"CRASH"
@@ -585,7 +585,12 @@ def send_get(what):
585585

586586
if is_special or test_file_abspath in tests_with_regex_output:
587587
# convert parts of the output that are not stable across runs
588-
with open(test_file + ".exp", "rb") as f:
588+
# Prefer emitter-specific expected output.
589+
exp_file = test_file + "." + args.emit + ".exp"
590+
if not os.path.isfile(exp_file):
591+
# Fall back to generic expected output.
592+
exp_file = test_file + ".exp"
593+
with open(exp_file, "rb") as f:
589594
lines_exp = []
590595
for line in f.readlines():
591596
if line == b"########\n":

0 commit comments

Comments
 (0)