Skip to content

Commit

Permalink
xunit/xunit#2819: xUnit1039 is not generic-aware and fails type matching
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Nov 11, 2023
1 parent d20f27b commit a9319ac
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,42 @@ public void TestMethod(int n, params int[] a) {{ }}
await Verify.VerifyAnalyzer(LanguageVersion.CSharp10, source);
}

[Theory]
[MemberData(nameof(MemberSyntaxAndArgs))]
public async void DoesNotFindWarning_WithGenericArgument(
string memberSyntax,
string memberArgs)
{
var source = $@"
public class TestClass {{
public static Xunit.TheoryData<int> TestData{memberSyntax}new();
[Xunit.MemberData(nameof(TestData){memberArgs})]
public void TestMethod<T>(T n) {{ }}
}}";

await Verify.VerifyAnalyzer(LanguageVersion.CSharp10, source);
}

[Theory]
[MemberData(nameof(MemberSyntaxAndArgs))]
public async void DoesNotFindWarning_WithGenericNullableArgument(
string memberSyntax,
string memberArgs)
{
var source = $@"
#nullable enable
public class TestClass {{
public static Xunit.TheoryData<int> TestData{memberSyntax}new();
[Xunit.MemberData(nameof(TestData){memberArgs})]
public void TestMethod<T>(T? n) {{ }}
}}";

await Verify.VerifyAnalyzer(LanguageVersion.CSharp10, source);
}

[Theory]
[MemberData(nameof(MemberSyntaxAndArgs))]
public async void FindWarning_IfHasValidTheoryDataMemberWithTooManyTypeParameters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ static void VerifyTheoryDataUsage(
if (typeArgument is null)
continue;

if (!parameterType.IsAssignableFrom(typeArgument))
if (parameterType.Kind != SymbolKind.TypeParameter && !parameterType.IsAssignableFrom(typeArgument))
ReportMemberMethodTheoryDataIncompatibleType(context, parameterSyntax.Type.GetLocation(), typeArgument, namedMemberType, memberName, parameter);

// Nullability of value types is handled by the type compatibility test,
Expand Down

0 comments on commit a9319ac

Please sign in to comment.