summaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2020-03-01 09:40:43 -0600
committerDamien George <damien@micropython.org>2021-05-30 10:38:48 +1000
commitf2dbc9102251f092e93b7c87cd8ffa5e9e5b880b (patch)
treef1f42bde0323d14ada0f8a057ac2956833a500eb /tests
parenta60ad3364132b9c4a30b20cd91fd5cd1ac965618 (diff)
downloadmicropython-f2dbc9102251f092e93b7c87cd8ffa5e9e5b880b.tar.gz
micropython-f2dbc9102251f092e93b7c87cd8ffa5e9e5b880b.zip
py/compile: Raise an error on async with/for outside an async function.
A simple reproducer is: async for x in (): x Before this change, it would cause an assertion error in mpy-cross and micropython-coverage.
Diffstat (limited to 'tests')
-rw-r--r--tests/basics/async_syntaxerror.py19
-rw-r--r--tests/basics/async_syntaxerror.py.exp2
2 files changed, 21 insertions, 0 deletions
diff --git a/tests/basics/async_syntaxerror.py b/tests/basics/async_syntaxerror.py
new file mode 100644
index 0000000000..ddd2c4b59e
--- /dev/null
+++ b/tests/basics/async_syntaxerror.py
@@ -0,0 +1,19 @@
+# test syntax errors using async
+
+try:
+ exec
+except NameError:
+ print("SKIP")
+ raise SystemExit
+
+
+def test_syntax(code):
+ try:
+ exec(code)
+ print("no SyntaxError")
+ except SyntaxError:
+ print("SyntaxError")
+
+
+test_syntax("async for x in (): x")
+test_syntax("async with x: x")
diff --git a/tests/basics/async_syntaxerror.py.exp b/tests/basics/async_syntaxerror.py.exp
new file mode 100644
index 0000000000..5275689b41
--- /dev/null
+++ b/tests/basics/async_syntaxerror.py.exp
@@ -0,0 +1,2 @@
+SyntaxError
+SyntaxError