-
Notifications
You must be signed in to change notification settings - Fork 32
Adjust NUnit1029 to account for TestCaseSource support for params and optional arguments #958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -248,7 +248,7 @@ private static void AnalyzeAttribute( | |||||||||
| var hasCancelAfterAttribute = testMethod.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, cancelAfterType)) || | ||||||||||
| testMethod.ContainingType.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, cancelAfterType)); | ||||||||||
|
|
||||||||||
| var (methodRequiredParameters, methodOptionalParameters, _) = testMethod.GetParameterCounts(hasCancelAfterAttribute, cancellationTokenType); | ||||||||||
| var (methodRequiredParameters, methodOptionalParameters, methodParamsParameters) = testMethod.GetParameterCounts(hasCancelAfterAttribute, cancellationTokenType); | ||||||||||
|
|
||||||||||
| if (elementType.SpecialType != SpecialType.System_String && (elementType.SpecialType == SpecialType.System_Object || elementType.IsIEnumerable(out _) || | ||||||||||
| IsOrDerivesFrom(elementType, context.SemanticModel.Compilation.GetTypeByMetadataName(NUnitFrameworkConstants.FullNameOfTypeTestCaseParameters)))) | ||||||||||
|
|
@@ -257,7 +257,7 @@ private static void AnalyzeAttribute( | |||||||||
| // The object could hide an array, possibly with a variable number of elements: TestCaseData.Argument. | ||||||||||
| // Potentially we could examine the body of the TestCaseSource to see if we can determine the exact amount. | ||||||||||
| // For complex method that is certainly beyond the scope of this. | ||||||||||
| if (methodRequiredParameters + methodOptionalParameters < 1 && !testMethod.IsGenericMethod) | ||||||||||
| if (methodRequiredParameters + methodOptionalParameters + methodParamsParameters < 1 && !testMethod.IsGenericMethod) | ||||||||||
| { | ||||||||||
| context.ReportDiagnostic(Diagnostic.Create( | ||||||||||
| mismatchInNumberOfTestMethodParameters, | ||||||||||
|
|
@@ -268,15 +268,7 @@ private static void AnalyzeAttribute( | |||||||||
| } | ||||||||||
| else | ||||||||||
| { | ||||||||||
| if (methodRequiredParameters != 1) | ||||||||||
| { | ||||||||||
| context.ReportDiagnostic(Diagnostic.Create( | ||||||||||
| mismatchInNumberOfTestMethodParameters, | ||||||||||
| syntaxNode.GetLocation(), | ||||||||||
| 1, | ||||||||||
| methodRequiredParameters)); | ||||||||||
| } | ||||||||||
| else | ||||||||||
| if (methodRequiredParameters == 1) | ||||||||||
| { | ||||||||||
| IParameterSymbol testMethodParameter = testMethod.Parameters.First(); | ||||||||||
|
|
||||||||||
|
|
@@ -290,6 +282,17 @@ private static void AnalyzeAttribute( | |||||||||
| testMethodParameter.Name)); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| else if (methodRequiredParameters > 1 || | ||||||||||
| (methodRequiredParameters + methodOptionalParameters + methodParamsParameters == 0)) | ||||||||||
| { | ||||||||||
| // more than one required parameter is always a mismatch | ||||||||||
| // zero parameters of any kind is also a mismatch | ||||||||||
| context.ReportDiagnostic(Diagnostic.Create( | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see a new test case that validates this.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @manfred-brands
That comment was added by me to clarify the existing logic for myself prior to and after refactoring the logic a bit. I had thought they're already covered through existing tests here:
Unless, would you prefer additional cases with 0 and two required args which also include optional args in the signature like this? [TestCaseSource(↓nameof(TestData))]
public void ShortName(int x, int y, int z = 2) |
||||||||||
| mismatchInNumberOfTestMethodParameters, | ||||||||||
| syntaxNode.GetLocation(), | ||||||||||
| 1, | ||||||||||
| methodRequiredParameters)); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NUnit itself fails to run this test with Unable to determine type arguments for method.
I always extract the code from the string to see if NUnit will actually run it.