Skip to content

Commit

Permalink
Update descriptors for xUnit1037/1038/1039/1040 so they can be reused…
Browse files Browse the repository at this point in the history
… for ClassData
  • Loading branch information
bradwilson committed May 23, 2024
1 parent 347e9fb commit f80b09d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ public class TestClass {{
}
}

public class X1037_MemberDataTheoryDataTypeArgumentsMustMatchTestMethodParameters_TooFewTypeParameters
public class X1037_TheoryDataTypeArgumentsMustMatchTestMethodParameters_TooFewTypeParameters
{
public static TheoryData<string, string> MemberSyntaxAndArgs = new()
{
Expand Down Expand Up @@ -948,7 +948,7 @@ public class TestClass {{
}
}

public class X1038_MemberDataTheoryDataTypeArgumentsMustMatchTestMethodParameters_ExtraTypeParameters
public class X1038_TheoryDataTypeArgumentsMustMatchTestMethodParameters_ExtraTypeParameters
{
public static MatrixTheoryData<(string syntax, string args), string> MemberSyntaxAndArgs_WithTheoryDataType(string theoryDataTypes) =>
new(
Expand Down Expand Up @@ -1481,7 +1481,7 @@ public class TestClass {{
}
}

public class X1039_MemberDataTheoryDataTypeArgumentsMustMatchTestMethodParameters_IncompatibleTypes
public class X1039_TheoryDataTypeArgumentsMustMatchTestMethodParameters_IncompatibleTypes
{
public static MatrixTheoryData<(string syntax, string args), string> TypeWithMemberSyntaxAndArgs =
new(
Expand Down Expand Up @@ -1648,7 +1648,7 @@ public class TestClass {
.Diagnostic("xUnit1039")
.WithSpan(8, 42, 8, 50)
.WithSeverity(DiagnosticSeverity.Error)
.WithArguments("int", "TestClass", "TestData", "_2");
.WithArguments("int", "TestClass.TestData", "_2");

await Verify.VerifyAnalyzer(source, expected);
}
Expand All @@ -1672,7 +1672,7 @@ public class TestClass {
.Diagnostic("xUnit1039")
.WithSpan(9, 42, 9, 50)
.WithSeverity(DiagnosticSeverity.Error)
.WithArguments("int", "TestClass", "TestData", "_2");
.WithArguments("int", "TestClass.TestData", "_2");

await Verify.VerifyAnalyzerV3(source, expected);
}
Expand All @@ -1698,7 +1698,7 @@ public class TestClass {{
.Diagnostic("xUnit1039")
.WithSpan(8, 28, 8, 34)
.WithSeverity(DiagnosticSeverity.Error)
.WithArguments(type, "TestClass", "TestData", "f");
.WithArguments(type, "TestClass.TestData", "f");

await Verify.VerifyAnalyzer(source, expected);
}
Expand All @@ -1725,13 +1725,13 @@ public class TestClass {{
.Diagnostic("xUnit1039")
.WithSpan(9, 28, 9, 34)
.WithSeverity(DiagnosticSeverity.Error)
.WithArguments(type, "TestClass", "TestData", "f");
.WithArguments(type, "TestClass.TestData", "f");

await Verify.VerifyAnalyzerV3(source, expected);
}
}

public class X1040_MemberDataTheoryDataTypeArgumentsMustMatchTestMethodParameters_IncompatibleNullability
public class X1040_TheoryDataTypeArgumentsMustMatchTestMethodParameters_IncompatibleNullability
{
public static TheoryData<string, string> MemberSyntaxAndArgs = new()
{
Expand Down Expand Up @@ -1764,7 +1764,7 @@ public class TestClass {{
.Diagnostic("xUnit1040")
.WithSpan(10, 28, 10, 34)
.WithSeverity(DiagnosticSeverity.Warning)
.WithArguments("string?", "TestClass", "TestData", "f");
.WithArguments("string?", "TestClass.TestData", "f");

await Verify.VerifyAnalyzer(LanguageVersion.CSharp8, source, expected);
}
Expand Down Expand Up @@ -1793,7 +1793,7 @@ public class TestClass {{
.Diagnostic("xUnit1040")
.WithSpan(11, 28, 11, 34)
.WithSeverity(DiagnosticSeverity.Warning)
.WithArguments("string?", "TestClass", "TestData", "f");
.WithArguments("string?", "TestClass.TestData", "f");

await Verify.VerifyAnalyzerV3(LanguageVersion.CSharp8, source, expected);
}
Expand Down
12 changes: 6 additions & 6 deletions src/xunit.analyzers/Utility/Descriptors.xUnit1xxx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public static partial class Descriptors
"There is no matching method parameter for value: {0}. Remove unused value(s), or add more parameter(s)."
);

public static DiagnosticDescriptor X1037_MemberDataTheoryDataTypeArgumentsMustMatchTestMethodParameters_TooFewTypeParameters { get; } =
public static DiagnosticDescriptor X1037_TheoryDataTypeArgumentsMustMatchTestMethodParameters_TooFewTypeParameters { get; } =
Diagnostic(
"xUnit1037",
"There are fewer theory data type arguments than required by the parameters of the test method",
Expand All @@ -348,7 +348,7 @@ public static partial class Descriptors
"There are fewer {0} type arguments than required by the parameters of the test method. Add more type parameters to match the method signature, or remove parameters from the test method."
);

public static DiagnosticDescriptor X1038_MemberDataTheoryDataTypeArgumentsMustMatchTestMethodParameters_ExtraTypeParameters { get; } =
public static DiagnosticDescriptor X1038_TheoryDataTypeArgumentsMustMatchTestMethodParameters_ExtraTypeParameters { get; } =
Diagnostic(
"xUnit1038",
"There are more theory data type arguments than allowed by the parameters of the test method",
Expand All @@ -357,22 +357,22 @@ public static partial class Descriptors
"There are more {0} type arguments than allowed by the parameters of the test method. Remove unused type arguments, or add more parameters."
);

public static DiagnosticDescriptor X1039_MemberDataTheoryDataTypeArgumentsMustMatchTestMethodParameters_IncompatibleTypes { get; } =
public static DiagnosticDescriptor X1039_TheoryDataTypeArgumentsMustMatchTestMethodParameters_IncompatibleTypes { get; } =
Diagnostic(
"xUnit1039",
"The type argument to theory data is not compatible with the type of the corresponding test method parameter",
Usage,
Error,
"The type argument {0} from {1}.{2} is not compatible with the type of the corresponding test method parameter {3}."
"The type argument {0} from {1} is not compatible with the type of the corresponding test method parameter {2}."
);

public static DiagnosticDescriptor X1040_MemberDataTheoryDataTypeArgumentsMustMatchTestMethodParameters_IncompatibleNullability { get; } =
public static DiagnosticDescriptor X1040_TheoryDataTypeArgumentsMustMatchTestMethodParameters_IncompatibleNullability { get; } =
Diagnostic(
"xUnit1040",
"The type argument to theory data is nullable, while the type of the corresponding test method parameter is not",
Usage,
Warning,
"The type argument {0} from {1}.{2} is nullable, while the type of the corresponding test method parameter {3} is not. Make the TheoryData type non-nullable, or make the test method parameter nullable."
"The type argument {0} from {1} is nullable, while the type of the corresponding test method parameter {2} is not. Make the theory data type non-nullable, or make the test method parameter nullable."
);

public static DiagnosticDescriptor X1041_EnsureFixturesHaveASource { get; } =
Expand Down
22 changes: 10 additions & 12 deletions src/xunit.analyzers/X1000/MemberDataShouldReferenceValidMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public class MemberDataShouldReferenceValidMember : XunitDiagnosticAnalyzer
Descriptors.X1034_MemberDataArgumentsMustMatchMethodParameters_NullShouldNotBeUsedForIncompatibleParameter,
Descriptors.X1035_MemberDataArgumentsMustMatchMethodParameters_IncompatibleValueType,
Descriptors.X1036_MemberDataArgumentsMustMatchMethodParameters_ExtraValue,
Descriptors.X1037_MemberDataTheoryDataTypeArgumentsMustMatchTestMethodParameters_TooFewTypeParameters,
Descriptors.X1038_MemberDataTheoryDataTypeArgumentsMustMatchTestMethodParameters_ExtraTypeParameters,
Descriptors.X1039_MemberDataTheoryDataTypeArgumentsMustMatchTestMethodParameters_IncompatibleTypes,
Descriptors.X1040_MemberDataTheoryDataTypeArgumentsMustMatchTestMethodParameters_IncompatibleNullability,
Descriptors.X1037_TheoryDataTypeArgumentsMustMatchTestMethodParameters_TooFewTypeParameters,
Descriptors.X1038_TheoryDataTypeArgumentsMustMatchTestMethodParameters_ExtraTypeParameters,
Descriptors.X1039_TheoryDataTypeArgumentsMustMatchTestMethodParameters_IncompatibleTypes,
Descriptors.X1040_TheoryDataTypeArgumentsMustMatchTestMethodParameters_IncompatibleNullability,
Descriptors.X1042_MemberDataTheoryDataIsRecommendedForStronglyTypedAnalysis
)
{ }
Expand Down Expand Up @@ -452,7 +452,7 @@ public class MemberDataShouldReferenceValidMember : XunitDiagnosticAnalyzer
INamedTypeSymbol theoryDataType) =>
context.ReportDiagnostic(
Diagnostic.Create(
Descriptors.X1038_MemberDataTheoryDataTypeArgumentsMustMatchTestMethodParameters_ExtraTypeParameters,
Descriptors.X1038_TheoryDataTypeArgumentsMustMatchTestMethodParameters_ExtraTypeParameters,
location,
builder.ToImmutable(),
SymbolDisplay.ToDisplayString(theoryDataType)
Expand All @@ -468,11 +468,10 @@ public class MemberDataShouldReferenceValidMember : XunitDiagnosticAnalyzer
IParameterSymbol parameter) =>
context.ReportDiagnostic(
Diagnostic.Create(
Descriptors.X1039_MemberDataTheoryDataTypeArgumentsMustMatchTestMethodParameters_IncompatibleTypes,
Descriptors.X1039_TheoryDataTypeArgumentsMustMatchTestMethodParameters_IncompatibleTypes,
location,
SymbolDisplay.ToDisplayString(theoryDataTypeParameter),
memberType.Name,
memberName,
memberType.Name + "." + memberName,
parameter.Name
)
);
Expand All @@ -486,11 +485,10 @@ public class MemberDataShouldReferenceValidMember : XunitDiagnosticAnalyzer
IParameterSymbol parameter) =>
context.ReportDiagnostic(
Diagnostic.Create(
Descriptors.X1040_MemberDataTheoryDataTypeArgumentsMustMatchTestMethodParameters_IncompatibleNullability,
Descriptors.X1040_TheoryDataTypeArgumentsMustMatchTestMethodParameters_IncompatibleNullability,
location,
SymbolDisplay.ToDisplayString(theoryDataTypeParameter),
memberType.Name,
memberName,
memberType.Name + "." + memberName,
parameter.Name
)
);
Expand All @@ -502,7 +500,7 @@ public class MemberDataShouldReferenceValidMember : XunitDiagnosticAnalyzer
INamedTypeSymbol theoryDataType) =>
context.ReportDiagnostic(
Diagnostic.Create(
Descriptors.X1037_MemberDataTheoryDataTypeArgumentsMustMatchTestMethodParameters_TooFewTypeParameters,
Descriptors.X1037_TheoryDataTypeArgumentsMustMatchTestMethodParameters_TooFewTypeParameters,
location,
builder.ToImmutable(),
SymbolDisplay.ToDisplayString(theoryDataType)
Expand Down

0 comments on commit f80b09d

Please sign in to comment.