Python: add tests for short-circuiting comparisons · ravvas/codeql@9b4de2b · GitHub
Skip to content

Commit 9b4de2b

Browse files
committed
Python: add tests for short-circuiting comparisons
- Both the old and new CFG model this incorrectly right now. - Added ConsecutivePredecessorTimestamps.ql for the old CFG for symmetry.
1 parent 3206ab0 commit 9b4de2b

6 files changed

Lines changed: 75 additions & 1 deletion
Lines changed: 13 additions & 0 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Checks that each annotated node (except the minimum timestamp) has a
3+
* predecessor annotation with timestamp `a - 1`. This is the reverse of
4+
* ConsecutiveTimestamps: it catches nodes that are reachable but arrived
5+
* at from the wrong place (skipping an intermediate node).
6+
*
7+
* Only applies to functions where all annotations are in the function's
8+
* own scope (excludes tests with generators, async, comprehensions, or
9+
* lambdas that have annotations in nested scopes).
10+
*/
11+
12+
import OldCfgImpl
13+
14+
private module Utils = EvalOrderCfgUtils<OldCfg>;
15+
16+
private import Utils
17+
private import Utils::CfgTests
18+
19+
from TimerAnnotation ann, int a
20+
where consecutivePredecessorTimestamps(ann, a)
21+
select ann, "$@ in $@ has no consecutive predecessor (expected " + (a - 1) + ")",
22+
ann.getTimestampExpr(a), "Timestamp " + a, ann.getTestFunction(), ann.getTestFunction().getName()

‎python/ql/test/library-tests/ControlFlow/evaluation-order/ConsecutiveTimestamps.expected‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| test_boolean.py:52:11:52:47 | BoolExpr | $@ in $@ has no consecutive successor (expected 3) | test_boolean.py:52:63:52:63 | IntegerLiteral | Timestamp 2 | test_boolean.py:50:1:50:25 | Function test_mixed_and_or | test_mixed_and_or |
88
| test_boolean.py:52:27:52:31 | False | $@ in $@ has no consecutive successor (expected 2) | test_boolean.py:52:37:52:37 | IntegerLiteral | Timestamp 1 | test_boolean.py:50:1:50:25 | Function test_mixed_and_or | test_mixed_and_or |
99
| test_boolean.py:52:78:52:79 | IntegerLiteral | $@ in $@ has no consecutive successor (expected 4) | test_boolean.py:52:85:52:85 | IntegerLiteral | Timestamp 3 | test_boolean.py:50:1:50:25 | Function test_mixed_and_or | test_mixed_and_or |
10+
| test_comparison.py:37:17:37:17 | IntegerLiteral | $@ in $@ has no consecutive successor (expected 2) | test_comparison.py:37:23:37:23 | IntegerLiteral | Timestamp 1 | test_comparison.py:32:1:32:32 | Function test_three_short_circuit | test_three_short_circuit |
1011
| test_if.py:95:9:95:13 | False | $@ in $@ has no consecutive successor (expected 2) | test_if.py:95:19:95:19 | IntegerLiteral | Timestamp 1 | test_if.py:93:1:93:34 | Function test_if_compound_condition | test_if_compound_condition |
1112
| test_if.py:96:9:96:29 | BoolExpr | $@ in $@ has no consecutive successor (expected 5) | test_if.py:96:36:96:36 | IntegerLiteral | Timestamp 4 | test_if.py:93:1:93:34 | Function test_if_compound_condition | test_if_compound_condition |
1213
| test_if.py:96:22:96:22 | y | $@ in $@ has no consecutive successor (expected 4) | test_if.py:96:28:96:28 | IntegerLiteral | Timestamp 3 | test_if.py:93:1:93:34 | Function test_if_compound_condition | test_if_compound_condition |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
| test_comparison.py:37:6:37:41 | Compare | $@ in $@ has no consecutive predecessor (expected 1) | test_comparison.py:37:48:37:48 | IntegerLiteral | Timestamp 2 | test_comparison.py:32:1:32:32 | Function test_three_short_circuit | test_three_short_circuit |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test_comparison.py:37:17:37:17 | IntegerLiteral | $@ in $@ has no consecutive successor (expected 2) | test_comparison.py:37:23:37:23 | IntegerLiteral | Timestamp 1 | test_comparison.py:32:1:32:32 | Function test_three_short_circuit | test_three_short_circuit |
Lines changed: 37 additions & 0 deletions

0 commit comments

Comments
 (0)