-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes xunit/xunit#2798: xUnit2007 code fix leads to CS8920 compiler e…
…rror (#167)
- Loading branch information
1 parent
79ca4d6
commit 0c15399
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
src/xunit.analyzers.tests/Analyzers/X2000/AssertIsTypeShouldUseGenericOverloadTypeTests.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,86 @@ | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Xunit; | ||
using Verify = CSharpVerifier<Xunit.Analyzers.AssertIsTypeShouldUseGenericOverloadType>; | ||
|
||
public class AssertIsTypeShouldUseGenericOverloadTypeTests | ||
{ | ||
#if NETCOREAPP // static abstract methods are only supported on .NET, not .NET Framework | ||
public class StaticAbstractInterfaceMethods | ||
{ | ||
const string methodCode = "static abstract void Method();"; | ||
const string codeTemplate = @" | ||
using Xunit; | ||
public interface IParentClass {{ | ||
{0} | ||
}} | ||
public interface IClass : IParentClass {{ | ||
{1} | ||
}} | ||
public class Class : IClass {{ | ||
public static void Method() {{ }} | ||
}} | ||
public abstract class TestClass {{ | ||
[Fact] | ||
public void TestMethod() {{ | ||
var data = new Class(); | ||
Assert.IsAssignableFrom(typeof(IClass), data); | ||
}} | ||
}}"; | ||
|
||
[Fact] | ||
public async void DoesNotFindWarning_ForStaticAbstractInterfaceMembers() | ||
{ | ||
string source = string.Format(codeTemplate, string.Empty, methodCode); | ||
|
||
await Verify.VerifyAnalyzer(LanguageVersion.Preview, source); | ||
} | ||
|
||
[Fact] | ||
public async void DoesNotFindWarning_ForNestedStaticAbstractInterfaceMembers() | ||
{ | ||
string source = string.Format(codeTemplate, methodCode, string.Empty); | ||
|
||
await Verify.VerifyAnalyzer(LanguageVersion.Preview, source); | ||
} | ||
|
||
[Theory] | ||
[InlineData("static", "", "{ }")] | ||
[InlineData("", "abstract", ";")] | ||
public async void FindsWarning_ForNotStaticAbstractInterfaceMembers(string staticModifier, string abstractModifier, string methodBody) | ||
{ | ||
string source = $@" | ||
using Xunit; | ||
public interface IClass {{ | ||
{staticModifier} {abstractModifier} void Method() {methodBody} | ||
}} | ||
public class Class : IClass {{ | ||
public {staticModifier} void Method() {{ }} | ||
}} | ||
public abstract class TestClass {{ | ||
[Fact] | ||
public void TestMethod() {{ | ||
var data = new Class(); | ||
Assert.IsAssignableFrom(typeof(IClass), data); | ||
}} | ||
}}"; | ||
|
||
var expected = | ||
Verify | ||
.Diagnostic() | ||
.WithSpan(17, 9, 17, 54) | ||
.WithArguments("IClass"); | ||
|
||
await Verify.VerifyAnalyzer(LanguageVersion.CSharp8, source, expected); | ||
} | ||
} | ||
#endif | ||
} |
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