From 5a04e2cca8255c2d4a1218d6ac0b38e67306206b Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 5 Oct 2014 22:27:12 +0100 Subject: tests: Add check for micropython.native and then skip relevant tests. If micropython.native decorator doesn't compile, then we skill all native/viper tests. This patch also re-enables the ujson_loads test on NT. Addresses issue #861, and partially addresses issue #856. --- tests/micropython/native.py | 10 ---- tests/micropython/native.py.exp | 2 - tests/micropython/native_check.py | 4 ++ tests/micropython/native_check.py.exp | 0 tests/micropython/native_misc.py | 10 ++++ tests/micropython/native_misc.py.exp | 2 + tests/micropython/viper.py | 90 ----------------------------------- tests/micropython/viper.py.exp | 13 ----- tests/micropython/viper_misc.py | 90 +++++++++++++++++++++++++++++++++++ tests/micropython/viper_misc.py.exp | 13 +++++ 10 files changed, 119 insertions(+), 115 deletions(-) delete mode 100644 tests/micropython/native.py delete mode 100644 tests/micropython/native.py.exp create mode 100644 tests/micropython/native_check.py create mode 100644 tests/micropython/native_check.py.exp create mode 100644 tests/micropython/native_misc.py create mode 100644 tests/micropython/native_misc.py.exp delete mode 100644 tests/micropython/viper.py delete mode 100644 tests/micropython/viper.py.exp create mode 100644 tests/micropython/viper_misc.py create mode 100644 tests/micropython/viper_misc.py.exp (limited to 'tests/micropython') diff --git a/tests/micropython/native.py b/tests/micropython/native.py deleted file mode 100644 index 8f087c494..000000000 --- a/tests/micropython/native.py +++ /dev/null @@ -1,10 +0,0 @@ -@micropython.native -def native_test(x): - print(1, [], x) - -native_test(2) - -# check that GC doesn't collect the native function -import gc -gc.collect() -native_test(3) diff --git a/tests/micropython/native.py.exp b/tests/micropython/native.py.exp deleted file mode 100644 index e1413fd79..000000000 --- a/tests/micropython/native.py.exp +++ /dev/null @@ -1,2 +0,0 @@ -1 [] 2 -1 [] 3 diff --git a/tests/micropython/native_check.py b/tests/micropython/native_check.py new file mode 100644 index 000000000..3971d1355 --- /dev/null +++ b/tests/micropython/native_check.py @@ -0,0 +1,4 @@ +# this test for the availability of native emitter +@micropython.native +def f(): + pass diff --git a/tests/micropython/native_check.py.exp b/tests/micropython/native_check.py.exp new file mode 100644 index 000000000..e69de29bb diff --git a/tests/micropython/native_misc.py b/tests/micropython/native_misc.py new file mode 100644 index 000000000..8f087c494 --- /dev/null +++ b/tests/micropython/native_misc.py @@ -0,0 +1,10 @@ +@micropython.native +def native_test(x): + print(1, [], x) + +native_test(2) + +# check that GC doesn't collect the native function +import gc +gc.collect() +native_test(3) diff --git a/tests/micropython/native_misc.py.exp b/tests/micropython/native_misc.py.exp new file mode 100644 index 000000000..e1413fd79 --- /dev/null +++ b/tests/micropython/native_misc.py.exp @@ -0,0 +1,2 @@ +1 [] 2 +1 [] 3 diff --git a/tests/micropython/viper.py b/tests/micropython/viper.py deleted file mode 100644 index 7e6ed67d4..000000000 --- a/tests/micropython/viper.py +++ /dev/null @@ -1,90 +0,0 @@ -import micropython - -# viper function taking and returning ints -@micropython.viper -def viper_int(x:int, y:int) -> int: - return x + y + 3 -print(viper_int(1, 2)) - -# viper function taking and returning objects -@micropython.viper -def viper_object(x:object, y:object) -> object: - return x + y -print(viper_object(1, 2)) - -# a local (should have automatic type int) -@micropython.viper -def viper_local(x:int) -> int: - y = 4 - return x + y -print(viper_local(3)) - -# without type annotation, types should default to object -@micropython.viper -def viper_no_annotation(x, y): - return x * y -print(viper_no_annotation(4, 5)) - -# a for loop -@micropython.viper -def viper_for(a:int, b:int) -> int: - total = 0 - for x in range(a, b): - total += x - return total -print(viper_for(10, 10000)) - -# accessing a global -@micropython.viper -def viper_access_global(): - global gl - gl = 1 - return gl -print(viper_access_global(), gl) - -# calling print with object and int types -@micropython.viper -def viper_print(x, y:int): - print(x, y + 1) -viper_print(1, 2) - -# making a tuple from an object and an int -@micropython.viper -def viper_tuple(x, y:int): - return (x, y + 1) -print(viper_tuple(1, 2)) - -# making a list from an object and an int -@micropython.viper -def viper_list(x, y:int): - return [x, y + 1] -print(viper_list(1, 2)) - -# making a set from an object and an int -@micropython.viper -def viper_set(x, y:int): - return {x, y + 1} -print(sorted(list(viper_set(1, 2)))) - -# raising an exception -@micropython.viper -def viper_raise(x:int): - raise SystemError(x) -try: - viper_raise(1) -except SystemError as e: - print(repr(e)) - -# this doesn't work at the moment -#@micropython.viper -#def g() -> uint: -# return -1 - -# calling GC after defining the function -@micropython.viper -def viper_gc() -> int: - return 1 -print(viper_gc()) -import gc -gc.collect() -print(viper_gc()) diff --git a/tests/micropython/viper.py.exp b/tests/micropython/viper.py.exp deleted file mode 100644 index 2ea26ce99..000000000 --- a/tests/micropython/viper.py.exp +++ /dev/null @@ -1,13 +0,0 @@ -6 -3 -7 -20 -49994955 -1 1 -1 3 -(1, 3) -[1, 3] -[1, 3] -SystemError(1,) -1 -1 diff --git a/tests/micropython/viper_misc.py b/tests/micropython/viper_misc.py new file mode 100644 index 000000000..7e6ed67d4 --- /dev/null +++ b/tests/micropython/viper_misc.py @@ -0,0 +1,90 @@ +import micropython + +# viper function taking and returning ints +@micropython.viper +def viper_int(x:int, y:int) -> int: + return x + y + 3 +print(viper_int(1, 2)) + +# viper function taking and returning objects +@micropython.viper +def viper_object(x:object, y:object) -> object: + return x + y +print(viper_object(1, 2)) + +# a local (should have automatic type int) +@micropython.viper +def viper_local(x:int) -> int: + y = 4 + return x + y +print(viper_local(3)) + +# without type annotation, types should default to object +@micropython.viper +def viper_no_annotation(x, y): + return x * y +print(viper_no_annotation(4, 5)) + +# a for loop +@micropython.viper +def viper_for(a:int, b:int) -> int: + total = 0 + for x in range(a, b): + total += x + return total +print(viper_for(10, 10000)) + +# accessing a global +@micropython.viper +def viper_access_global(): + global gl + gl = 1 + return gl +print(viper_access_global(), gl) + +# calling print with object and int types +@micropython.viper +def viper_print(x, y:int): + print(x, y + 1) +viper_print(1, 2) + +# making a tuple from an object and an int +@micropython.viper +def viper_tuple(x, y:int): + return (x, y + 1) +print(viper_tuple(1, 2)) + +# making a list from an object and an int +@micropython.viper +def viper_list(x, y:int): + return [x, y + 1] +print(viper_list(1, 2)) + +# making a set from an object and an int +@micropython.viper +def viper_set(x, y:int): + return {x, y + 1} +print(sorted(list(viper_set(1, 2)))) + +# raising an exception +@micropython.viper +def viper_raise(x:int): + raise SystemError(x) +try: + viper_raise(1) +except SystemError as e: + print(repr(e)) + +# this doesn't work at the moment +#@micropython.viper +#def g() -> uint: +# return -1 + +# calling GC after defining the function +@micropython.viper +def viper_gc() -> int: + return 1 +print(viper_gc()) +import gc +gc.collect() +print(viper_gc()) diff --git a/tests/micropython/viper_misc.py.exp b/tests/micropython/viper_misc.py.exp new file mode 100644 index 000000000..2ea26ce99 --- /dev/null +++ b/tests/micropython/viper_misc.py.exp @@ -0,0 +1,13 @@ +6 +3 +7 +20 +49994955 +1 1 +1 3 +(1, 3) +[1, 3] +[1, 3] +SystemError(1,) +1 +1 -- cgit v1.2.3