From 0f5f6484a2e6f330d03ee4786011ccb8062ac325 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 10 Aug 2025 12:05:32 +1000 Subject: [PATCH] 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 `.py.native.exp`. If such an .exp file exists then it take precedence over any normal `.py.exp` file. (Actually, the implementation here is general enough that it also supports `.py.bytecode.exp` as well, if bytecode ever needs a specific exp file.) Signed-off-by: Damien George --- tests/run-tests.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/run-tests.py b/tests/run-tests.py index 958ddb1dc8..d0a9121b4a 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -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 .exp file is found, in which -case it is used as comparison. +produced by running the test through CPython unless a .exp file is found (or a +.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 .out and .exp files in the result directory with the MicroPython output and the expectations, respectively.