diff options
| author | Damien George | 2015-01-29 00:44:11 +0000 |
|---|---|---|
| committer | Damien George | 2015-01-29 00:44:11 +0000 |
| commit | 12c66be2b8baab093c7be5e2108d2767c9779a69 (patch) | |
| tree | 7db0c4259eaae84cea25d79b3856fc08d863cef1 /tests | |
| parent | 81e70a88a7a4adb33c4a5d049c83f42d94e6332b (diff) | |
tests: Add some tests to improve coverage.
Used gcov to find some parts of vm.c, runtime.c, obj.c that were not
covered by any tests. Still need to use gcov more thoroughly.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/basics/builtin_hash.py | 11 | ||||
| -rw-r--r-- | tests/basics/del_global.py | 18 | ||||
| -rw-r--r-- | tests/basics/del_name.py | 2 | ||||
| -rw-r--r-- | tests/basics/fun_largestate.py | 4 | ||||
| -rw-r--r-- | tests/basics/int1.py | 3 | ||||
| -rw-r--r-- | tests/basics/int_small.py | 9 | ||||
| -rw-r--r-- | tests/basics/unary_op.py | 5 | ||||
| -rw-r--r-- | tests/float/int_power.py | 8 |
8 files changed, 59 insertions, 1 deletions
diff --git a/tests/basics/builtin_hash.py b/tests/basics/builtin_hash.py index c4c7019b4..0abfe980e 100644 --- a/tests/basics/builtin_hash.py +++ b/tests/basics/builtin_hash.py @@ -1,5 +1,16 @@ # test builtin hash function +print(hash(False)) +print(hash(True)) +print({():1}) # hash tuple +print({1 << 66:1}) # hash big int +print(hash in {hash:1}) # hash function + +try: + hash([]) +except TypeError: + print("TypeError") + class A: def __hash__(self): return 123 diff --git a/tests/basics/del_global.py b/tests/basics/del_global.py new file mode 100644 index 000000000..24ecec8e8 --- /dev/null +++ b/tests/basics/del_global.py @@ -0,0 +1,18 @@ +# del global + +def do_del(): + global x + del x + +x = 1 +print(x) +do_del() +try: + print(x) +except NameError: + print("NameError") +try: + do_del() +except: # NameError: + # FIXME uPy returns KeyError for this + print("NameError") diff --git a/tests/basics/del_name.py b/tests/basics/del_name.py index f75a2f5dc..c92be54d3 100644 --- a/tests/basics/del_name.py +++ b/tests/basics/del_name.py @@ -1,4 +1,4 @@ -# del global +# del name x = 1 print(x) diff --git a/tests/basics/fun_largestate.py b/tests/basics/fun_largestate.py index c83f730dc..f13619295 100644 --- a/tests/basics/fun_largestate.py +++ b/tests/basics/fun_largestate.py @@ -129,5 +129,9 @@ def f(): x125 = 1 x126 = 1 +f() + def g(): x = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,] + +g() diff --git a/tests/basics/int1.py b/tests/basics/int1.py index 01e0b0b40..89d4fd9d4 100644 --- a/tests/basics/int1.py +++ b/tests/basics/int1.py @@ -1,3 +1,6 @@ +print(int(False)) +print(int(True)) + print(int(0)) print(int(1)) print(int(+1)) diff --git a/tests/basics/int_small.py b/tests/basics/int_small.py index 1b2c983e2..496e830d2 100644 --- a/tests/basics/int_small.py +++ b/tests/basics/int_small.py @@ -49,6 +49,15 @@ print(a) # This would overflow #a -= 1 +# negative shifts are not allowed +try: + a << -1 +except ValueError: + print("ValueError") +try: + a >> -1 +except ValueError: + print("ValueError") # Shifts to big amounts are undefined behavior in C and is CPU-specific diff --git a/tests/basics/unary_op.py b/tests/basics/unary_op.py index 9846285d5..3084c273e 100644 --- a/tests/basics/unary_op.py +++ b/tests/basics/unary_op.py @@ -1,3 +1,8 @@ +x = 1 +print(+x) +print(-x) +print(~x) + print(not None) print(not False) print(not True) diff --git a/tests/float/int_power.py b/tests/float/int_power.py new file mode 100644 index 000000000..a5a9a5b7a --- /dev/null +++ b/tests/float/int_power.py @@ -0,0 +1,8 @@ +# negative power should produce float + +x = 2 +print(x ** -2) + +x = 3 +x **= -2 +print(x) |
