Skip to content

Commit 6d9745e

Browse files
committed
Python: Rewrite call-graph tests to be inline expectation (2/2)
I ported the predicates showing difference between points-to and type-tracking, since it's helpful to see the list of differences, instead of having to parse expectations!
1 parent 4caaa3a commit 6d9745e

13 files changed

+48
-292
lines changed

python/ql/test/experimental/library-tests/CallGraph/CallGraphTest.qll

Lines changed: 0 additions & 147 deletions
This file was deleted.

python/ql/test/experimental/library-tests/CallGraph/InlineCallGraphTest.expected

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,21 @@ failures
22
debug_callableNotUnique
33
| code/class_advanced.py:18:5:18:18 | Function arg | Qualified function name 'B.arg' is not unique. Please fix. |
44
| code/class_advanced.py:23:5:23:25 | Function arg | Qualified function name 'B.arg' is not unique. Please fix. |
5+
pointsTo_found_typeTracker_notFound
6+
| code/class_simple.py:28:1:28:15 | ControlFlowNode for Attribute() | A.some_method |
7+
| code/class_simple.py:30:1:30:21 | ControlFlowNode for Attribute() | A.some_staticmethod |
8+
| code/class_simple.py:32:1:32:20 | ControlFlowNode for Attribute() | A.some_classmethod |
9+
| code/class_simple.py:35:1:35:21 | ControlFlowNode for Attribute() | A.some_staticmethod |
10+
| code/class_simple.py:37:1:37:20 | ControlFlowNode for Attribute() | A.some_classmethod |
11+
| code/runtime_decision.py:18:1:18:6 | ControlFlowNode for func() | rd_bar |
12+
| code/runtime_decision.py:18:1:18:6 | ControlFlowNode for func() | rd_foo |
13+
| code/runtime_decision.py:26:1:26:7 | ControlFlowNode for func2() | rd_bar |
14+
| code/runtime_decision.py:26:1:26:7 | ControlFlowNode for func2() | rd_foo |
15+
| code/simple.py:15:1:15:5 | ControlFlowNode for foo() | foo |
16+
| code/simple.py:16:1:16:14 | ControlFlowNode for indirect_foo() | foo |
17+
| code/simple.py:17:1:17:5 | ControlFlowNode for bar() | bar |
18+
| code/simple.py:18:1:18:5 | ControlFlowNode for lam() | lambda[simple.py:12:7] |
19+
| code/underscore_prefix_func_name.py:18:5:18:19 | ControlFlowNode for some_function() | some_function |
20+
| code/underscore_prefix_func_name.py:21:5:21:19 | ControlFlowNode for some_function() | some_function |
21+
| code/underscore_prefix_func_name.py:24:1:24:21 | ControlFlowNode for _works_since_called() | _works_since_called |
22+
typeTracker_found_pointsTo_notFound

python/ql/test/experimental/library-tests/CallGraph/InlineCallGraphTest.ql

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,41 @@ class CallGraphTest extends InlineExpectationsTest {
2828
|
2929
location = call.getLocation() and
3030
element = call.toString() and
31-
(
32-
// note: `target.getQualifiedName` for Lambdas is just "lambda", so is not very useful :|
33-
not target.isLambda() and
34-
value = target.getQualifiedName()
35-
or
36-
target.isLambda() and
37-
value =
38-
"lambda[" + target.getLocation().getFile().getShortName() + ":" +
39-
target.getLocation().getStartLine() + ":" + target.getLocation().getStartColumn() + "]"
40-
)
31+
value = betterQualName(target)
4132
)
4233
}
4334
}
4435

36+
bindingset[func]
37+
string betterQualName(Function func) {
38+
// note: `target.getQualifiedName` for Lambdas is just "lambda", so is not very useful :|
39+
not func.isLambda() and
40+
result = func.getQualifiedName()
41+
or
42+
func.isLambda() and
43+
result =
44+
"lambda[" + func.getLocation().getFile().getShortName() + ":" +
45+
func.getLocation().getStartLine() + ":" + func.getLocation().getStartColumn() + "]"
46+
}
47+
4548
query predicate debug_callableNotUnique(Function callable, string message) {
4649
exists(Function f | f != callable and f.getQualifiedName() = callable.getQualifiedName()) and
4750
message =
4851
"Qualified function name '" + callable.getQualifiedName() + "' is not unique. Please fix."
4952
}
53+
54+
query predicate pointsTo_found_typeTracker_notFound(CallNode call, string qualname) {
55+
exists(Function target |
56+
pointsToCallEdge(call, target) and
57+
not typeTrackerCallEdge(call, target) and
58+
qualname = betterQualName(target)
59+
)
60+
}
61+
62+
query predicate typeTracker_found_pointsTo_notFound(CallNode call, string qualname) {
63+
exists(Function target |
64+
not pointsToCallEdge(call, target) and
65+
typeTrackerCallEdge(call, target) and
66+
qualname = betterQualName(target)
67+
)
68+
}

python/ql/test/experimental/library-tests/CallGraph/PointsTo.expected

Lines changed: 0 additions & 6 deletions
This file was deleted.

python/ql/test/experimental/library-tests/CallGraph/PointsTo.ql

Lines changed: 0 additions & 10 deletions
This file was deleted.

python/ql/test/experimental/library-tests/CallGraph/README.md

Lines changed: 0 additions & 38 deletions
This file was deleted.

python/ql/test/experimental/library-tests/CallGraph/Relative.expected

Lines changed: 0 additions & 20 deletions
This file was deleted.

python/ql/test/experimental/library-tests/CallGraph/Relative.ql

Lines changed: 0 additions & 14 deletions
This file was deleted.

python/ql/test/experimental/library-tests/CallGraph/TypeTracker.expected

Lines changed: 0 additions & 21 deletions
This file was deleted.

python/ql/test/experimental/library-tests/CallGraph/TypeTracker.ql

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)