mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
C#: Add tests for the inline test post-processor
This commit is contained in:
82
csharp/ql/test/TestUtilities/inline-tests/InlineTests.cs
Normal file
82
csharp/ql/test/TestUtilities/inline-tests/InlineTests.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
class C
|
||||
{
|
||||
void Problems()
|
||||
{
|
||||
// correct expectation comment, but only for `problem-query`
|
||||
var x = "Alert"; // $ Alert
|
||||
|
||||
// irrelevant expectation comment, will be ignored
|
||||
x = "Not an alert"; // $ IrrelevantTag
|
||||
|
||||
// incorrect expectation comment
|
||||
x = "Also not an alert"; // $ Alert
|
||||
|
||||
// missing expectation comment, but only for `problem-query`
|
||||
x = "Alert";
|
||||
|
||||
// correct expectation comment
|
||||
x = "Alert"; // $ Alert[problem-query]
|
||||
}
|
||||
|
||||
void PathProblems()
|
||||
{
|
||||
// correct expectation comments, but only for `path-problem-query`
|
||||
var source = "Source"; // $ Source
|
||||
var sink = "Sink"; // $ Sink
|
||||
var x = "Alert:2:1"; // $ Alert
|
||||
|
||||
// incorrect expectation comments
|
||||
source = "Source"; // $ Source
|
||||
sink = "Sink"; // $ Sink
|
||||
x = "Not an alert:2:1"; // $ Alert
|
||||
|
||||
// missing expectation comments, but only for `path-problem-query`
|
||||
source = "Source";
|
||||
sink = "Sink";
|
||||
x = "Alert:2:1";
|
||||
|
||||
// correct expectation comments
|
||||
source = "Source"; // $ Source[path-problem-query]
|
||||
sink = "Sink"; // $ Sink[path-problem-query]
|
||||
x = "Alert:2:1"; // $ Alert[path-problem-query]
|
||||
|
||||
// correct expectation comments; the alert location coincides with the sink location
|
||||
source = "Source"; // $ Source[path-problem-query]
|
||||
x = "Alert:1:0"; // $ Alert[path-problem-query]
|
||||
|
||||
// correct expectation comments; the alert location coincides with the source location
|
||||
sink = "Sink"; // $ Sink[path-problem-query]
|
||||
x = "Alert:0:1"; // $ Alert[path-problem-query]
|
||||
|
||||
// correct expectation comments, using an identifier tag
|
||||
source = "Source"; // $ Source[path-problem-query]=source1
|
||||
sink = "Sink"; // $ Sink[path-problem-query]=source1
|
||||
x = "Alert:2:1"; // $ Alert[path-problem-query]=source1
|
||||
|
||||
// incorrect expectation comment, using wrong identifier tag at the sink
|
||||
source = "Source"; // $ Source[path-problem-query]=source2
|
||||
sink = "Sink"; // $ Sink[path-problem-query]=source1
|
||||
x = "Alert:2:1"; // $ Alert[path-problem-query]=source2
|
||||
|
||||
// incorrect expectation comment, using wrong identifier tag at the alert
|
||||
source = "Source"; // $ Source[path-problem-query]=source3
|
||||
sink = "Sink"; // $ Sink[path-problem-query]=source3
|
||||
x = "Alert:2:1"; // $ Alert[path-problem-query]=source2
|
||||
|
||||
// correct expectation comments, using an identifier tag; the alert location coincides with the sink location
|
||||
source = "Source"; // $ Source[path-problem-query]=source4
|
||||
x = "Alert:1:0"; // $ Alert[path-problem-query]=source4
|
||||
|
||||
// incorrect expectation comments, using an identifier tag; the alert location coincides with the sink location
|
||||
source = "Source"; // $ Source[path-problem-query]=source5
|
||||
x = "Alert:1:0"; // $ Alert[path-problem-query]=source4
|
||||
|
||||
// correct expectation comments, using an identifier tag; the alert location coincides with the source location
|
||||
sink = "Sink"; // $ Sink[path-problem-query]=sink1
|
||||
x = "Alert:0:1"; // $ Alert[path-problem-query]=sink1
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#select
|
||||
| InlineTests.cs:26:17:26:27 | "Alert:2:1" | InlineTests.cs:24:22:24:29 | "Source" | InlineTests.cs:25:20:25:25 | "Sink" | This is a problem |
|
||||
| InlineTests.cs:36:13:36:23 | "Alert:2:1" | InlineTests.cs:34:18:34:25 | "Source" | InlineTests.cs:35:16:35:21 | "Sink" | This is a problem |
|
||||
| InlineTests.cs:41:13:41:23 | "Alert:2:1" | InlineTests.cs:39:18:39:25 | "Source" | InlineTests.cs:40:16:40:21 | "Sink" | This is a problem |
|
||||
| InlineTests.cs:45:13:45:23 | "Alert:1:0" | InlineTests.cs:44:18:44:25 | "Source" | InlineTests.cs:45:13:45:23 | "Alert:1:0" | This is a problem |
|
||||
| InlineTests.cs:49:13:49:23 | "Alert:0:1" | InlineTests.cs:49:13:49:23 | "Alert:0:1" | InlineTests.cs:48:16:48:21 | "Sink" | This is a problem |
|
||||
| InlineTests.cs:54:13:54:23 | "Alert:2:1" | InlineTests.cs:52:18:52:25 | "Source" | InlineTests.cs:53:16:53:21 | "Sink" | This is a problem |
|
||||
| InlineTests.cs:59:13:59:23 | "Alert:2:1" | InlineTests.cs:57:18:57:25 | "Source" | InlineTests.cs:58:16:58:21 | "Sink" | This is a problem |
|
||||
| InlineTests.cs:64:13:64:23 | "Alert:2:1" | InlineTests.cs:62:18:62:25 | "Source" | InlineTests.cs:63:16:63:21 | "Sink" | This is a problem |
|
||||
| InlineTests.cs:68:13:68:23 | "Alert:1:0" | InlineTests.cs:67:18:67:25 | "Source" | InlineTests.cs:68:13:68:23 | "Alert:1:0" | This is a problem |
|
||||
| InlineTests.cs:72:13:72:23 | "Alert:1:0" | InlineTests.cs:71:18:71:25 | "Source" | InlineTests.cs:72:13:72:23 | "Alert:1:0" | This is a problem |
|
||||
| InlineTests.cs:76:13:76:23 | "Alert:0:1" | InlineTests.cs:76:13:76:23 | "Alert:0:1" | InlineTests.cs:75:16:75:21 | "Sink" | This is a problem |
|
||||
| InlineTests.cs:80:13:80:23 | "Alert:0:1" | InlineTests.cs:80:13:80:23 | "Alert:0:1" | InlineTests.cs:79:16:79:21 | "Sink" | This is a problem |
|
||||
edges
|
||||
testFailures
|
||||
| InlineTests.cs:6:26:6:35 | // ... | Missing result: Alert |
|
||||
| InlineTests.cs:12:34:12:43 | // ... | Missing result: Alert |
|
||||
| InlineTests.cs:29:28:29:38 | // ... | Missing result: Source |
|
||||
| InlineTests.cs:30:24:30:32 | // ... | Missing result: Sink |
|
||||
| InlineTests.cs:31:33:31:42 | // ... | Missing result: Alert |
|
||||
| InlineTests.cs:34:18:34:25 | "Source" | Unexpected result: Source |
|
||||
| InlineTests.cs:35:16:35:21 | "Sink" | Unexpected result: Sink |
|
||||
| InlineTests.cs:36:13:36:23 | InlineTests.cs:34:18:34:25 | Unexpected result: Alert |
|
||||
@@ -0,0 +1,2 @@
|
||||
query: TestUtilities/inline-tests/queries/PathProblemQuery.ql
|
||||
postprocess: TestUtilities/InlineExpectationsTestQuery.ql
|
||||
@@ -0,0 +1,9 @@
|
||||
#select
|
||||
| InlineTests.cs:6:17:6:23 | "Alert" | This is a problem |
|
||||
| InlineTests.cs:15:13:15:19 | "Alert" | This is a problem |
|
||||
| InlineTests.cs:18:13:18:19 | "Alert" | This is a problem |
|
||||
testFailures
|
||||
| InlineTests.cs:12:34:12:43 | // ... | Missing result: Alert |
|
||||
| InlineTests.cs:15:13:15:19 | This is a problem | Unexpected result: Alert |
|
||||
| InlineTests.cs:26:30:26:39 | // ... | Missing result: Alert |
|
||||
| InlineTests.cs:31:33:31:42 | // ... | Missing result: Alert |
|
||||
@@ -0,0 +1,2 @@
|
||||
query: TestUtilities/inline-tests/queries/ProblemQuery.ql
|
||||
postprocess: TestUtilities/InlineExpectationsTestQuery.ql
|
||||
@@ -0,0 +1,2 @@
|
||||
edges
|
||||
#select
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* @kind path-problem
|
||||
* @id path-problem-query
|
||||
*/
|
||||
|
||||
import csharp
|
||||
|
||||
query predicate edges(StringLiteral sl1, StringLiteral sl2) { none() }
|
||||
|
||||
from StringLiteral alert, StringLiteral source, StringLiteral sink
|
||||
where
|
||||
exists(string regexp, int sourceOffset, int sinkOffset | regexp = "Alert:([0-9]+):([0-9]+)" |
|
||||
sourceOffset = alert.getValue().regexpCapture(regexp, 1).toInt() and
|
||||
sinkOffset = alert.getValue().regexpCapture(regexp, 2).toInt() and
|
||||
source.getLocation().getStartLine() = alert.getLocation().getStartLine() - sourceOffset and
|
||||
sink.getLocation().getStartLine() = alert.getLocation().getStartLine() - sinkOffset
|
||||
)
|
||||
select alert, source, sink, "This is a problem"
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @kind problem
|
||||
* @id problem-query
|
||||
*/
|
||||
|
||||
import csharp
|
||||
|
||||
from StringLiteral sl
|
||||
where sl.getValue() = "Alert"
|
||||
select sl, "This is a problem"
|
||||
Reference in New Issue
Block a user