Python: Update remaining inline expectation tests to use the paramterized module

This commit is contained in:
Jeroen Ketema
2023-07-02 11:51:30 +02:00
parent 95ddc01ccb
commit abe06e5b95
22 changed files with 143 additions and 162 deletions

View File

@@ -9,7 +9,7 @@ signature module FlowTestSig {
predicate relevantFlow(DataFlow::Node fromNode, DataFlow::Node toNode);
}
private module FlowTest<FlowTestSig Impl> implements TestSig {
module MakeTestSig<FlowTestSig Impl> implements TestSig {
string getARelevantTag() { result = Impl::flowTag() }
predicate hasActualResult(Location location, string element, string tag, string value) {
@@ -37,11 +37,3 @@ private module FlowTest<FlowTestSig Impl> implements TestSig {
)
}
}
module MakeFlowTest<FlowTestSig Impl> {
import MakeTest<FlowTest<Impl>>
}
module MakeFlowTest2<FlowTestSig Impl1, FlowTestSig Impl2> {
import MakeTest<MergeTests<FlowTest<Impl1>, FlowTest<Impl2>>>
}

View File

@@ -10,4 +10,4 @@ module LocalFlowStepTest implements FlowTestSig {
}
}
import MakeFlowTest<LocalFlowStepTest>
import MakeTest<MakeTestSig<LocalFlowStepTest>>

View File

@@ -12,7 +12,7 @@ module MaximalFlowTest implements FlowTestSig {
}
}
import MakeFlowTest<MaximalFlowTest>
import MakeTest<MakeTestSig<MaximalFlowTest>>
/**
* A configuration to find all "maximal" flows.

View File

@@ -11,7 +11,7 @@ module DataFlowTest implements FlowTestSig {
}
}
import MakeFlowTest<DataFlowTest>
import MakeTest<MakeTestSig<DataFlowTest>>
query predicate missingAnnotationOnSink(Location location, string error, string element) {
error = "ERROR, you should add `# $ MISSING: flow` annotation" and

View File

@@ -11,7 +11,7 @@ module DataFlowTest implements FlowTestSig {
}
}
import MakeFlowTest<DataFlowTest>
import MakeTest<MakeTestSig<DataFlowTest>>
query predicate missingAnnotationOnSink(Location location, string error, string element) {
error = "ERROR, you should add `# $ MISSING: flow` annotation" and

View File

@@ -10,22 +10,25 @@ private import semmle.python.dataflow.new.internal.DataFlowPrivate as DataFlowPr
* the functions tested sink their arguments sequentially, that is
* `SINK1(arg1)`, etc.
*/
abstract class RoutingTest extends InlineExpectationsTest {
bindingset[this]
RoutingTest() { any() }
signature module RoutingTestSig {
class Argument;
abstract string flowTag();
string flowTag(Argument arg);
abstract predicate relevantFlow(DataFlow::Node fromNode, DataFlow::Node toNode);
predicate relevantFlow(DataFlow::Node fromNode, DataFlow::Node toNode, Argument arg);
}
override string getARelevantTag() { result in ["func", this.flowTag()] }
module MakeTestSig<RoutingTestSig Impl> implements TestSig {
string getARelevantTag() { result in ["func", Impl::flowTag(_)] }
override predicate hasActualResult(Location location, string element, string tag, string value) {
exists(DataFlow::Node fromNode, DataFlow::Node toNode | this.relevantFlow(fromNode, toNode) |
predicate hasActualResult(Location location, string element, string tag, string value) {
exists(DataFlow::Node fromNode, DataFlow::Node toNode, Impl::Argument arg |
Impl::relevantFlow(fromNode, toNode, arg)
|
location = fromNode.getLocation() and
element = fromNode.toString() and
(
tag = this.flowTag() and
tag = Impl::flowTag(arg) and
if "\"" + tag + "\"" = fromValue(fromNode) then value = "" else value = fromValue(fromNode)
or
// only have result for `func` tag if the function where `arg<n>` is used, is