summaryrefslogtreecommitdiff
path: root/tests/micropython/viper_error.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/micropython/viper_error.py')
-rw-r--r--tests/micropython/viper_error.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/tests/micropython/viper_error.py b/tests/micropython/viper_error.py
index ff32f5473..790f3d75c 100644
--- a/tests/micropython/viper_error.py
+++ b/tests/micropython/viper_error.py
@@ -1,11 +1,13 @@
# test syntax and type errors specific to viper code generation
+
def test(code):
try:
exec(code)
except (SyntaxError, ViperTypeError, NotImplementedError) as e:
print(repr(e))
+
# viper: annotations must be identifiers
test("@micropython.viper\ndef f(a:1): pass")
test("@micropython.viper\ndef f() -> 1: pass")
@@ -14,30 +16,36 @@ test("@micropython.viper\ndef f() -> 1: pass")
test("@micropython.viper\ndef f(x:unknown_type): pass")
# local used before type known
-test("""
+test(
+ """
@micropython.viper
def f():
print(x)
x = 1
-""")
+"""
+)
# type mismatch storing to local
-test("""
+test(
+ """
@micropython.viper
def f():
x = 1
y = []
x = y
-""")
+"""
+)
# can't implicitly convert type to bool
-test("""
+test(
+ """
@micropython.viper
def f():
x = ptr(0)
if x:
pass
-""")
+"""
+)
# incorrect return type
test("@micropython.viper\ndef f() -> int: return []")