@@ -584,3 +584,68 @@ private string expectationPattern() {
584584 result = tags + "(?:=" + value + ")?"
585585 )
586586}
587+
588+ /**
589+ * Provides logic for creating a `@kind test-postprocess` query that checks
590+ * inline test expectations using `$ BAD` markers.
591+ */
592+ module TestPostProcessing {
593+ external predicate queryResults ( string relation , int row , int column , string data ) ;
594+
595+ external predicate queryRelations ( string relation ) ;
596+
597+ signature module InputSig< InlineExpectationsTestSig Input> {
598+ string getRelativeUrl ( Input:: Location location ) ;
599+ }
600+
601+ module Make< InlineExpectationsTestSig Input, InputSig< Input > Input2> {
602+ private import InlineExpectationsTest as InlineExpectationsTest
603+ private import InlineExpectationsTest:: Make< Input >
604+
605+ private module TestInput implements TestSig {
606+ string getARelevantTag ( ) { result = "BAD" }
607+
608+ predicate hasActualResult ( Input:: Location location , string element , string tag , string value ) {
609+ exists ( int row , string loc |
610+ queryResults ( "#select" , row , 0 , loc ) and
611+ element = "Unexpected result" and
612+ tag = "BAD" and
613+ value = "" and
614+ Input2:: getRelativeUrl ( location ) = loc
615+ )
616+ }
617+ }
618+
619+ private module Test = MakeTest< TestInput > ;
620+
621+ private predicate rankedTestFailures ( int i , Test:: FailureLocatable f ) {
622+ f =
623+ rank [ i ] ( Test:: FailureLocatable f0 , string filename , int startLine , int startColumn ,
624+ int endLine , int endColumn |
625+ f0 .getLocation ( ) .hasLocationInfo ( filename , startLine , startColumn , endLine , endColumn )
626+ |
627+ f0 order by filename , startLine , startColumn , endLine , endColumn
628+ )
629+ }
630+
631+ query predicate results ( string relation , int row , int column , string data ) {
632+ queryResults ( relation , row , column , data )
633+ or
634+ exists ( Test:: FailureLocatable f |
635+ relation = "testFailures" and
636+ rankedTestFailures ( row , f )
637+ |
638+ column = 0 and data = Input2:: getRelativeUrl ( f .getLocation ( ) )
639+ or
640+ column = 1 and data = f .toString ( )
641+ )
642+ }
643+
644+ query predicate resultRelations ( string relation ) {
645+ queryRelations ( relation )
646+ or
647+ Test:: testFailures ( _, _) and
648+ relation = "testFailures"
649+ }
650+ }
651+ }
0 commit comments