forked from SonarSource/sonar-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add C# 9 tests for S3877 , S1067 , S4226 (SonarSource#3750)
- Loading branch information
1 parent
c285b29
commit 809b0f7
Showing
7 changed files
with
123 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...narAnalyzer.UnitTest/TestCases/ExceptionShouldNotBeThrownFromUnexpectedMethods.CSharp9.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Tests.Diagnostics | ||
{ | ||
record Record1 : IDisposable | ||
{ | ||
static Record1() => throw new NotImplementedException(); | ||
public void Dispose() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
record Record2 : IDisposable | ||
{ | ||
static Record2() => throw new Exception(); // FN, needs support for throw expressions | ||
|
||
[ModuleInitializer] | ||
internal static void M1() | ||
{ | ||
throw new Exception(); // FN | ||
} | ||
|
||
event EventHandler OnSomething | ||
{ | ||
add | ||
{ | ||
throw new Exception(); // Noncompliant | ||
} | ||
remove | ||
{ | ||
throw new InvalidOperationException(); // Compliant | ||
} | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
throw new Exception(); // Noncompliant | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
throw new Exception(); // Noncompliant | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/ExpressionComplexity.CSharp9.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var d1 = true && false && true && false && true && true; // Noncompliant | ||
|
||
object x = null; | ||
|
||
if (x is true or true or true or true or true) { } // FN | ||
|
||
if (x is true and true and true and true and true) { } // FN | ||
|
||
if (x is 10 or 20 or 40 or 50 or 60 or 70) { } // FN | ||
|
||
if (x is < 10 or < 20 or < 30 and (40 or 50 or 60)) { } // FN |
29 changes: 29 additions & 0 deletions
29
...ts/SonarAnalyzer.UnitTest/TestCases/ExtensionMethodShouldBeInSeparateNamespace.CSharp9.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var isTopLevelFile = true; | ||
|
||
public record GlobalRecord { } | ||
|
||
public static class GlobalExtensions | ||
{ | ||
public static void Bar(this GlobalRecord r) { } // Noncompliant | ||
} | ||
|
||
namespace MyLibrary | ||
{ | ||
public record Foo { } | ||
} | ||
namespace Helpers | ||
{ | ||
public static class MyExtensions | ||
{ | ||
public static void Bar(this MyLibrary.Foo foo) { } | ||
public static void Bar(this GlobalRecord foo) { } | ||
} | ||
} | ||
namespace Same | ||
{ | ||
public record R { } | ||
public static class Extensions | ||
{ | ||
public static void Bar(this R r) { } // Noncompliant | ||
} | ||
} |