Skip to content

Commit 28472ae

Browse files
committed
Test: Don't expect 'Source' tag when source and alert are on same line
Previously the Source tag was required if the source and alert did not have the exact same location. This relaxes the restriction to being on the same line. Note that in order to be "on the same line" both start and end lines have to match. It's still possible for a given line to expect both Alert and Source tags, in case the source pairs up with another alert on a different line.
1 parent 1066b88 commit 28472ae

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

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

+27-2
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,29 @@ module TestPostProcessing {
645645
private import InlineExpectationsTest as InlineExpectationsTest
646646
private import InlineExpectationsTest::Make<Input>
647647

648+
bindingset[loc]
649+
private predicate parseLocation(
650+
string loc, string file, int startLine, int startColumn, int endLine, int endColumn
651+
) {
652+
exists(string regexp |
653+
regexp = "(.*):(-?\\d+):(-?\\d+):(-?\\d+):(-?\\d+)" and
654+
file = loc.regexpCapture(regexp, 1) and
655+
startLine = loc.regexpCapture(regexp, 2).toInt() and
656+
startColumn = loc.regexpCapture(regexp, 3).toInt() and
657+
endLine = loc.regexpCapture(regexp, 4).toInt() and
658+
endColumn = loc.regexpCapture(regexp, 5).toInt()
659+
)
660+
}
661+
662+
/** Holds if the given location strings refer to the same lines, but possibly with different column numbers. */
663+
bindingset[loc1, loc2]
664+
private predicate sameLineInfo(string loc1, string loc2) {
665+
exists(string file, int line1, int line2 |
666+
parseLocation(loc1, file, line1, _, line2, _) and
667+
parseLocation(loc2, file, line1, _, line2, _)
668+
)
669+
}
670+
648671
/**
649672
* Gets the tag to be used for the path-problem source at result row `row`.
650673
*
@@ -653,8 +676,10 @@ module TestPostProcessing {
653676
*/
654677
private string getSourceTag(int row) {
655678
getQueryKind() = "path-problem" and
656-
exists(string loc | queryResults(mainResultSet(), row, 2, loc) |
657-
if queryResults(mainResultSet(), row, 0, loc) then result = "Alert" else result = "Source"
679+
exists(string sourceLoc, string selectLoc |
680+
queryResults(mainResultSet(), row, 0, selectLoc) and
681+
queryResults(mainResultSet(), row, 2, sourceLoc) and
682+
if sameLineInfo(selectLoc, sourceLoc) then result = "Alert" else result = "Source"
658683
)
659684
}
660685

0 commit comments

Comments
 (0)