mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
40 lines
1.3 KiB
Plaintext
40 lines
1.3 KiB
Plaintext
import python
|
|
import semmle.python.dataflow.new.DataFlow
|
|
import utils.test.InlineExpectationsTest
|
|
private import semmle.python.dataflow.new.internal.PrintNode
|
|
|
|
signature module FlowTestSig {
|
|
string flowTag();
|
|
|
|
predicate relevantFlow(DataFlow::Node fromNode, DataFlow::Node toNode);
|
|
}
|
|
|
|
module MakeTestSig<FlowTestSig Impl> implements TestSig {
|
|
string getARelevantTag() { result = Impl::flowTag() }
|
|
|
|
predicate hasActualResult(Location location, string element, string tag, string value) {
|
|
exists(DataFlow::Node fromNode, DataFlow::Node toNode | Impl::relevantFlow(fromNode, toNode) |
|
|
location = toNode.getLocation() and
|
|
tag = Impl::flowTag() and
|
|
value =
|
|
"\"" + prettyNode(fromNode).replaceAll("\"", "'") + lineStr(fromNode, toNode) + " -> " +
|
|
prettyNode(toNode).replaceAll("\"", "'") + "\"" and
|
|
element = toNode.toString()
|
|
)
|
|
}
|
|
|
|
pragma[inline]
|
|
private string lineStr(DataFlow::Node fromNode, DataFlow::Node toNode) {
|
|
exists(int delta |
|
|
delta = fromNode.getLocation().getStartLine() - toNode.getLocation().getStartLine()
|
|
|
|
|
if delta = 0
|
|
then result = ""
|
|
else
|
|
if delta > 0
|
|
then result = ", l:+" + delta.toString()
|
|
else result = ", l:" + delta.toString()
|
|
)
|
|
}
|
|
}
|