From cdec7ba30ed6d527c2d007b7fd37413f0c71a1fd Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 22 Dec 2016 11:26:06 +1100 Subject: [PATCH] tests: Add a coverage test for printing the parse-tree. --- tests/cmdline/cmd_parsetree.py | 11 +++++ tests/cmdline/cmd_parsetree.py.exp | 67 +++++++++++++++++++++++++++++ tests/feature_check/coverage.py | 5 +++ tests/feature_check/coverage.py.exp | 0 tests/run-tests | 4 ++ 5 files changed, 87 insertions(+) create mode 100644 tests/cmdline/cmd_parsetree.py create mode 100644 tests/cmdline/cmd_parsetree.py.exp create mode 100644 tests/feature_check/coverage.py create mode 100644 tests/feature_check/coverage.py.exp diff --git a/tests/cmdline/cmd_parsetree.py b/tests/cmdline/cmd_parsetree.py new file mode 100644 index 0000000000..5f698eeae3 --- /dev/null +++ b/tests/cmdline/cmd_parsetree.py @@ -0,0 +1,11 @@ +# cmdline: -v -v -v +# test printing of the parse-tree + +for i in (): + pass +a = None +b = 'str' +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 diff --git a/tests/cmdline/cmd_parsetree.py.exp b/tests/cmdline/cmd_parsetree.py.exp new file mode 100644 index 0000000000..06fbeadfc8 --- /dev/null +++ b/tests/cmdline/cmd_parsetree.py.exp @@ -0,0 +1,67 @@ +---------------- +[ 4] rule(2) (n=8) + tok(5) +[ 4] rule(78) (n=4) + id(i) +[ 4] rule(131) (n=1) + NULL +[ 5] rule(42) (n=0) + NULL +[ 6] rule(32) (n=2) + id(a) + tok(15) +[ 7] rule(32) (n=2) + id(b) + str(str) +[ 8] rule(32) (n=2) + id(c) +[ 8] literal str(a very long str that will not be interned) +[ 9] rule(32) (n=2) + id(d) + bytes(bytes) +[ 10] rule(32) (n=2) + id(e) +[ 10] literal bytes(a very long bytes that will not be interned) +[ 11] rule(32) (n=2) + id(f) +[ 11] literal \.\+ +---------------- +File cmdline/cmd_parsetree.py, code block '' (descriptor: \.\+, bytecode @\.\+ bytes) +Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+): +######## +\.\+5b +arg names: +(N_STATE 2) +(N_EXC_STACK 0) + bc=-1 line=1 + bc=0 line=4 + bc=9 line=5 + bc=12 line=6 + bc=16 line=7 + bc=22 line=8 + bc=27 line=9 + bc=32 line=10 + bc=37 line=11 +00 BUILD_TUPLE 0 +02 GET_ITER +03 FOR_ITER 12 +06 STORE_NAME i +09 JUMP 3 +12 LOAD_CONST_NONE +13 STORE_NAME a +16 LOAD_CONST_STRING 'str' +19 STORE_NAME b +22 LOAD_CONST_OBJ \.\+ +24 STORE_NAME c +27 LOAD_CONST_OBJ \.\+ +29 STORE_NAME d +32 LOAD_CONST_OBJ \.\+ +34 STORE_NAME e +37 LOAD_CONST_OBJ \.\+ +39 STORE_NAME f +42 LOAD_CONST_NONE +43 RETURN_VALUE +mem: total=\\d\+, current=\\d\+, peak=\\d\+ +stack: \\d\+ out of \\d\+ +GC: total: \\d\+, used: \\d\+, free: \\d\+ + No. of 1-blocks: \\d\+, 2-blocks: \\d\+, max blk sz: \\d\+, max free sz: \\d\+ diff --git a/tests/feature_check/coverage.py b/tests/feature_check/coverage.py new file mode 100644 index 0000000000..dcda53eae2 --- /dev/null +++ b/tests/feature_check/coverage.py @@ -0,0 +1,5 @@ +try: + extra_coverage + print('coverage') +except NameError: + print('no') diff --git a/tests/feature_check/coverage.py.exp b/tests/feature_check/coverage.py.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/run-tests b/tests/run-tests index 1a686584c3..d142c998cf 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -208,6 +208,7 @@ def run_tests(pyb, tests, args): upy_byteorder = run_micropython(pyb, args, 'feature_check/byteorder.py') has_complex = run_micropython(pyb, args, 'feature_check/complex.py') == b'complex\n' + has_coverage = run_micropython(pyb, args, 'feature_check/coverage.py') == b'coverage\n' cpy_byteorder = subprocess.check_output([CPYTHON3, 'feature_check/byteorder.py']) skip_endian = (upy_byteorder != cpy_byteorder) @@ -225,6 +226,9 @@ def run_tests(pyb, tests, args): skip_tests.add('float/true_value.py') skip_tests.add('float/types.py') + if not has_coverage: + skip_tests.add('cmdline/cmd_parsetree.py') + # Some tests shouldn't be run on a PC if pyb is None: # unix build does not have the GIL so can't run thread mutation tests