Skip to content

Commit 79baaad

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

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,20 @@ 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+
* An expectation with an optional tag acts as a normal expectation, meaning that there
153+
* must be a matching result. In contrast, a result with an optional tag does not require
154+
* a matching expectation.
155+
*/
150156
bindingset[expectedTag]
151157
default predicate tagIsOptional(string expectedTag) { none() }
152158

159+
/** Holds if expectations marked with `expectedTag` should be ignored. */
160+
bindingset[expectedTag]
161+
default predicate ignoreTag(string expectedTag) { none() }
162+
153163
/**
154164
* Holds if expected value `expectedValue` matches actual value `actualValue`.
155165
*
@@ -223,8 +233,7 @@ module Make<InlineExpectationsTestSig Impl> {
223233
exists(ValidTestExpectation expectation |
224234
not exists(ActualTestResult actualResult | expectation.matchesActualResult(actualResult)) and
225235
expectation.getTag() = TestImpl::getARelevantTag() and
226-
element = expectation and
227-
not expectation.isOptional()
236+
element = expectation
228237
|
229238
expectation instanceof GoodTestExpectation and
230239
message = "Missing result: " + expectation.getExpectationText()
@@ -253,7 +262,8 @@ module Make<InlineExpectationsTestSig Impl> {
253262
exists(TColumn column, string tags |
254263
getAnExpectation(comment, column, _, tags, value) and
255264
tag = tags.splitAt(",") and
256-
knownFailure = getColumnString(column)
265+
knownFailure = getColumnString(column) and
266+
not TestImpl::ignoreTag(tag)
257267
)
258268
} or
259269
TInvalidExpectation(Impl::ExpectationComment comment, string expectation) {
@@ -870,7 +880,7 @@ module TestPostProcessing {
870880
}
871881

872882
bindingset[expectedTag]
873-
predicate tagIsOptional(string expectedTag) {
883+
predicate ignoreTag(string expectedTag) {
874884
exists(getQueryKind()) and
875885
(
876886
// ignore irrelevant tags

0 commit comments

Comments
 (0)