From 35a759dc1dae33d62d005fe44f3cda4599a3c297 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 19 Dec 2017 16:13:00 +1100 Subject: [PATCH] tests: Add some more tests to improve coverage of py/parse.c. --- tests/basics/errno1.py | 4 ++++ tests/basics/errno1.py.exp | 1 + tests/basics/int_constfolding.py | 6 ++++++ tests/basics/syntaxerror.py | 4 ++++ tests/cmdline/cmd_parsetree.py | 1 + tests/cmdline/cmd_parsetree.py.exp | 12 +++++++++--- 6 files changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/basics/errno1.py b/tests/basics/errno1.py index 63930b767f..d7a5ccd542 100644 --- a/tests/basics/errno1.py +++ b/tests/basics/errno1.py @@ -15,3 +15,7 @@ print(msg[:7], msg[-5:]) # check that unknown errno is still rendered print(str(OSError(9999))) + +# this tests a failed constant lookup in errno +errno = uerrno +print(errno.__name__) diff --git a/tests/basics/errno1.py.exp b/tests/basics/errno1.py.exp index c3703df4a2..7dd22757dd 100644 --- a/tests/basics/errno1.py.exp +++ b/tests/basics/errno1.py.exp @@ -1,3 +1,4 @@ [Errno ] EIO 9999 +uerrno diff --git a/tests/basics/int_constfolding.py b/tests/basics/int_constfolding.py index 7bb5383785..158897f553 100644 --- a/tests/basics/int_constfolding.py +++ b/tests/basics/int_constfolding.py @@ -29,3 +29,9 @@ print(123 // 7, 123 % 7) print(-123 // 7, -123 % 7) print(123 // -7, 123 % -7) print(-123 // -7, -123 % -7) + +# won't fold so an exception can be raised at runtime +try: + 1 << -1 +except ValueError: + print('ValueError') diff --git a/tests/basics/syntaxerror.py b/tests/basics/syntaxerror.py index 4161de017b..843459f0bf 100644 --- a/tests/basics/syntaxerror.py +++ b/tests/basics/syntaxerror.py @@ -29,6 +29,10 @@ test_syntax(" a\n") # malformed integer literal (parser error) test_syntax("123z") +# input doesn't match the grammar (parser error) +test_syntax('1 or 2 or') +test_syntax('{1:') + # can't assign to literals test_syntax("1 = 2") test_syntax("'' = 1") diff --git a/tests/cmdline/cmd_parsetree.py b/tests/cmdline/cmd_parsetree.py index 5f698eeae3..da36c80703 100644 --- a/tests/cmdline/cmd_parsetree.py +++ b/tests/cmdline/cmd_parsetree.py @@ -9,3 +9,4 @@ c = 'a very long str that will not be interned' d = b'bytes' e = b'a very long bytes that will not be interned' f = 123456789012345678901234567890 +g = 123 diff --git a/tests/cmdline/cmd_parsetree.py.exp b/tests/cmdline/cmd_parsetree.py.exp index d9f81d8d4c..12a1bfbe90 100644 --- a/tests/cmdline/cmd_parsetree.py.exp +++ b/tests/cmdline/cmd_parsetree.py.exp @@ -1,5 +1,5 @@ ---------------- -[ 4] rule(1) (n=8) +[ 4] rule(1) (n=9) tok(4) [ 4] rule(22) (n=4) id(i) @@ -25,6 +25,9 @@ [ 11] rule(5) (n=2) id(f) [ 11] literal \.\+ +[ 12] rule(5) (n=2) + id(g) + int(123) ---------------- File cmdline/cmd_parsetree.py, code block '' (descriptor: \.\+, bytecode @\.\+ bytes) Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+): @@ -42,6 +45,7 @@ arg names: bc=27 line=9 bc=32 line=10 bc=37 line=11 + bc=42 line=12 00 BUILD_TUPLE 0 02 GET_ITER_STACK 03 FOR_ITER 12 @@ -59,8 +63,10 @@ arg names: 34 STORE_NAME e 37 LOAD_CONST_OBJ \.\+ 39 STORE_NAME f -42 LOAD_CONST_NONE -43 RETURN_VALUE +42 LOAD_CONST_SMALL_INT 123 +45 STORE_NAME g +48 LOAD_CONST_NONE +49 RETURN_VALUE mem: total=\\d\+, current=\\d\+, peak=\\d\+ stack: \\d\+ out of \\d\+ GC: total: \\d\+, used: \\d\+, free: \\d\+