@@ -643,21 +643,118 @@ module TestPostProcessing {
643
643
644
644
module Make< InlineExpectationsTestSig Input, InputSig< Input > Input2> {
645
645
private import InlineExpectationsTest as InlineExpectationsTest
646
- private import InlineExpectationsTest:: Make< Input >
646
+
647
+ bindingset [ loc]
648
+ private predicate parseLocationString (
649
+ string loc , string relativePath , int sl , int sc , int el , int ec
650
+ ) {
651
+ relativePath = loc .splitAt ( ":" , 0 ) and
652
+ sl = loc .splitAt ( ":" , 1 ) .toInt ( ) and
653
+ sc = loc .splitAt ( ":" , 2 ) .toInt ( ) and
654
+ el = loc .splitAt ( ":" , 3 ) .toInt ( ) and
655
+ ec = loc .splitAt ( ":" , 4 ) .toInt ( )
656
+ }
657
+
658
+ pragma [ nomagic]
659
+ private string getRelativePathTo ( string absolutePath ) {
660
+ exists ( Input:: Location loc |
661
+ loc .hasLocationInfo ( absolutePath , _, _, _, _) and
662
+ result = Input2:: getRelativeUrl ( loc ) .splitAt ( ":" , 0 )
663
+ )
664
+ }
665
+
666
+ private newtype TTestLocation =
667
+ MkInputLocation ( Input:: Location loc ) or
668
+ MkResultLocation ( string relativePath , int sl , int sc , int el , int ec ) {
669
+ exists ( string data |
670
+ queryResults ( _, _, _, data ) and
671
+ parseLocationString ( data , relativePath , sl , sc , el , ec ) and
672
+ not Input2:: getRelativeUrl ( _) = data // avoid duplicate locations
673
+ )
674
+ }
675
+
676
+ /**
677
+ * A location that is either an `Input::Location` or a location from an alert.
678
+ *
679
+ * We use this location type to support queries that select a location that does not correspond
680
+ * to an instance of `Input::Location`.
681
+ */
682
+ abstract private class TestLocationImpl extends TTestLocation {
683
+ string getAbsoluteFile ( ) { this .hasLocationInfo ( result , _, _, _, _) }
684
+
685
+ int getStartLine ( ) { this .hasLocationInfo ( _, result , _, _, _) }
686
+
687
+ int getStartColumn ( ) { this .hasLocationInfo ( _, _, result , _, _) }
688
+
689
+ int getEndLine ( ) { this .hasLocationInfo ( _, _, _, result , _) }
690
+
691
+ int getEndColumn ( ) { this .hasLocationInfo ( _, _, _, _, result ) }
692
+
693
+ abstract string getRelativeUrl ( ) ;
694
+
695
+ abstract string toString ( ) ;
696
+
697
+ abstract predicate hasLocationInfo ( string file , int sl , int sc , int el , int ec ) ;
698
+ }
699
+
700
+ private class LocationFromResult extends TestLocationImpl , MkResultLocation {
701
+ override string getRelativeUrl ( ) {
702
+ exists ( string file , int sl , int sc , int el , int ec |
703
+ this = MkResultLocation ( file , sl , sc , el , ec ) and
704
+ result = file + ":" + sl + ":" + sc + ":" + el + ":" + ec
705
+ )
706
+ }
707
+
708
+ override string toString ( ) { result = this .getRelativeUrl ( ) }
709
+
710
+ override predicate hasLocationInfo ( string file , int sl , int sc , int el , int ec ) {
711
+ this = MkResultLocation ( getRelativePathTo ( file ) , sl , sc , el , ec )
712
+ }
713
+ }
714
+
715
+ private class LocationFromInput extends TestLocationImpl , MkInputLocation {
716
+ private Input:: Location loc ;
717
+
718
+ LocationFromInput ( ) { this = MkInputLocation ( loc ) }
719
+
720
+ override string getRelativeUrl ( ) { result = Input2:: getRelativeUrl ( loc ) }
721
+
722
+ override string toString ( ) { result = this .getRelativeUrl ( ) }
723
+
724
+ override predicate hasLocationInfo ( string file , int sl , int sc , int el , int ec ) {
725
+ loc .hasLocationInfo ( file , sl , sc , el , ec )
726
+ }
727
+ }
728
+
729
+ final class TestLocation = TestLocationImpl ;
730
+
731
+ module TestImpl2 implements InlineExpectationsTestSig {
732
+ final class Location = TestLocation ;
733
+
734
+ class ExpectationComment instanceof Input:: ExpectationComment {
735
+ string getContents ( ) { result = super .getContents ( ) }
736
+
737
+ Location getLocation ( ) { result = MkInputLocation ( super .getLocation ( ) ) }
738
+
739
+ string toString ( ) { result = super .toString ( ) }
740
+ }
741
+ }
742
+
743
+ private import InlineExpectationsTest:: Make< TestImpl2 >
647
744
648
745
/** Holds if the given locations refer to the same lines, but possibly with different column numbers. */
649
746
bindingset [ loc1, loc2]
650
747
pragma [ inline_late]
651
- private predicate sameLineInfo ( Input :: Location loc1 , Input :: Location loc2 ) {
748
+ private predicate sameLineInfo ( TestLocation loc1 , TestLocation loc2 ) {
652
749
exists ( string file , int line1 , int line2 |
653
750
loc1 .hasLocationInfo ( file , line1 , _, line2 , _) and
654
751
loc2 .hasLocationInfo ( file , line1 , _, line2 , _)
655
752
)
656
753
}
657
754
658
755
pragma [ nomagic]
659
- private predicate mainQueryResult ( int row , int column , Input :: Location loc ) {
660
- queryResults ( mainResultSet ( ) , row , column , Input2 :: getRelativeUrl ( loc ) )
756
+ private predicate mainQueryResult ( int row , int column , TestLocation loc ) {
757
+ queryResults ( mainResultSet ( ) , row , column , loc . getRelativeUrl ( ) )
661
758
}
662
759
663
760
/**
@@ -668,7 +765,7 @@ module TestPostProcessing {
668
765
*/
669
766
private string getSourceTag ( int row ) {
670
767
getQueryKind ( ) = "path-problem" and
671
- exists ( Input :: Location sourceLoc , Input :: Location selectLoc |
768
+ exists ( TestLocation sourceLoc , TestLocation selectLoc |
672
769
mainQueryResult ( row , 0 , selectLoc ) and
673
770
mainQueryResult ( row , 2 , sourceLoc ) and
674
771
if sameLineInfo ( selectLoc , sourceLoc ) then result = "Alert" else result = "Source"
@@ -733,7 +830,7 @@ module TestPostProcessing {
733
830
}
734
831
735
832
additional predicate hasPathProblemSource (
736
- int row , Input :: Location location , string element , string tag , string value
833
+ int row , TestLocation location , string element , string tag , string value
737
834
) {
738
835
getQueryKind ( ) = "path-problem" and
739
836
mainQueryResult ( row , 2 , location ) and
@@ -742,7 +839,7 @@ module TestPostProcessing {
742
839
value = ""
743
840
}
744
841
745
- predicate hasActualResult ( Input :: Location location , string element , string tag , string value ) {
842
+ predicate hasActualResult ( TestLocation location , string element , string tag , string value ) {
746
843
hasPathProblemSource ( _, location , element , tag , value )
747
844
}
748
845
}
@@ -770,15 +867,15 @@ module TestPostProcessing {
770
867
private predicate hasPathProblemSource = PathProblemSourceTestInput:: hasPathProblemSource / 5 ;
771
868
772
869
private predicate hasPathProblemSink (
773
- int row , Input :: Location location , string element , string tag
870
+ int row , TestLocation location , string element , string tag
774
871
) {
775
872
getQueryKind ( ) = "path-problem" and
776
873
mainQueryResult ( row , 4 , location ) and
777
874
queryResults ( mainResultSet ( ) , row , 5 , element ) and
778
875
tag = getSinkTag ( row )
779
876
}
780
877
781
- private predicate hasAlert ( int row , Input :: Location location , string element , string tag ) {
878
+ private predicate hasAlert ( int row , TestLocation location , string element , string tag ) {
782
879
getQueryKind ( ) = [ "problem" , "path-problem" ] and
783
880
mainQueryResult ( row , 0 , location ) and
784
881
queryResults ( mainResultSet ( ) , row , 2 , element ) and
@@ -793,15 +890,15 @@ module TestPostProcessing {
793
890
* present).
794
891
*/
795
892
private string getValue ( int row ) {
796
- exists ( Input :: Location location , string element , string tag , string val |
893
+ exists ( TestLocation location , string element , string tag , string val |
797
894
hasPathProblemSource ( row , location , element , tag , val ) and
798
895
result =
799
896
PathProblemSourceTest:: getAMatchingExpectation ( location , element , tag , val , false )
800
897
.getValue ( )
801
898
)
802
899
}
803
900
804
- predicate hasActualResult ( Input :: Location location , string element , string tag , string value ) {
901
+ predicate hasActualResult ( TestLocation location , string element , string tag , string value ) {
805
902
exists ( int row |
806
903
hasPathProblemSource ( row , location , element , tag , _)
807
904
or
@@ -840,7 +937,7 @@ module TestPostProcessing {
840
937
rankedTestFailures ( row , f ) and
841
938
f = MkTestFailure ( fl , message )
842
939
|
843
- column = 0 and data = Input2 :: getRelativeUrl ( fl .getLocation ( ) )
940
+ column = 0 and data = fl .getLocation ( ) . getRelativeUrl ( )
844
941
or
845
942
column = 1 and data = fl .toString ( )
846
943
or
0 commit comments