mirror of
https://github.com/github/codeql.git
synced 2025-12-20 10:46:30 +01:00
Python: started adding some coverage tests
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
| test.py:20:9:20:14 | ControlFlowNode for SOURCE | test.py:21:10:21:10 | ControlFlowNode for x |
|
||||
| test.py:25:9:25:16 | ControlFlowNode for Str | test.py:26:10:26:10 | ControlFlowNode for x |
|
||||
| test.py:29:9:29:17 | ControlFlowNode for Str | test.py:30:10:30:10 | ControlFlowNode for x |
|
||||
| test.py:33:9:33:10 | ControlFlowNode for IntegerLiteral | test.py:34:10:34:10 | ControlFlowNode for x |
|
||||
| test.py:37:9:37:12 | ControlFlowNode for FloatLiteral | test.py:38:10:38:10 | ControlFlowNode for x |
|
||||
| test.py:46:10:46:15 | ControlFlowNode for SOURCE | test.py:47:10:47:10 | ControlFlowNode for x |
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
| test.py:12:1:12:33 | GSSA Variable SINK | test.py:15:5:15:8 | ControlFlowNode for SINK |
|
||||
| test.py:12:1:12:33 | GSSA Variable SOURCE | test.py:13:13:13:18 | ControlFlowNode for SOURCE |
|
||||
| test.py:13:5:13:5 | SSA variable x | test.py:12:1:12:33 | Exit node for Function test_tuple_with_local_flow |
|
||||
| test.py:13:5:13:5 | SSA variable x | test.py:14:9:14:9 | ControlFlowNode for x |
|
||||
| test.py:13:10:13:18 | ControlFlowNode for Tuple | test.py:13:5:13:5 | SSA variable x |
|
||||
|
||||
@@ -4,16 +4,91 @@
|
||||
#
|
||||
# Functions whose name ends with "_with_local_flow" will also be tested for local flow.
|
||||
|
||||
# Uncomment these to test the test code
|
||||
# SOURCE = 42
|
||||
# def SINK(x):
|
||||
# return 42
|
||||
# These are included so that we can easily evaluate the test code
|
||||
SOURCE = "source"
|
||||
def SINK(x):
|
||||
print(x)
|
||||
|
||||
def test_tuple_with_local_flow():
|
||||
x = (3, SOURCE)
|
||||
y = x[1]
|
||||
SINK(y)
|
||||
|
||||
# List taken from https://docs.python.org/3/reference/expressions.html
|
||||
# 6.2.1. Identifiers (Names)
|
||||
def test_names():
|
||||
x = SOURCE
|
||||
SINK(x)
|
||||
|
||||
# 6.2.2. Literals
|
||||
def test_string_literal():
|
||||
x = "source"
|
||||
SINK(x)
|
||||
|
||||
def test_bytes_literal():
|
||||
x = b"source"
|
||||
SINK(x)
|
||||
|
||||
def test_integer_literal():
|
||||
x = 42
|
||||
SINK(x)
|
||||
|
||||
def test_floatnumber_literal():
|
||||
x = 42.0
|
||||
SINK(x)
|
||||
|
||||
def test_imagnumber_literal():
|
||||
x = 42j
|
||||
SINK(x)
|
||||
|
||||
# 6.2.3. Parenthesized forms
|
||||
def test_parenthesized_form():
|
||||
x = (SOURCE)
|
||||
SINK(x)
|
||||
|
||||
# 6.2.5. List displays
|
||||
def test_list_display():
|
||||
x = [SOURCE]
|
||||
SINK(x[0])
|
||||
|
||||
def test_list_comprehension():
|
||||
x = [SOURCE for y in [3]]
|
||||
SINK(x[0])
|
||||
|
||||
def test_nested_list_display():
|
||||
x = [* [SOURCE]]
|
||||
SINK(x[0])
|
||||
|
||||
# 6.2.6. Set displays
|
||||
def test_set_display():
|
||||
x = {SOURCE}
|
||||
SINK(x.pop())
|
||||
|
||||
def test_set_comprehension():
|
||||
x = {SOURCE for y in [3]}
|
||||
SINK(x.pop())
|
||||
|
||||
def test_nested_set_display():
|
||||
x = {* {SOURCE}}
|
||||
SINK(x.pop())
|
||||
|
||||
# 6.2.7. Dictionary displays
|
||||
def test_dict_display():
|
||||
x = {"s": SOURCE}
|
||||
SINK(x["s"])
|
||||
|
||||
def test_dict_comprehension():
|
||||
x = {y: SOURCE for y in ["s"]}
|
||||
SINK(x["s"])
|
||||
|
||||
def test_nested_dict_display():
|
||||
x = {** {"s": SOURCE}}
|
||||
SINK(x["s"])
|
||||
|
||||
# 6.2.8. Generator expressions
|
||||
def test_generator():
|
||||
x = (SOURCE for y in [3])
|
||||
SINK([*x][0])
|
||||
|
||||
# List taken from https://docs.python.org/3/reference/expressions.html
|
||||
# 6. Expressions
|
||||
|
||||
@@ -159,9 +159,9 @@ def test_truth():
|
||||
if t:
|
||||
SINK(t)
|
||||
else:
|
||||
SINK(t)
|
||||
SINK(t) # Regression: FP here
|
||||
if not t:
|
||||
SINK(t)
|
||||
SINK(t) # Regression: FP here
|
||||
else:
|
||||
SINK(t)
|
||||
|
||||
|
||||
@@ -9,6 +9,15 @@
|
||||
* SINK(s)
|
||||
* ```
|
||||
* `SOURCE` will be a source and the second occurance of `s` will be a sink.
|
||||
*
|
||||
* In order to test literals, alternative sources are defined for each type:
|
||||
*
|
||||
* for | use
|
||||
* ----------
|
||||
* string | `"source"`
|
||||
* integer | `42`
|
||||
* float | `42.0`
|
||||
* complex | `42j` (not supported yet)
|
||||
*/
|
||||
|
||||
import experimental.dataflow.DataFlow
|
||||
@@ -18,6 +27,13 @@ class TestConfiguration extends DataFlow::Configuration {
|
||||
|
||||
override predicate isSource(DataFlow::Node node) {
|
||||
node.asCfgNode().(NameNode).getId() = "SOURCE"
|
||||
or
|
||||
node.asCfgNode().getNode().(StrConst).getS() = "source"
|
||||
or
|
||||
node.asCfgNode().getNode().(IntegerLiteral).getN() = "42"
|
||||
or
|
||||
node.asCfgNode().getNode().(FloatLiteral).getN() = "42.0"
|
||||
// No support for complex numbers
|
||||
}
|
||||
|
||||
override predicate isSink(DataFlow::Node node) {
|
||||
|
||||
Reference in New Issue
Block a user