Skip to content

Commit 29fe942

Browse files
committed
Shared: Make test post-processor for custom query predicates
Expands the scope of inline test expectations post-processor to support .ql files with no `@kind` but with a bunch of unary or binary query predicates, which each correspond to a tag.
1 parent a54e732 commit 29fe942

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

shared/util/codeql/util/test/InlineExpectationsTest.qll

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,13 @@ module TestPostProcessing {
739739
bindingset[result]
740740
string getARelevantTag() { any() }
741741

742-
predicate tagMatches = PathProblemSourceTestInput::tagMatches/2;
742+
bindingset[expectedTag, actualTag]
743+
predicate tagMatches(string expectedTag, string actualTag) {
744+
PathProblemSourceTestInput::tagMatches(expectedTag, actualTag)
745+
or
746+
not exists(getQueryKind()) and
747+
expectedTag = actualTag
748+
}
743749

744750
bindingset[expectedTag]
745751
predicate tagIsOptional(string expectedTag) {
@@ -751,6 +757,9 @@ module TestPostProcessing {
751757
queryId = expectedTag.regexpCapture(getTagRegex(), 3) and
752758
queryId != getQueryId()
753759
)
760+
or
761+
not exists(getQueryKind()) and
762+
expectedTag = ["Alert", "Source", "Sink"]
754763
}
755764

756765
private predicate hasPathProblemSource = PathProblemSourceTestInput::hasPathProblemSource/5;
@@ -779,6 +788,22 @@ module TestPostProcessing {
779788
)
780789
}
781790

791+
private predicate hasCustomQueryPredicateResult(
792+
Input::Location location, string tag, string value
793+
) {
794+
not exists(getQueryKind()) and
795+
exists(int row |
796+
queryResults(tag, row, 0, Input2::getRelativeUrl(location)) and
797+
not tag = [mainResultSet(), "nodes", "edges", "subpaths"] and
798+
(
799+
queryResults(tag, row, 2, value)
800+
or
801+
not queryResults(tag, row, 2, _) and
802+
value = ""
803+
)
804+
)
805+
}
806+
782807
/**
783808
* Gets the expected value for result row `row`, if any. This value must
784809
* match the value at the corresponding path-problem source (if it is
@@ -805,6 +830,9 @@ module TestPostProcessing {
805830
or
806831
value = getValue(row)
807832
)
833+
or
834+
hasCustomQueryPredicateResult(location, tag, value) and
835+
element = ""
808836
}
809837
}
810838

0 commit comments

Comments
 (0)