Skip to content

Commit 80f7d58

Browse files
committed
Add missing tests for not-quite-working flow steps
1 parent 7a43bdb commit 80f7d58

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

swift/ql/test/library-tests/dataflow/dataflow/FlowConfig.qll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import swift
66
import codeql.swift.dataflow.DataFlow
7+
import codeql.swift.dataflow.ExternalFlow
78

89
class TestConfiguration extends DataFlow::Configuration {
910
TestConfiguration() { this = "TestConfiguration" }
@@ -14,10 +15,17 @@ class TestConfiguration extends DataFlow::Configuration {
1415

1516
override predicate isSink(DataFlow::Node sink) {
1617
exists(CallExpr sinkCall |
17-
sinkCall.getStaticTarget().getName() = "sink(arg:)" and
18+
sinkCall.getStaticTarget().getName() = ["sink(arg:)", "sink(opt:)"] and
1819
sinkCall.getAnArgument().getExpr() = sink.asExpr()
1920
)
2021
}
2122

2223
override int explorationLimit() { result = 100 }
2324
}
25+
26+
private class TestSummaries extends SummaryModelCsv {
27+
override predicate row(string row) {
28+
// dumb model to allow testing flow through optional chaining (`x?.signum()`)
29+
row = ";Int;true;signum();;;Argument[-1];ReturnValue;value"
30+
}
31+
}

swift/ql/test/library-tests/dataflow/dataflow/test.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,21 @@ func test_computed_property() {
251251
func test_property_wrapper() {
252252
@DidSetSource var x = 42
253253
sink(arg: x) // $ MISSING: flow=243
254-
}
254+
}
255+
256+
func sink(opt: Int?) {}
257+
258+
func optionalSource() -> Int? {
259+
return source()
260+
}
261+
262+
func test_optionals() {
263+
let x = optionalSource()
264+
sink(arg: x!) // $ flow=259
265+
sink(arg: source().signum()) // $ MISSING: flow=259
266+
sink(opt: x?.signum()) // $ MISSING: flow=259
267+
sink(arg: x ?? 0) // $ MISSING: flow=259
268+
if let y = x {
269+
sink(arg: y) // $ MISSING: flow=259
270+
}
271+
}

0 commit comments

Comments
 (0)