@@ -858,17 +858,26 @@ module TestPostProcessing {
858858 bindingset [ result ]
859859 string getARelevantTag ( ) { any ( ) }
860860
861- predicate tagMatches = PathProblemSourceTestInput:: tagMatches / 2 ;
861+ bindingset [ expectedTag, actualTag]
862+ predicate tagMatches ( string expectedTag , string actualTag ) {
863+ PathProblemSourceTestInput:: tagMatches ( expectedTag , actualTag )
864+ or
865+ not exists ( getQueryKind ( ) ) and
866+ expectedTag = actualTag
867+ }
862868
863869 bindingset [ expectedTag]
864870 predicate tagIsOptional ( string expectedTag ) {
865- // ignore irrelevant tags
866- not expectedTag .regexpMatch ( getTagRegex ( ) )
867- or
868- // ignore tags annotated with a query ID that does not match the current query ID
869- exists ( string queryId |
870- queryId = expectedTag .regexpCapture ( getTagRegex ( ) , 3 ) and
871- queryId != getQueryId ( )
871+ exists ( getQueryKind ( ) ) and
872+ (
873+ // ignore irrelevant tags
874+ not expectedTag .regexpMatch ( getTagRegex ( ) )
875+ or
876+ // ignore tags annotated with a query ID that does not match the current query ID
877+ exists ( string queryId |
878+ queryId = expectedTag .regexpCapture ( getTagRegex ( ) , 3 ) and
879+ queryId != getQueryId ( )
880+ )
872881 )
873882 }
874883
@@ -911,6 +920,28 @@ module TestPostProcessing {
911920 not hasPathProblemSink ( row , location , _, _)
912921 }
913922
923+ /**
924+ * Holds if a custom query predicate implies `tag=value` at the given `location`.
925+ *
926+ * Such query predicates are only allowed in kind-less queries, usually in the form
927+ * of a `.ql` file in a test folder, with a same-named `.qlref` file to enable
928+ * post-processing for that test.
929+ */
930+ private predicate hasCustomQueryPredicateResult (
931+ int row , TestLocation location , string element , string tag , string value
932+ ) {
933+ not exists ( getQueryKind ( ) ) and
934+ queryResults ( tag , row , 0 , location .getRelativeUrl ( ) ) and
935+ queryResults ( tag , row , 1 , element ) and
936+ (
937+ queryResults ( tag , row , 2 , value ) and
938+ not queryResults ( tag , row , 3 , _) // ignore if arity is greater than expected
939+ or
940+ not queryResults ( tag , row , 2 , _) and
941+ value = "" // allow value-less expectations for unary predicates
942+ )
943+ }
944+
914945 /**
915946 * Gets the expected value for result row `row`, if any. This value must
916947 * match the value at the corresponding path-problem source (if it is
@@ -939,6 +970,8 @@ module TestPostProcessing {
939970 or
940971 value = getValue ( row )
941972 )
973+ or
974+ hasCustomQueryPredicateResult ( _, location , element , tag , value )
942975 }
943976 }
944977
0 commit comments