Skip to content

Commit f486c44

Browse files
committed
python: library for inline query tests
similar to the consistency queires used in js but based on the inline expectations framework
1 parent c2339b1 commit f486c44

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import python
2+
import experimental.dataflow.TestUtil.FlowTest
3+
private import semmle.python.dataflow.new.internal.PrintNode
4+
5+
class DataFlowQueryTest extends FlowTest {
6+
DataFlowQueryTest() { this = "DataFlowQueryTest" }
7+
8+
override string flowTag() { result = "flow" }
9+
10+
override predicate relevantFlow(DataFlow::Node source, DataFlow::Node sink) {
11+
exists(DataFlow::Configuration cfg | cfg.hasFlow(source, sink))
12+
}
13+
}
14+
15+
query predicate missingAnnotationOnSink(Location location, string error, string element) {
16+
error = "ERROR, you should add `# $ MISSING: flow` annotation" and
17+
exists(DataFlow::Node sink |
18+
exists(DataFlow::Configuration cfg | cfg.isSink(sink)) and
19+
location = sink.getLocation() and
20+
element = prettyExpr(sink.asExpr()) and
21+
not any(DataFlow::Configuration config).hasFlow(_, sink) and
22+
not exists(FalseNegativeExpectation missingResult |
23+
missingResult.getTag() = "flow" and
24+
missingResult.getLocation().getFile() = location.getFile() and
25+
missingResult.getLocation().getStartLine() = location.getStartLine()
26+
)
27+
)
28+
}

0 commit comments

Comments
 (0)