Add meta-tests for inline expectation with related locations

This commit is contained in:
Asger F
2025-02-25 11:58:54 +01:00
parent 694f01ab78
commit ae161f1654
8 changed files with 75 additions and 1 deletions

View File

@@ -16,6 +16,14 @@ class C
// correct expectation comment
x = "Alert"; // $ Alert[problem-query]
// correct expectation comments with a related location
var related = "Related"; // $ RelatedLocation[problem-query-with-related-loc]
x = "Alert:1"; // $ Alert[problem-query-with-related-loc]
// expectation comments missing the related location
related = "Related";
x = "Alert:1"; // $ Alert[problem-query-with-related-loc]
}
void PathProblems()
@@ -78,5 +86,17 @@ class C
// incorrect expectation comments, using an identifier tag; the alert location coincides with the source location
sink = "Sink"; // $ Sink[path-problem-query]=sink2
x = "Alert:0:1"; // $ Alert[path-problem-query]=sink1
// correct expectation comments with a related location
source = "Source"; // $ Source[path-problem-query-with-related-loc]
sink = "Sink"; // $ Sink[path-problem-query-with-related-loc]
var related = "Related"; // $ RelatedLocation[path-problem-query-with-related-loc]
x = "Alert:3:2:1"; // $ Alert[path-problem-query-with-related-loc]
// expectation comments missing the related location
source = "Source"; // $ Source[path-problem-query-with-related-loc]
sink = "Sink"; // $ Sink[path-problem-query-with-related-loc]
related = "Related";
x = "Alert:3:2:1"; // $ Alert[path-problem-query-with-related-loc]
}
}
}

View File

@@ -0,0 +1,14 @@
#select
| InlineTests.cs:94:13:94:25 | "Alert:3:2:1" | InlineTests.cs:91:18:91:25 | "Source" | InlineTests.cs:92:16:92:21 | "Sink" | This is a problem with $@ | InlineTests.cs:93:23:93:31 | "Related" | a related location |
| InlineTests.cs:100:13:100:25 | "Alert:3:2:1" | InlineTests.cs:97:18:97:25 | "Source" | InlineTests.cs:98:16:98:21 | "Sink" | This is a problem with $@ | InlineTests.cs:99:19:99:27 | "Related" | a related location |
edges
testFailures
| InlineTests.cs:6:26:6:35 | // ... | Missing result: Alert |
| InlineTests.cs:12:34:12:43 | // ... | Missing result: Alert |
| InlineTests.cs:32:32:32:42 | // ... | Missing result: Source |
| InlineTests.cs:33:28:33:36 | // ... | Missing result: Sink |
| InlineTests.cs:34:30:34:39 | // ... | Missing result: Alert |
| InlineTests.cs:37:28:37:38 | // ... | Missing result: Source |
| InlineTests.cs:38:24:38:32 | // ... | Missing result: Sink |
| InlineTests.cs:39:33:39:42 | // ... | Missing result: Alert |
| InlineTests.cs:93:34:93:90 | // ... | Missing result: RelatedLocation[path-problem-query-with-related-loc] |

View File

@@ -0,0 +1,2 @@
query: utils/inline-tests/queries/PathProblemQueryRelatedLocs.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -0,0 +1,2 @@
query: utils/inline-tests/queries/ProblemQueryRelatedLocs.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -0,0 +1,2 @@
edges
#select

View File

@@ -0,0 +1,22 @@
/**
* @kind path-problem
* @id path-problem-query-with-related-loc
*/
import csharp
query predicate edges(StringLiteral sl1, StringLiteral sl2) { none() }
from StringLiteral alert, StringLiteral source, StringLiteral sink, StringLiteral related
where
exists(string regexp, int sourceOffset, int sinkOffset, int relatedOffset |
regexp = "Alert:([0-9]+):([0-9]+):([0-9]+)"
|
sourceOffset = alert.getValue().regexpCapture(regexp, 1).toInt() and
sinkOffset = alert.getValue().regexpCapture(regexp, 2).toInt() and
relatedOffset = alert.getValue().regexpCapture(regexp, 3).toInt() and
source.getLocation().getStartLine() = alert.getLocation().getStartLine() - sourceOffset and
sink.getLocation().getStartLine() = alert.getLocation().getStartLine() - sinkOffset and
related.getLocation().getStartLine() = alert.getLocation().getStartLine() - relatedOffset
)
select alert, source, sink, "This is a problem with $@", related, "a related location"

View File

@@ -0,0 +1,12 @@
/**
* @kind problem
* @id problem-query-with-related-locs
*/
import csharp
from StringLiteral sl, StringLiteral related, int offset
where
sl.getValue().regexpCapture("Alert:([0-9]+)", 1).toInt() = offset and
related.getLocation().getStartLine() = sl.getLocation().getStartLine() - offset
select sl, "This is a problem with $@", related, "a related location"