From 572e7128306c5fc643682a50376204c591df6ea2 Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Wed, 29 Apr 2026 09:55:16 +0200 Subject: [PATCH] Shared: Adjust semantics of optional inline expectation tags --- .../util/test/InlineExpectationsTest.qll | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/shared/util/codeql/util/test/InlineExpectationsTest.qll b/shared/util/codeql/util/test/InlineExpectationsTest.qll index 0d4bb3d9710d..d954df726b41 100644 --- a/shared/util/codeql/util/test/InlineExpectationsTest.qll +++ b/shared/util/codeql/util/test/InlineExpectationsTest.qll @@ -146,10 +146,19 @@ module Make { bindingset[expectedTag, actualTag] default predicate tagMatches(string expectedTag, string actualTag) { expectedTag = actualTag } - /** Holds if expectations marked with `expectedTag` are optional. */ + /** + * Holds if expectations marked with `expectedTag` are optional. + * + * Results with an optional tag will not cause a failure if there is no matching expectation, + * but any expectation with an optional tag must have a matching result. + */ bindingset[expectedTag] default predicate tagIsOptional(string expectedTag) { none() } + /** Holds if expectations marked with `expectedTag` should be ignored. */ + bindingset[expectedTag] + default predicate ignoreTag(string expectedTag) { none() } + /** * Holds if expected value `expectedValue` matches actual value `actualValue`. * @@ -223,8 +232,7 @@ module Make { exists(ValidTestExpectation expectation | not exists(ActualTestResult actualResult | expectation.matchesActualResult(actualResult)) and expectation.getTag() = TestImpl::getARelevantTag() and - element = expectation and - not expectation.isOptional() + element = expectation | expectation instanceof GoodTestExpectation and message = "Missing result: " + expectation.getExpectationText() @@ -253,7 +261,8 @@ module Make { exists(TColumn column, string tags | getAnExpectation(comment, column, _, tags, value) and tag = tags.splitAt(",") and - knownFailure = getColumnString(column) + knownFailure = getColumnString(column) and + not TestImpl::ignoreTag(tag) ) } or TInvalidExpectation(Impl::ExpectationComment comment, string expectation) { @@ -870,7 +879,7 @@ module TestPostProcessing { } bindingset[expectedTag] - predicate tagIsOptional(string expectedTag) { + predicate ignoreTag(string expectedTag) { exists(getQueryKind()) and ( // ignore irrelevant tags