Skip to content

Commit a9d45a2

Browse files
committed
C#: Add some tests for cs/useless-if-statement.
1 parent 795a2e1 commit a9d45a2

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
3+
class FutileConditionalTest
4+
{
5+
6+
public void M(string s)
7+
{
8+
if (s.Length > 0) ; // $ Alert
9+
10+
if (s.Length > 1)
11+
{
12+
} // $ Alert
13+
14+
if (s.Length > 2) // GOOD: because of else-branch
15+
{
16+
}
17+
else
18+
{
19+
Console.WriteLine("hello");
20+
}
21+
22+
if (s.Length > 3)
23+
{
24+
}
25+
else
26+
{
27+
} // $ Alert
28+
}
29+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| FutileConditional.cs:8:9:8:27 | if (...) ... | If-statement with an empty then-branch and no else-branch. |
2+
| FutileConditional.cs:10:9:12:9 | if (...) ... | If-statement with an empty then-branch and no else-branch. |
3+
| FutileConditional.cs:22:9:27:9 | if (...) ... | If-statement with an empty then-branch and no else-branch. |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
query: Useless code/FutileConditional.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
semmle-extractor-options: /nostdlib /noconfig
2+
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj

0 commit comments

Comments
 (0)