Skip to content

Commit 7de304b

Browse files
committed
Python: Add proper type-tracking tests for content
Instead of just relying on the call-graph tests
1 parent fa0c4e1 commit 7de304b

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# test of other content types than attributes
2+
3+
def test_tuple(index_arg):
4+
tup = (tracked, other) # $tracked
5+
6+
tup[0] # $ tracked
7+
tup[1]
8+
9+
a,b = tup # $tracked
10+
a # $ tracked
11+
b
12+
13+
# non-precise access is not supported right now (and it's not 100% clear if we want
14+
# to support it, or if it will lead to bad results)
15+
tup[index_arg]
16+
17+
for x in tup:
18+
print(x)
19+
20+
for i in range(len(tup)):
21+
print(tup[i])
22+
23+
24+
def test_dict(key_arg):
25+
d1 = {"t": tracked, "o": other} # $tracked
26+
d1["t"] # $ tracked
27+
d1.get("t") # $ MISSING: tracked
28+
d1.setdefault("t") # $ MISSING: tracked
29+
30+
d1["o"]
31+
d1.get("o")
32+
d1.setdefault("o")
33+
34+
35+
# non-precise access is not supported right now (and it's not 100% clear if we want
36+
# to support it, or if it will lead to bad results)
37+
d1[key_arg]
38+
39+
for k in d1:
40+
d1[k]
41+
42+
for v in d1.values():
43+
v
44+
45+
for k, v in d1.items():
46+
v
47+
48+
49+
# construction with inline updates
50+
d2 = dict()
51+
d2["t"] = tracked # $ tracked
52+
d2["o"] = other
53+
54+
d2["t"] # $ tracked
55+
d2["o"]
56+
57+
# notice that time-travel is also possible (just as with attributes)
58+
d3 = dict()
59+
d3["t"] # $ SPURIOUS: tracked
60+
d3["t"] = tracked # $ tracked
61+
d3["t"] # $ tracked
62+
63+
64+
def test_list(index_arg):
65+
l = [tracked, other] # $tracked
66+
67+
l[0] # $ MISSING: tracked
68+
l[1]
69+
70+
# non-precise access is not supported right now (and it's not 100% clear if we want
71+
# to support it, or if it will lead to bad results)
72+
l[index_arg]
73+
74+
for x in l:
75+
print(x)
76+
77+
for i in range(len(l)):
78+
print(l[i])

python/ql/test/experimental/dataflow/typetracking/tracked.ql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ module TrackedTest implements TestSig {
3030
not e instanceof DataFlow::ScopeEntryDefinitionNode and
3131
// ...same for `SynthCaptureNode`s
3232
not e instanceof DP::SynthCaptureNode and
33+
// after starting to track all kinds of content, we generally just want to show
34+
// annotations after reading the tracked data out again. (we keep the old
35+
// attribute logic to not rewrite all our tests)
36+
(
37+
t.getContent().isNone()
38+
or
39+
t.getContent().asSome() instanceof DataFlow::AttributeContent
40+
) and
3341
tag = "tracked" and
3442
location = e.getLocation() and
3543
value = t.getAttr() and

0 commit comments

Comments
 (0)