aboutsummaryrefslogtreecommitdiff
path: root/tests/micropython
diff options
context:
space:
mode:
authorDamien George2015-03-25 23:10:09 +0000
committerDamien George2015-03-25 23:10:09 +0000
commit214179b430ebc1101e28b19248b6166f5e511e6b (patch)
tree74f8dc7b2e9dbfd902514b82a698e9ddaa8bb4bc /tests/micropython
parent44f65c0e2f5ce27ce90bbec218ecb39cba9d75a2 (diff)
tests: Add tests for SyntaxError, TypeError, and other missing things.
This is intended to improve coverage of the test suite.
Diffstat (limited to 'tests/micropython')
-rw-r--r--tests/micropython/const_error.py17
-rw-r--r--tests/micropython/const_error.py.exp1
-rw-r--r--tests/micropython/decorator_error.py11
-rw-r--r--tests/micropython/decorator_error.py.exp2
-rw-r--r--tests/micropython/native_misc.py23
-rw-r--r--tests/micropython/native_misc.py.exp4
-rw-r--r--tests/micropython/viper_error.py11
-rw-r--r--tests/micropython/viper_error.py.exp2
8 files changed, 65 insertions, 6 deletions
diff --git a/tests/micropython/const_error.py b/tests/micropython/const_error.py
index fa7deaaf3..b46efcae2 100644
--- a/tests/micropython/const_error.py
+++ b/tests/micropython/const_error.py
@@ -1,6 +1,13 @@
-# make sure syntax error works corrects for bad const definition
+# make sure syntax error works correctly for bad const definition
-try:
- exec("a = const(x)")
-except SyntaxError:
- print("SyntaxError")
+def test_syntax(code):
+ try:
+ exec(code)
+ except SyntaxError:
+ print("SyntaxError")
+
+# argument not a constant
+test_syntax("a = const(x)")
+
+# redefined constant
+test_syntax("A = const(1); A = const(2)")
diff --git a/tests/micropython/const_error.py.exp b/tests/micropython/const_error.py.exp
index 8729fc434..5275689b4 100644
--- a/tests/micropython/const_error.py.exp
+++ b/tests/micropython/const_error.py.exp
@@ -1 +1,2 @@
SyntaxError
+SyntaxError
diff --git a/tests/micropython/decorator_error.py b/tests/micropython/decorator_error.py
new file mode 100644
index 000000000..c7da3119f
--- /dev/null
+++ b/tests/micropython/decorator_error.py
@@ -0,0 +1,11 @@
+# test syntax errors for uPy-specific decorators
+
+def test_syntax(code):
+ try:
+ exec(code)
+ except SyntaxError:
+ print("SyntaxError")
+
+# invalid micropython decorators
+test_syntax("@micropython.a\ndef f(): pass")
+test_syntax("@micropython.a.b\ndef f(): pass")
diff --git a/tests/micropython/decorator_error.py.exp b/tests/micropython/decorator_error.py.exp
new file mode 100644
index 000000000..5275689b4
--- /dev/null
+++ b/tests/micropython/decorator_error.py.exp
@@ -0,0 +1,2 @@
+SyntaxError
+SyntaxError
diff --git a/tests/micropython/native_misc.py b/tests/micropython/native_misc.py
index 8f087c494..0cd521de6 100644
--- a/tests/micropython/native_misc.py
+++ b/tests/micropython/native_misc.py
@@ -1,10 +1,31 @@
+# tests for natively compiled functions
+
+# basic test
@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)
+
+# native with 2 args
+@micropython.native
+def f(a, b):
+ print(a + b)
+f(1, 2)
+
+# native with 3 args
+@micropython.native
+def f(a, b, c):
+ print(a + b + c)
+f(1, 2, 3)
+
+# check not operator
+@micropython.native
+def f(a):
+ print(not a)
+f(False)
+f(True)
diff --git a/tests/micropython/native_misc.py.exp b/tests/micropython/native_misc.py.exp
index e1413fd79..b3e1389ef 100644
--- a/tests/micropython/native_misc.py.exp
+++ b/tests/micropython/native_misc.py.exp
@@ -1,2 +1,6 @@
1 [] 2
1 [] 3
+3
+6
+True
+False
diff --git a/tests/micropython/viper_error.py b/tests/micropython/viper_error.py
new file mode 100644
index 000000000..514acebd7
--- /dev/null
+++ b/tests/micropython/viper_error.py
@@ -0,0 +1,11 @@
+# test syntax errors specific to viper code generation
+
+def test_syntax(code):
+ try:
+ exec(code)
+ except SyntaxError:
+ print("SyntaxError")
+
+# viper: annotations must be identifiers
+test_syntax("@micropython.viper\ndef f(a:1): pass")
+test_syntax("@micropython.viper\ndef f() -> 1: pass")
diff --git a/tests/micropython/viper_error.py.exp b/tests/micropython/viper_error.py.exp
new file mode 100644
index 000000000..5275689b4
--- /dev/null
+++ b/tests/micropython/viper_error.py.exp
@@ -0,0 +1,2 @@
+SyntaxError
+SyntaxError