tests/basics: Move test for "return" outside function to own file.

Because its behaviour is conditional on MICROPY_CPYTHON_COMPAT.
This commit is contained in:
Petr Viktorin 2020-02-04 16:34:38 +01:00 committed by Damien George
parent e6c9800645
commit dbed8f576d
2 changed files with 18 additions and 1 deletions

View File

@ -82,7 +82,6 @@ test_syntax("break")
test_syntax("continue")
# must be in a function
test_syntax("return")
test_syntax("yield")
test_syntax("nonlocal a")
test_syntax("await 1")

View File

@ -0,0 +1,18 @@
# With MICROPY_CPYTHON_COMPAT, the "return" statement can only appear in a
# function.
# Otherwise (in minimal builds), it ends execution of a module/class.
try:
exec
except NameError:
print("SKIP")
raise SystemExit
try:
exec('return; print("this should not be executed.")')
# if we get here then MICROPY_CPYTHON_COMPAT is disabled and test
# should be skipped.
print("SKIP")
raise SystemExit
except SyntaxError:
print('SyntaxError')