Browse Source

tests/micropython/viper_error: Add more tests to improve coverage.

pull/2960/head
Damien George 8 years ago
parent
commit
e29f704b67
  1. 24
      tests/micropython/viper_error.py
  2. 10
      tests/micropython/viper_error.py.exp

24
tests/micropython/viper_error.py

@ -3,13 +3,19 @@
def test(code):
try:
exec(code)
except (SyntaxError, ViperTypeError) as e:
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")
# unknown type
test("@micropython.viper\ndef f(x:unknown_type): pass")
# too many arguments
test("@micropython.viper\ndef f(a, b, c, d, e): pass")
# local used before type known
test("""
@micropython.viper
@ -49,6 +55,9 @@ test("@micropython.viper\ndef f(): 1[x]")
# can't store
test("@micropython.viper\ndef f(): 1[0] = 1")
test("@micropython.viper\ndef f(): 1[x] = 1")
test("@micropython.viper\ndef f(x:int): x[0] = x")
test("@micropython.viper\ndef f(x:ptr32): x[0] = None")
test("@micropython.viper\ndef f(x:ptr32): x[x] = None")
# must raise an object
test("@micropython.viper\ndef f(): raise 1")
@ -57,3 +66,16 @@ test("@micropython.viper\ndef f(): raise 1")
test("@micropython.viper\ndef f(x:int): +x")
test("@micropython.viper\ndef f(x:int): -x")
test("@micropython.viper\ndef f(x:int): ~x")
# binary op not implemented
test("@micropython.viper\ndef f(x:int): res = x in x")
# yield (from) not implemented
test("@micropython.viper\ndef f(): yield")
test("@micropython.viper\ndef f(): yield from f")
# passing a ptr to a Python function not implemented
test("@micropython.viper\ndef f(): print(ptr(1))")
# cast of a casting identifier not implemented
test("@micropython.viper\ndef f(): int(int)")

10
tests/micropython/viper_error.py.exp

@ -1,5 +1,7 @@
SyntaxError('parameter annotation must be an identifier',)
SyntaxError('return annotation must be an identifier',)
ViperTypeError("unknown type 'unknown_type'",)
ViperTypeError("Viper functions don't currently support more than 4 arguments",)
ViperTypeError("local 'x' used before type known",)
ViperTypeError("local 'x' has type 'int' but source is 'object'",)
ViperTypeError("can't implicitly convert 'ptr' to 'bool'",)
@ -9,7 +11,15 @@ ViperTypeError("can't load from 'int'",)
ViperTypeError("can't load from 'int'",)
ViperTypeError("can't store to 'int'",)
ViperTypeError("can't store to 'int'",)
ViperTypeError("can't store to 'int'",)
ViperTypeError("can't store 'None'",)
ViperTypeError("can't store 'None'",)
ViperTypeError('must raise an object',)
ViperTypeError('unary op __pos__ not implemented',)
ViperTypeError('unary op __neg__ not implemented',)
ViperTypeError('unary op __invert__ not implemented',)
ViperTypeError('binary op __contains__ not implemented',)
NotImplementedError('native yield',)
NotImplementedError('native yield from',)
NotImplementedError('conversion to object',)
NotImplementedError('casting',)

Loading…
Cancel
Save