Skip to content

Commit e67515f

Browse files
committed
python: dataflow tests names in exception handlers
1 parent a7e394b commit e67515f

File tree

7 files changed

+127
-6
lines changed

7 files changed

+127
-6
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
missingAnnotationOnSink
2+
failures
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import python
2+
import experimental.dataflow.TestUtil.NormalDataflowTest
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
uniqueEnclosingCallable
2+
uniqueType
3+
uniqueNodeLocation
4+
missingLocation
5+
uniqueNodeToString
6+
missingToString
7+
parameterCallable
8+
localFlowIsLocal
9+
compatibleTypesReflexive
10+
unreachableNodeCCtx
11+
localCallNodes
12+
postIsNotPre
13+
postHasUniquePre
14+
uniquePostUpdate
15+
postIsInSameCallable
16+
reverseRead
17+
argHasPostUpdate
18+
postWithInFlow
19+
viableImplInCallContextTooLarge
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import semmle.python.dataflow.new.internal.DataFlowImplConsistency::Consistency
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# This should cover all the syntactical constructs that we hope to support.
2+
# Headings refer to https://docs.python.org/3/reference/expressions.html,
3+
# and are selected whenever they incur dataflow.
4+
# Intended sources should be the variable `SOURCE` and intended sinks should be
5+
# arguments to the function `SINK` (see python/ql/test/experimental/dataflow/testConfig.qll).
6+
#
7+
# Functions whose name ends with "_with_local_flow" will also be tested for local flow.
8+
#
9+
# All functions starting with "test_" should run and execute `print("OK")` exactly once.
10+
# This can be checked by running validTest.py.
11+
12+
import sys
13+
import os
14+
15+
sys.path.append(os.path.dirname(os.path.dirname((__file__))))
16+
from testlib import expects
17+
18+
# These are defined so that we can evaluate the test code.
19+
NONSOURCE = "not a source"
20+
SOURCE = "source"
21+
22+
23+
def is_source(x):
24+
return x == "source" or x == b"source" or x == 42 or x == 42.0 or x == 42j
25+
26+
27+
def SINK(x):
28+
if is_source(x):
29+
print("OK")
30+
else:
31+
print("Unexpected flow", x)
32+
33+
34+
def SINK_F(x):
35+
if is_source(x):
36+
print("Unexpected flow", x)
37+
else:
38+
print("OK")
39+
40+
def test_as_binding():
41+
try:
42+
e_with_source = Exception()
43+
e_with_source.a = SOURCE
44+
raise e_with_source
45+
except Exception as e:
46+
SINK(e.a) # $ MISSING: flow
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# This should cover all the syntactical constructs that we hope to support.
2+
# Headings refer to https://docs.python.org/3/reference/expressions.html,
3+
# and are selected whenever they incur dataflow.
4+
# Intended sources should be the variable `SOURCE` and intended sinks should be
5+
# arguments to the function `SINK` (see python/ql/test/experimental/dataflow/testConfig.qll).
6+
#
7+
# Functions whose name ends with "_with_local_flow" will also be tested for local flow.
8+
#
9+
# All functions starting with "test_" should run and execute `print("OK")` exactly once.
10+
# This can be checked by running validTest.py.
11+
12+
import sys
13+
import os
14+
15+
sys.path.append(os.path.dirname(os.path.dirname((__file__))))
16+
from testlib import expects
17+
18+
# These are defined so that we can evaluate the test code.
19+
NONSOURCE = "not a source"
20+
SOURCE = "source"
21+
22+
23+
def is_source(x):
24+
return x == "source" or x == b"source" or x == 42 or x == 42.0 or x == 42j
25+
26+
27+
def SINK(x):
28+
if is_source(x):
29+
print("OK")
30+
else:
31+
print("Unexpected flow", x)
32+
33+
34+
def SINK_F(x):
35+
if is_source(x):
36+
print("Unexpected flow", x)
37+
else:
38+
print("OK")
39+
40+
def test_as_binding():
41+
try:
42+
e_with_source = Exception()
43+
e_with_source.a = SOURCE
44+
raise e_with_source
45+
except* Exception as e:
46+
SINK(e.a) # $ MISSING: flow

python/ql/test/experimental/dataflow/validTest.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ def check_tests_valid(testFile):
5151
check_async_test_function(item)
5252

5353

54+
def check_tests_valid_after_version(testFile, version):
55+
56+
if sys.version_info[:2] >= version:
57+
print("INFO: Will run tests in", testFile, "since we're running Python", version, "or newer")
58+
check_tests_valid(testFile)
59+
else:
60+
print("WARN: Will not run tests in", testFile, "since we're running Python", sys.version_info[:2], "and need", version, "or newer")
61+
5462
if __name__ == "__main__":
5563
check_tests_valid("coverage.classes")
5664
check_tests_valid("coverage.test")
@@ -60,12 +68,9 @@ def check_tests_valid(testFile):
6068
check_tests_valid("variable-capture.dict")
6169
check_tests_valid("module-initialization.multiphase")
6270
check_tests_valid("fieldflow.test")
63-
64-
if sys.version_info[:2] >= (3, 10):
65-
print("INFO: Will run `match` tests since we're running Python 3.10 or newer")
66-
check_tests_valid("match.test")
67-
else:
68-
print("WARN: Skipping `match` tests since we're not running 3.10 or newer")
71+
check_tests_valid_after_version("match.test", (3, 10))
72+
check_tests_valid("exceptions.test")
73+
check_tests_valid_after_version("exceptions.test_group", (3, 11))
6974

7075
# The below fails when trying to import modules
7176
# check_tests_valid("module-initialization.test")

0 commit comments

Comments
 (0)