Skip to content

Commit ffa8b12

Browse files
authored
Merge pull request #782 from markshannon/python-add-more-tests
Python: Add more tests
2 parents d735c36 + 0ea2d56 commit ffa8b12

28 files changed

+4513
-1
lines changed

python/ql/src/Statements/ExecUsed.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ string message() {
1919
}
2020

2121
predicate exec_function_call(Call c) {
22-
major_version() = 3 and exists(GlobalVariable exec | exec = ((Name)c.getFunc()).getVariable() and exec.getId() = "exec")
22+
exists(GlobalVariable exec | exec = ((Name)c.getFunc()).getVariable() and exec.getId() = "exec")
2323
}
2424

2525
from AstNode exec

python/ql/src/semmle/python/TestUtils.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ string remove_prefix_before_substring(string str, string sub) {
2222
string remove_library_prefix(Location loc) {
2323
result = remove_prefix_before_substring(loc.toString(), "resources/lib")
2424
}
25+
26+
/** Returns the location of an AST node in compact form: `basename:line:column` */
27+
string compact_location(AstNode a) {
28+
exists(Location l |
29+
l = a.getLocation() |
30+
result = l.getFile().getBaseName() + ":" + l.getStartLine() + ":" + l.getStartColumn()
31+
)
32+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
| Module flowtest | 5 |
2+
| Module imports | 0 |

python/ql/test/library-tests/ControlFlow/general/Lines.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
| Function try_except | 7 |
99
| Function try_finally | 7 |
1010
| Module flowtest | 70 |
11+
| Module imports | 4 |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from foo import x, y
2+
import bar
3+
from baz import x as a, y as b
4+
import spam as eggs

python/ql/test/library-tests/ControlFlow/successors/Successors.expected

Lines changed: 3290 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import python
2+
import semmle.python.TestUtils
3+
4+
from ControlFlowNode p, ControlFlowNode s, string what
5+
where
6+
s = p.getAFalseSuccessor() and what = "false"
7+
or
8+
s = p.getATrueSuccessor() and what = "true"
9+
or
10+
s = p.getAnExceptionalSuccessor() and what = "exceptional"
11+
or
12+
s = p.getANormalSuccessor() and what = "normal"
13+
or
14+
// Add fake edges for node that raise out of scope
15+
p.isExceptionalExit(_) and s = p.getScope().getEntryNode() and what = "exit"
16+
17+
select compact_location(p.getNode()), p.getNode().toString(),
18+
compact_location(s.getNode()), s.getNode().toString(), what

0 commit comments

Comments
 (0)