Skip to content

Commit 45ab723

Browse files
committed
Python: Add dataflow test for a,b = b,a
Also enables a single test to output more than one OK
1 parent ceddc24 commit 45ab723

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

python/ql/test/experimental/dataflow/coverage/dataflow.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ edges
131131
| test.py:276:28:276:33 | ControlFlowNode for SOURCE | test.py:276:10:276:34 | ControlFlowNode for second() |
132132
| test.py:335:12:335:17 | ControlFlowNode for SOURCE | test.py:335:10:335:18 | ControlFlowNode for f() |
133133
| test.py:339:28:339:33 | ControlFlowNode for SOURCE | test.py:339:10:339:34 | ControlFlowNode for second() |
134+
| test.py:372:9:372:14 | ControlFlowNode for SOURCE | test.py:374:10:374:10 | ControlFlowNode for a |
135+
| test.py:372:9:372:14 | ControlFlowNode for SOURCE | test.py:379:10:379:10 | ControlFlowNode for b |
134136
nodes
135137
| datamodel.py:13:1:13:6 | GSSA Variable SOURCE | semmle.label | GSSA Variable SOURCE |
136138
| datamodel.py:13:10:13:17 | ControlFlowNode for Str | semmle.label | ControlFlowNode for Str |
@@ -260,6 +262,9 @@ nodes
260262
| test.py:335:12:335:17 | ControlFlowNode for SOURCE | semmle.label | ControlFlowNode for SOURCE |
261263
| test.py:339:10:339:34 | ControlFlowNode for second() | semmle.label | ControlFlowNode for second() |
262264
| test.py:339:28:339:33 | ControlFlowNode for SOURCE | semmle.label | ControlFlowNode for SOURCE |
265+
| test.py:372:9:372:14 | ControlFlowNode for SOURCE | semmle.label | ControlFlowNode for SOURCE |
266+
| test.py:374:10:374:10 | ControlFlowNode for a | semmle.label | ControlFlowNode for a |
267+
| test.py:379:10:379:10 | ControlFlowNode for b | semmle.label | ControlFlowNode for b |
263268
#select
264269
| datamodel.py:38:6:38:17 | ControlFlowNode for f() | datamodel.py:13:10:13:17 | ControlFlowNode for Str | datamodel.py:38:6:38:17 | ControlFlowNode for f() | <message> |
265270
| datamodel.py:38:6:38:17 | ControlFlowNode for f() | datamodel.py:38:8:38:13 | ControlFlowNode for SOURCE | datamodel.py:38:6:38:17 | ControlFlowNode for f() | <message> |
@@ -301,3 +306,5 @@ nodes
301306
| test.py:276:10:276:34 | ControlFlowNode for second() | test.py:276:28:276:33 | ControlFlowNode for SOURCE | test.py:276:10:276:34 | ControlFlowNode for second() | <message> |
302307
| test.py:335:10:335:18 | ControlFlowNode for f() | test.py:335:12:335:17 | ControlFlowNode for SOURCE | test.py:335:10:335:18 | ControlFlowNode for f() | <message> |
303308
| test.py:339:10:339:34 | ControlFlowNode for second() | test.py:339:28:339:33 | ControlFlowNode for SOURCE | test.py:339:10:339:34 | ControlFlowNode for second() | <message> |
309+
| test.py:374:10:374:10 | ControlFlowNode for a | test.py:372:9:372:14 | ControlFlowNode for SOURCE | test.py:374:10:374:10 | ControlFlowNode for a | <message> |
310+
| test.py:379:10:379:10 | ControlFlowNode for b | test.py:372:9:372:14 | ControlFlowNode for SOURCE | test.py:379:10:379:10 | ControlFlowNode for b | <message> |

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,14 @@ def test_lambda_extra_keyword():
366366
def test_lambda_extra_keyword_flow():
367367
f_extra_keyword_flow = lambda **a : [*a][0] # return the name of the first extra keyword argument
368368
SINK(f_extra_keyword_flow(**{SOURCE: None})) # Flow missing
369+
370+
371+
def test_swap():
372+
a = SOURCE
373+
b = NONSOURCE
374+
SINK(a)
375+
SINK_F(b)
376+
377+
a, b = b, a
378+
SINK_F(a)
379+
SINK(b)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
def check_output(s, f):
2-
if s == "OK\n":
1+
def check_output(outtext, f):
2+
if all(s == "OK" for s in outtext.splitlines()):
33
pass
44
else:
5-
raise RuntimeError("Function failed", s, f)
5+
raise RuntimeError("Function failed", outtext, f)
66

77
def check_test_function(f):
88
from io import StringIO

0 commit comments

Comments
 (0)