tests/run-tests.py: Add support for .native.exp expected output files.

There are currently a few tests that are excluded when using the native
emitter because they test printing of exception tracebacks, which includes
line numbers.  And the native emitter doesn't store line numbers, so gets
these tests wrong.

But we'd still like to run these tests using the native emitter, because
they test useful things even if the line number info is not in the
traceback (eg that threads which crash print out their exception).

This commit adds support for native-specific .exp files, which are of the
form `<test>.py.native.exp`.  If such an .exp file exists then it take
precedence over any normal `<test>.py.exp` file.

(Actually, the implementation here is general enough that it also supports
`<test>.py.bytecode.exp` as well, if bytecode ever needs a specific exp
file.)

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2025-08-10 12:05:32 +10:00
parent 0cb2c69b3f
commit 0f5f6484a2

View File

@@ -994,7 +994,11 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
# Expected output is result of running unittest.
output_expected = None
else:
test_file_expected = test_file + ".exp"
# Prefer emitter-specific expected output.
test_file_expected = test_file + "." + args.emit + ".exp"
if not os.path.isfile(test_file_expected):
# Fall back to generic expected output.
test_file_expected = test_file + ".exp"
if os.path.isfile(test_file_expected):
# Expected output given by a file, so read that in.
with open(test_file_expected, "rb") as f:
@@ -1202,8 +1206,8 @@ def main():
{test_directory_description}
When running tests, run-tests.py compares the MicroPython output of the test with the output
produced by running the test through CPython unless a <test>.exp file is found, in which
case it is used as comparison.
produced by running the test through CPython unless a <test>.exp file is found (or a
<test>.native.exp file when using the native emitter), in which case it is used as comparison.
If a test fails, run-tests.py produces a pair of <test>.out and <test>.exp files in the result
directory with the MicroPython output and the expectations, respectively.