Skip to content

Commit e29f704

Browse files
committed
tests/micropython/viper_error: Add more tests to improve coverage.
1 parent a5a84e1 commit e29f704

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

tests/micropython/viper_error.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
def test(code):
44
try:
55
exec(code)
6-
except (SyntaxError, ViperTypeError) as e:
6+
except (SyntaxError, ViperTypeError, NotImplementedError) as e:
77
print(repr(e))
88

99
# viper: annotations must be identifiers
1010
test("@micropython.viper\ndef f(a:1): pass")
1111
test("@micropython.viper\ndef f() -> 1: pass")
1212

13+
# unknown type
14+
test("@micropython.viper\ndef f(x:unknown_type): pass")
15+
16+
# too many arguments
17+
test("@micropython.viper\ndef f(a, b, c, d, e): pass")
18+
1319
# local used before type known
1420
test("""
1521
@micropython.viper
@@ -49,6 +55,9 @@ def f():
4955
# can't store
5056
test("@micropython.viper\ndef f(): 1[0] = 1")
5157
test("@micropython.viper\ndef f(): 1[x] = 1")
58+
test("@micropython.viper\ndef f(x:int): x[0] = x")
59+
test("@micropython.viper\ndef f(x:ptr32): x[0] = None")
60+
test("@micropython.viper\ndef f(x:ptr32): x[x] = None")
5261

5362
# must raise an object
5463
test("@micropython.viper\ndef f(): raise 1")
@@ -57,3 +66,16 @@ def f():
5766
test("@micropython.viper\ndef f(x:int): +x")
5867
test("@micropython.viper\ndef f(x:int): -x")
5968
test("@micropython.viper\ndef f(x:int): ~x")
69+
70+
# binary op not implemented
71+
test("@micropython.viper\ndef f(x:int): res = x in x")
72+
73+
# yield (from) not implemented
74+
test("@micropython.viper\ndef f(): yield")
75+
test("@micropython.viper\ndef f(): yield from f")
76+
77+
# passing a ptr to a Python function not implemented
78+
test("@micropython.viper\ndef f(): print(ptr(1))")
79+
80+
# cast of a casting identifier not implemented
81+
test("@micropython.viper\ndef f(): int(int)")

tests/micropython/viper_error.py.exp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
SyntaxError('parameter annotation must be an identifier',)
22
SyntaxError('return annotation must be an identifier',)
3+
ViperTypeError("unknown type 'unknown_type'",)
4+
ViperTypeError("Viper functions don't currently support more than 4 arguments",)
35
ViperTypeError("local 'x' used before type known",)
46
ViperTypeError("local 'x' has type 'int' but source is 'object'",)
57
ViperTypeError("can't implicitly convert 'ptr' to 'bool'",)
@@ -9,7 +11,15 @@ ViperTypeError("can't load from 'int'",)
911
ViperTypeError("can't load from 'int'",)
1012
ViperTypeError("can't store to 'int'",)
1113
ViperTypeError("can't store to 'int'",)
14+
ViperTypeError("can't store to 'int'",)
15+
ViperTypeError("can't store 'None'",)
16+
ViperTypeError("can't store 'None'",)
1217
ViperTypeError('must raise an object',)
1318
ViperTypeError('unary op __pos__ not implemented',)
1419
ViperTypeError('unary op __neg__ not implemented',)
1520
ViperTypeError('unary op __invert__ not implemented',)
21+
ViperTypeError('binary op __contains__ not implemented',)
22+
NotImplementedError('native yield',)
23+
NotImplementedError('native yield from',)
24+
NotImplementedError('conversion to object',)
25+
NotImplementedError('casting',)

0 commit comments

Comments
 (0)