File tree Expand file tree Collapse file tree 1 file changed +64
-0
lines changed
python/ql/test/experimental/dataflow/variable-capture Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Here we test the case where a captured variable is being read.
2
+
3
+ # All functions starting with "test_" should run and execute `print("OK")` exactly once.
4
+ # This can be checked by running validTest.py.
5
+
6
+ import sys
7
+ import os
8
+
9
+ sys .path .append (os .path .dirname (os .path .dirname ((__file__ ))))
10
+ from testlib import expects
11
+
12
+ # These are defined so that we can evaluate the test code.
13
+ NONSOURCE = "not a source"
14
+ SOURCE = "source"
15
+
16
+ def is_source (x ):
17
+ return x == "source" or x == b"source" or x == 42 or x == 42.0 or x == 42j
18
+
19
+
20
+ def SINK (x ):
21
+ if is_source (x ):
22
+ print ("OK" )
23
+ else :
24
+ print ("Unexpected flow" , x )
25
+
26
+
27
+ def SINK_F (x ):
28
+ if is_source (x ):
29
+ print ("Unexpected flow" , x )
30
+ else :
31
+ print ("OK" )
32
+
33
+ l = [NONSOURCE ]
34
+ SINK_F (l_mod [0 ])
35
+
36
+ l_mod = [SOURCE for x in l ]
37
+ SINK (l_mod [0 ]) #$ captured
38
+
39
+ l_mod_lambda = [(lambda a : SOURCE )(x ) for x in l ]
40
+ SINK (l_mod_lambda [0 ]) #$ captured
41
+
42
+ def mod (x ):
43
+ return SOURCE
44
+
45
+ l_mod_function = [mod (x ) for x in l ]
46
+ SINK (l_mod_function [0 ]) #$ captured
47
+
48
+ def mod_list (l ):
49
+ def mod_local (x ):
50
+ return SOURCE
51
+
52
+ return [mod_local (x ) for x in l ]
53
+
54
+ l_modded = mod_list (l )
55
+ SINK (l_modded [0 ]) #$ MISSING: captured
56
+
57
+ def mod_list_first (l ):
58
+ def mod_local (x ):
59
+ return SOURCE
60
+
61
+ return [mod_local (l [0 ])]
62
+
63
+ l_modded_first = mod_list_first (l )
64
+ SINK (l_modded_first [0 ]) #$ captured
You can’t perform that action at this time.
0 commit comments