8000 tests: Add comprehensive tests for new pyexec functionality. · micropython/micropython@0f97a2f · GitHub
Skip to content

Commit 0f97a2f

Browse files
committed
tests: Add comprehensive tests for new pyexec functionality.
Add tests for: - compile-only flag functionality (cmd_compile_only.py) - compile-only with syntax errors (cmd_compile_only_error.py) - __file__ variable in script execution (cmd_file_variable.py) - normalize_newlines function behavior (test_normalize_newlines.py) These tests verify the new features added to shared/runtime/pyexec.c and the test framework improvements. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
1 parent 47a26a6 commit 0f97a2f

9 files changed

+52
-1
lines changed

pyproject.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ target-version = "py37"
2828

2929
[tool.ruff.lint]
3030
exclude = [ # Ruff finds Python SyntaxError in these files
31+
"tests/cmdline/cmd_compile_only_error.py",
3132
"tests/cmdline/repl_autocomplete.py",
3233
"tests/cmdline/repl_autoindent.py",
3334
"tests/cmdline/repl_basic.py",
@@ -65,5 +66,11 @@ mccabe.max-complexity = 40
6566
# basics: needs careful attention before applying automatic formatting
6667
# repl_: not real python files
6768
# viper_args: uses f(*)
68-
exclude = ["tests/basics/*.py", "tests/*/repl_*.py", "tests/micropython/viper_args.py"]
69+
exclude = [
70+
"tests/basics/*.py",
71+
"tests/*/repl_*.py",
72+
"tests/cmdline/cmd_compile_only_error.py",
73+
"tests/micropython/test_normalize_newlines.py",
74+
"tests/micropython/viper_args.py",
75+
]
6976
quote-style = "preserve"

tests/cmdline/cmd_compile_only.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# cmdline: -X compile-only
2+
# test compile-only functionality
3+
print("This should not be printed")
4+
x = 1 + 2
5+
6+
7+
def hello():
8+
return "world"
9+
10+
11+
class TestClass:
12+
def __init__(self):
13+
self.value = 42

tests/cmdline/cmd_compile_only.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# cmdline: -X compile-only
2+
# test compile-only with syntax error
3+
print("This should not be printed")
4+
def broken_syntax(
5+
# Missing closing parenthesis
6+
return "error"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CRASH

tests/cmdline/cmd_file_variable.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Test that __file__ is set correctly for script execution
2+
try:
3+
print("__file__ =", __file__)
4+
except NameError:
5+
print("__file__ not defined")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__file__ = cmdline/cmd_file_variable.py
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Test for normalize_newlines functionality
2+
# This test verifies that test framework handles various newline combinations correctly
3+
4+
# Note: This is more of an integration test since normalize_newlines is in the test framework
5+
# The actual testing happens when this test is run through run-tests.py
6+
7+
print("Testing newline handling")
8+
print("Line 1\r\nLine 2") # This has \r\n
9+
print("Line 3\rLine 4") # This has \r only
10+
print("Line 5\nLine 6") # This has \n only
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Testing newline handling
2+
Line 1
3+
Line 2
4+
Line 3
5+
Line 4
6+
Line 5
7+
Line 6

0 commit comments

Comments
 (0)
0