Skip to content

Commit 572e712

Browse files
committed
Shared: Adjust semantics of optional inline expectation tags
1 parent 1ba9601 commit 572e712

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,19 @@ module Make<InlineExpectationsTestSig Impl> {
146146
bindingset[expectedTag, actualTag]
147147
default predicate tagMatches(string expectedTag, string actualTag) { expectedTag = actualTag }
148148

149-
/** Holds if expectations marked with `expectedTag` are optional. */
149+
/**
150+
* Holds if expectations marked with `expectedTag` are optional.
151+
*
152+
* Results with an optional tag will not cause a failure if there is no matching expectation,
153+
* but any expectation with an optional tag must have a matching result.
154+
*/
150155
bindingset[expectedTag]
151156
default predicate tagIsOptional(string expectedTag) { none() }
152157

158+
/** Holds if expectations marked with `expectedTag` should be ignored. */
159+
bindingset[expectedTag]
160+
default predicate ignoreTag(string expectedTag) { none() }
161+
153162
/**
154163
* Holds if expected value `expectedValue` matches actual value `actualValue`.
155164
*
@@ -223,8 +232,7 @@ module Make<InlineExpectationsTestSig Impl> {
223232
exists(ValidTestExpectation expectation |
224233
not exists(ActualTestResult actualResult | expectation.matchesActualResult(actualResult)) and
225234
expectation.getTag() = TestImpl::getARelevantTag() and
226-
element = expectation and
227-
not expectation.isOptional()
235+
element = expectation
228236
|
229237
expectation instanceof GoodTestExpectation and
230238
message = "Missing result: " + expectation.getExpectationText()
@@ -253,7 +261,8 @@ module Make<InlineExpectationsTestSig Impl> {
253261
exists(TColumn column, string tags |
254262
getAnExpectation(comment, column, _, tags, value) and
255263
tag = tags.splitAt(",") and
256-
knownFailure = getColumnString(column)
264+
knownFailure = getColumnString(column) and
265+
not TestImpl::ignoreTag(tag)
257266
)
258267
} or
259268
TInvalidExpectation(Impl::ExpectationComment comment, string expectation) {
@@ -870,7 +879,7 @@ module TestPostProcessing {
870879
}
871880

872881
bindingset[expectedTag]
873-
predicate tagIsOptional(string expectedTag) {
882+
predicate ignoreTag(string expectedTag) {
874883
exists(getQueryKind()) and
875884
(
876885
// ignore irrelevant tags

0 commit comments

Comments
 (0)