Skip to content

Commit 65c0933

Browse files
committed
C#: Post-processing query for inline test expectations
1 parent da62e81 commit 65c0933

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

csharp/ql/test/TestUtilities/InlineExpectationsTest.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Inline expectation tests for CSharp.
2+
* Inline expectation tests for C#.
33
* See `shared/util/codeql/util/test/InlineExpectationsTest.qll`
44
*/
55

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @kind test-postprocess
3+
*/
4+
5+
private import csharp
6+
private import codeql.util.test.InlineExpectationsTest as T
7+
private import internal.InlineExpectationsTestImpl
8+
import T::TestPostProcessing
9+
import T::TestPostProcessing::Make<Impl, Input>
10+
11+
private module Input implements T::TestPostProcessing::InputSig<Impl> {
12+
string getRelativeUrl(Location location) {
13+
exists(File f, int startline, int startcolumn, int endline, int endcolumn |
14+
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
15+
f = location.getFile()
16+
|
17+
result =
18+
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
19+
)
20+
}
21+
}

csharp/ql/test/query-tests/Useless Code/UnusedLabel/UnusedLabel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ class UnusedLabelTest
33
void F1()
44
{
55
goto a;
6-
a: // GOOD
6+
a: // GOOD
77
;
88
}
99

1010
void F2()
1111
{
12-
a: // BAD
12+
a: // $ Alert
1313
;
1414
}
1515
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| UnusedLabel.cs:12:9:12:9 | a: | This label is not used. |
1+
| UnusedLabel.cs:12:5:12:5 | a: | This label is not used. |
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Useless code/UnusedLabel.ql
1+
query: Useless code/UnusedLabel.ql
2+
postprocess: TestUtilities/InlineExpectationsTestQuery.ql

0 commit comments

Comments
 (0)