mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Python: Add copy of extractor tests
These get to live next to the existing library and query tests, and are run as part of both the Python 2 and Python 3 language tests.
This commit is contained in:
36
python/ql/test/extractor-tests/pruning/Reachable.expected
Normal file
36
python/ql/test/extractor-tests/pruning/Reachable.expected
Normal file
@@ -0,0 +1,36 @@
|
||||
| 5 | reachable | true |
|
||||
| 7 | reachable | true |
|
||||
| 11 | reachable | true |
|
||||
| 13 | reachable | true |
|
||||
| 17 | reachable | true |
|
||||
| 19 | reachable | true |
|
||||
| 23 | reachable | true |
|
||||
| 25 | reachable | true |
|
||||
| 29 | reachable | true |
|
||||
| 31 | unreachable | false |
|
||||
| 35 | reachable | true |
|
||||
| 37 | unreachable | false |
|
||||
| 41 | reachable | true |
|
||||
| 43 | unreachable | false |
|
||||
| 47 | reachable | true |
|
||||
| 49 | reachable | true |
|
||||
| 53 | reachable | true |
|
||||
| 55 | unreachable | false |
|
||||
| 60 | reachable | true |
|
||||
| 62 | reachable | true |
|
||||
| 66 | reachable | true |
|
||||
| 68 | reachable | true |
|
||||
| 72 | reachable | true |
|
||||
| 74 | reachable | true |
|
||||
| 78 | reachable | true |
|
||||
| 80 | reachable | true |
|
||||
| 84 | reachable | true |
|
||||
| 86 | unreachable | false |
|
||||
| 90 | reachable | true |
|
||||
| 92 | unreachable | false |
|
||||
| 96 | reachable | true |
|
||||
| 98 | unreachable | false |
|
||||
| 102 | reachable | true |
|
||||
| 104 | reachable | true |
|
||||
| 108 | reachable | true |
|
||||
| 110 | unreachable | false |
|
||||
8
python/ql/test/extractor-tests/pruning/Reachable.ql
Normal file
8
python/ql/test/extractor-tests/pruning/Reachable.ql
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
import python
|
||||
|
||||
from Name n, GlobalVariable v, boolean reachable
|
||||
where n.getVariable() = v and exists(ExprStmt s | s.getValue() = n) and
|
||||
if exists(ControlFlowNode f | f.getNode() = n) then reachable = true else reachable = false
|
||||
|
||||
select n.getLocation().getStartLine(), v.getId(), reachable
|
||||
3
python/ql/test/extractor-tests/pruning/Test.expected
Normal file
3
python/ql/test/extractor-tests/pruning/Test.expected
Normal file
@@ -0,0 +1,3 @@
|
||||
| comparisons | comparisons.py | 261 |
|
||||
| overflow | overflow.py | 18 |
|
||||
| plurally_dead_edges | plurally_dead_edges.py | 21 |
|
||||
4
python/ql/test/extractor-tests/pruning/Test.ql
Normal file
4
python/ql/test/extractor-tests/pruning/Test.ql
Normal file
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
from Module m
|
||||
select m.getName(), m.getFile().getAbsolutePath(), count(ControlFlowNode n | n.getScope().getEnclosingModule() = m)
|
||||
111
python/ql/test/extractor-tests/pruning/comparisons.py
Normal file
111
python/ql/test/extractor-tests/pruning/comparisons.py
Normal file
@@ -0,0 +1,111 @@
|
||||
|
||||
|
||||
def cmp1(x):
|
||||
if x < 3:
|
||||
reachable
|
||||
if x == 0:
|
||||
reachable
|
||||
|
||||
def cmp2(x):
|
||||
if x == 0:
|
||||
reachable
|
||||
if x < 3:
|
||||
reachable
|
||||
|
||||
def cmp3(x):
|
||||
if x < 3:
|
||||
reachable
|
||||
if x >= 3:
|
||||
reachable
|
||||
|
||||
def cmp4(x):
|
||||
if x < 3:
|
||||
reachable
|
||||
if x > 3:
|
||||
reachable
|
||||
|
||||
def cmp5(x):
|
||||
if x != 3:
|
||||
reachable
|
||||
elif x > 3:
|
||||
unreachable
|
||||
|
||||
def cmp6(x):
|
||||
if x < 3:
|
||||
reachable
|
||||
elif x < 3:
|
||||
unreachable
|
||||
|
||||
def cmp7(x):
|
||||
if x < 3:
|
||||
reachable
|
||||
elif x < 2:
|
||||
unreachable
|
||||
|
||||
def cmp8(x):
|
||||
if x < 3:
|
||||
reachable
|
||||
elif x == 3:
|
||||
reachable
|
||||
|
||||
def cmp9(x):
|
||||
if x < 3:
|
||||
reachable
|
||||
elif x == 2:
|
||||
unreachable
|
||||
|
||||
|
||||
def cmp11(x):
|
||||
if x > 3:
|
||||
reachable
|
||||
if x == 0:
|
||||
reachable
|
||||
|
||||
def cmp12(x):
|
||||
if x == 0:
|
||||
reachable
|
||||
if x > 3:
|
||||
reachable
|
||||
|
||||
def cmp13(x):
|
||||
if x > 3:
|
||||
reachable
|
||||
if x <= 3:
|
||||
reachable
|
||||
|
||||
def cmp14(x):
|
||||
if x > 3:
|
||||
reachable
|
||||
if x < 3:
|
||||
reachable
|
||||
|
||||
def cmp15(x):
|
||||
if x != 3:
|
||||
reachable
|
||||
elif x < 3:
|
||||
unreachable
|
||||
|
||||
def cmp16(x):
|
||||
if x > 3:
|
||||
reachable
|
||||
elif x > 3:
|
||||
unreachable
|
||||
|
||||
def cmp17(x):
|
||||
if x > 3:
|
||||
reachable
|
||||
elif x > 4:
|
||||
unreachable
|
||||
|
||||
def cmp18(x):
|
||||
if x > 3:
|
||||
reachable
|
||||
elif x == 3:
|
||||
reachable
|
||||
|
||||
def cmp19(x):
|
||||
if x > 3:
|
||||
reachable
|
||||
elif x == 4:
|
||||
unreachable
|
||||
|
||||
11
python/ql/test/extractor-tests/pruning/overflow.py
Normal file
11
python/ql/test/extractor-tests/pruning/overflow.py
Normal file
@@ -0,0 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
def func():
|
||||
#Test for overflow in pruning
|
||||
LARGE = 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
if LARGE:
|
||||
func("Some text")
|
||||
if LARGE:
|
||||
func("Some more text")
|
||||
f = 1
|
||||
@@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
|
||||
class Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(Yyyyyyyyyyyyyyyyyyyyyyyy):
|
||||
|
||||
|
||||
def ffffffffffffffffffffffff(self, p, ppppppp=20):
|
||||
|
||||
debug = False # True
|
||||
if debug:
|
||||
print("Some text")
|
||||
if debug:
|
||||
#With splitting, the edge to the print is dead for two different reasons.
|
||||
#But we can only delete it once.
|
||||
print("Some more text")
|
||||
f = 1
|
||||
Reference in New Issue
Block a user