summaryrefslogtreecommitdiff
path: root/tests/basics/builtin_compile.py
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2020-08-21 10:30:09 +1000
committerDamien George <damien@micropython.org>2020-08-22 11:38:46 +1000
commit5f9b105244bb9f605f3ca157cd421967c665bd6e (patch)
treea0c71dca66b5f52e214399e21b051ba204173b5d /tests/basics/builtin_compile.py
parent448319a7450714efd72ae527e184a247a82ee39d (diff)
py/runtime: Fix builtin compile() in "single" mode so it prints exprs.
As per CPython behaviour, compile(stmt, "file", "single") should create code which prints to stdout (via __repl_print__) the results of any expressions in stmt. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests/basics/builtin_compile.py')
-rw-r--r--tests/basics/builtin_compile.py22
1 files changed, 9 insertions, 13 deletions
diff --git a/tests/basics/builtin_compile.py b/tests/basics/builtin_compile.py
index bf272aca1..a2f2cbe55 100644
--- a/tests/basics/builtin_compile.py
+++ b/tests/basics/builtin_compile.py
@@ -1,11 +1,10 @@
# test compile builtin
-def have_compile():
- try:
- compile
- return True
- except NameError:
- return False
+try:
+ compile
+except NameError:
+ print("SKIP")
+ raise SystemExit
def test():
global x
@@ -26,8 +25,9 @@ def test():
exec(c, {}, {"x":3})
# single/eval mode
- exec(compile('print(1 + 1)', 'file', 'single'))
- print(eval(compile('1 + 1', 'file', 'eval')))
+ exec(compile("if 1: 10 + 1\n", "file", "single"))
+ exec(compile("print(10 + 2)", "file", "single"))
+ print(eval(compile("10 + 3", "file", "eval")))
# bad mode
try:
@@ -42,8 +42,4 @@ def test():
print("NameError")
print(x) # check 'x' still exists as a global
-if have_compile():
- test()
-else:
- print("SKIP")
- raise SystemExit
+test()