mirror of
https://github.com/github/codeql.git
synced 2026-04-20 22:44:52 +02:00
Refactor application-mode tests so we can reuse most of it for framework mode.
This commit is contained in:
@@ -21,6 +21,11 @@ signature module CandidateSig {
|
||||
* Gets the kind of this endpoint, either "sourceModel" or "sinkModel".
|
||||
*/
|
||||
string getExtensibleType();
|
||||
|
||||
/**
|
||||
* Gets a string representation of this endpoint.
|
||||
*/
|
||||
string toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,47 +1,36 @@
|
||||
import java
|
||||
import AutomodelApplicationModeCharacteristics
|
||||
import AutomodelApplicationModeCharacteristics as Characteristics
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
import AutomodelExtractionTests
|
||||
|
||||
module Extraction implements TestSig {
|
||||
string getARelevantTag() {
|
||||
result in ["sourceModel", "sinkModel", "positiveExample", "negativeExample"]
|
||||
module TestHelper implements TestHelperSig<Characteristics::ApplicationCandidatesImpl> {
|
||||
Location getEndpointLocation(Characteristics::Endpoint endpoint) {
|
||||
result = endpoint.asTop().getLocation()
|
||||
}
|
||||
|
||||
additional predicate selectEndpoint(
|
||||
Endpoint endpoint, string name, string signature, string input, string output,
|
||||
string extensibleType, string tag, string suffix
|
||||
predicate isCandidate(
|
||||
Characteristics::Endpoint endpoint, string name, string signature, string input, string output,
|
||||
string extensibleType
|
||||
) {
|
||||
isCandidate(endpoint, _, _, _, name, signature, input, output, _, extensibleType, _) and
|
||||
tag = extensibleType and
|
||||
suffix = ""
|
||||
or
|
||||
isNegativeExample(endpoint, _, _, _, _, _, name, signature, input, output, _, extensibleType) and
|
||||
tag = "negativeExample" and
|
||||
suffix = ""
|
||||
or
|
||||
exists(string endpointType |
|
||||
isPositiveExample(endpoint, endpointType, _, _, _, name, signature, input, output, _,
|
||||
extensibleType) and
|
||||
tag = "positiveExample" and
|
||||
suffix = "(" + endpointType + ")"
|
||||
)
|
||||
Characteristics::isCandidate(endpoint, _, _, _, name, signature, input, output, _,
|
||||
extensibleType, _)
|
||||
}
|
||||
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(
|
||||
Endpoint endpoint, string name, string signature, string input, string output,
|
||||
string extensibleType, string suffix
|
||||
|
|
||||
selectEndpoint(endpoint, name, signature, input, output, extensibleType, tag, suffix)
|
||||
|
|
||||
endpoint.asTop().getLocation() = location and
|
||||
endpoint.toString() = element and
|
||||
// for source models only the output is relevant, and vice versa for sink models
|
||||
if extensibleType = "sourceModel"
|
||||
then value = name + signature + ":" + output + suffix
|
||||
else value = name + signature + ":" + input + suffix
|
||||
)
|
||||
predicate isPositiveExample(
|
||||
Characteristics::Endpoint endpoint, string endpointType, string name, string signature,
|
||||
string input, string output, string extensibleType
|
||||
) {
|
||||
Characteristics::isPositiveExample(endpoint, endpointType, _, _, _, name, signature, input,
|
||||
output, _, extensibleType)
|
||||
}
|
||||
|
||||
predicate isNegativeExample(
|
||||
Characteristics::Endpoint endpoint, string name, string signature, string input, string output,
|
||||
string extensibleType
|
||||
) {
|
||||
Characteristics::isNegativeExample(endpoint, _, _, _, _, _, name, signature, input, output, _,
|
||||
extensibleType)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<Extraction>
|
||||
import MakeTest<Extraction<Characteristics::ApplicationCandidatesImpl, TestHelper>>
|
||||
|
||||
64
java/ql/automodel/test/AutomodelExtractionTests.qll
Normal file
64
java/ql/automodel/test/AutomodelExtractionTests.qll
Normal file
@@ -0,0 +1,64 @@
|
||||
import java
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
import AutomodelSharedCharacteristics
|
||||
|
||||
signature module TestHelperSig<CandidateSig Candidate> {
|
||||
Location getEndpointLocation(Candidate::Endpoint e);
|
||||
|
||||
predicate isCandidate(
|
||||
Candidate::Endpoint e, string name, string signature, string input, string output,
|
||||
string extensibleType
|
||||
);
|
||||
|
||||
predicate isPositiveExample(
|
||||
Candidate::Endpoint e, string endpointType, string name, string signature, string input,
|
||||
string output, string extensibleType
|
||||
);
|
||||
|
||||
predicate isNegativeExample(
|
||||
Candidate::Endpoint e, string name, string signature, string input, string output,
|
||||
string extensibleType
|
||||
);
|
||||
}
|
||||
|
||||
module Extraction<CandidateSig Candidate, TestHelperSig<Candidate> TestHelper> implements TestSig {
|
||||
string getARelevantTag() {
|
||||
result in ["sourceModel", "sinkModel", "positiveExample", "negativeExample"]
|
||||
}
|
||||
|
||||
additional predicate selectEndpoint(
|
||||
Candidate::Endpoint endpoint, string name, string signature, string input, string output,
|
||||
string extensibleType, string tag, string suffix
|
||||
) {
|
||||
TestHelper::isCandidate(endpoint, name, signature, input, output, extensibleType) and
|
||||
tag = extensibleType and
|
||||
suffix = ""
|
||||
or
|
||||
TestHelper::isNegativeExample(endpoint, name, signature, input, output, extensibleType) and
|
||||
tag = "negativeExample" and
|
||||
suffix = ""
|
||||
or
|
||||
exists(string endpointType |
|
||||
TestHelper::isPositiveExample(endpoint, endpointType, name, signature, input, output,
|
||||
extensibleType) and
|
||||
tag = "positiveExample" and
|
||||
suffix = "(" + endpointType + ")"
|
||||
)
|
||||
}
|
||||
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(
|
||||
Candidate::Endpoint endpoint, string name, string signature, string input, string output,
|
||||
string extensibleType, string suffix
|
||||
|
|
||||
selectEndpoint(endpoint, name, signature, input, output, extensibleType, tag, suffix)
|
||||
|
|
||||
TestHelper::getEndpointLocation(endpoint) = location and
|
||||
endpoint.toString() = element and
|
||||
// for source models only the output is relevant, and vice versa for sink models
|
||||
if extensibleType = "sourceModel"
|
||||
then value = name + signature + ":" + output + suffix
|
||||
else value = name + signature + ":" + input + suffix
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user