Skip to content

Commit 35a759d

Browse files
committed
tests: Add some more tests to improve coverage of py/parse.c.
1 parent ae1be76 commit 35a759d

6 files changed

Lines changed: 25 additions & 3 deletions

File tree

tests/basics/errno1.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@
1515

1616
# check that unknown errno is still rendered
1717
print(str(OSError(9999)))
18+
19+
# this tests a failed constant lookup in errno
20+
errno = uerrno
21+
print(errno.__name__)

tests/basics/errno1.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<class 'int'>
22
[Errno ] EIO
33
9999
4+
uerrno

tests/basics/int_constfolding.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@
2929
print(-123 // 7, -123 % 7)
3030
print(123 // -7, 123 % -7)
3131
print(-123 // -7, -123 % -7)
32+
33+
# won't fold so an exception can be raised at runtime
34+
try:
35+
1 << -1
36+
except ValueError:
37+
print('ValueError')

tests/basics/syntaxerror.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def test_syntax(code):
2929
# malformed integer literal (parser error)
3030
test_syntax("123z")
3131

32+
# input doesn't match the grammar (parser error)
33+
test_syntax('1 or 2 or')
34+
test_syntax('{1:')
35+
3236
# can't assign to literals
3337
test_syntax("1 = 2")
3438
test_syntax("'' = 1")

tests/cmdline/cmd_parsetree.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
d = b'bytes'
1010
e = b'a very long bytes that will not be interned'
1111
f = 123456789012345678901234567890
12+
g = 123

tests/cmdline/cmd_parsetree.py.exp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
----------------
2-
[ 4] rule(1) (n=8)
2+
[ 4] rule(1) (n=9)
33
tok(4)
44
[ 4] rule(22) (n=4)
55
id(i)
@@ -25,6 +25,9 @@
2525
[ 11] rule(5) (n=2)
2626
id(f)
2727
[ 11] literal \.\+
28+
[ 12] rule(5) (n=2)
29+
id(g)
30+
int(123)
2831
----------------
2932
File cmdline/cmd_parsetree.py, code block '<module>' (descriptor: \.\+, bytecode @\.\+ bytes)
3033
Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+):
@@ -42,6 +45,7 @@ arg names:
4245
bc=27 line=9
4346
bc=32 line=10
4447
bc=37 line=11
48+
bc=42 line=12
4549
00 BUILD_TUPLE 0
4650
02 GET_ITER_STACK
4751
03 FOR_ITER 12
@@ -59,8 +63,10 @@ arg names:
5963
34 STORE_NAME e
6064
37 LOAD_CONST_OBJ \.\+
6165
39 STORE_NAME f
62-
42 LOAD_CONST_NONE
63-
43 RETURN_VALUE
66+
42 LOAD_CONST_SMALL_INT 123
67+
45 STORE_NAME g
68+
48 LOAD_CONST_NONE
69+
49 RETURN_VALUE
6470
mem: total=\\d\+, current=\\d\+, peak=\\d\+
6571
stack: \\d\+ out of \\d\+
6672
GC: total: \\d\+, used: \\d\+, free: \\d\+

0 commit comments

Comments
 (0)