Skip to content

tests: add support for native-specific .exp test output files #17882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/basics/sys_tracebacklimit.py.native.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ValueError: value

limit 4
ValueError: value

limit 3
ValueError: value

limit 2
ValueError: value

limit 1
ValueError: value

limit 0
ValueError: value

limit -1
ValueError: value

True
False
2 changes: 2 additions & 0 deletions tests/micropython/emg_exc.py.native.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ValueError: 1

3 changes: 3 additions & 0 deletions tests/micropython/heapalloc_traceback.py.native.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
StopIteration
StopIteration:

13 changes: 12 additions & 1 deletion tests/micropython/opt_level_lineno.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,15 @@
# check that level 3 doesn't store line numbers
# the expected output is that any line is printed as "line 1"
micropython.opt_level(3)
exec("try:\n xyz\nexcept NameError as er:\n import sys\n sys.print_exception(er)")

# force bytecode emitter, because native emitter doesn't store line numbers
exec("""
@micropython.bytecode
def f():
try:
xyz
except NameError as er:
import sys
sys.print_exception(er)
f()
""")
2 changes: 1 addition & 1 deletion tests/micropython/opt_level_lineno.py.exp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<string>", line 1, in f
NameError: name 'xyz' isn't defined
2 changes: 1 addition & 1 deletion tests/misc/print_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def g():
except Exception as e:
print("reraise")
print_exc(e)
raise
raise e
except Exception as e:
print("caught")
print_exc(e)
Expand Down
18 changes: 18 additions & 0 deletions tests/misc/print_exception.py.native.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
caught
Exception: msg

caught
Exception: fail

finally
caught
Exception: fail

reraise
Exception: fail

caught
Exception: fail

AttributeError: 'function' object has no attribute 'X'

17 changes: 7 additions & 10 deletions tests/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,6 @@ def open(self, path, mode):
"basics/unboundlocal.py",
# These require "raise from".
"basics/exception_chain.py",
# These require proper traceback info.
"basics/sys_tracebacklimit.py",
"misc/print_exception.py",
"micropython/emg_exc.py",
"micropython/heapalloc_traceback.py",
"micropython/opt_level_lineno.py",
"thread/thread_exc2.py",
# These require stack-allocated slice optimisation.
"micropython/heapalloc_slice.py",
# These require running the scheduler.
Expand Down Expand Up @@ -994,7 +987,11 @@ def run_one_test(test_file):
# 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:
Expand Down Expand Up @@ -1202,8 +1199,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.
Expand Down
3 changes: 3 additions & 0 deletions tests/thread/thread_exc2.py.native.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Unhandled exception in thread started by <function thread_entry at 0x\[0-9a-f\]\+>
ValueError:
done
Loading