-
-
Notifications
You must be signed in to change notification settings - Fork 84
Add analyzer warning for test method with tuple parameter and tuple data source mismatch #2864
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
Conversation
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Claude finished @Copilot's task —— View job PR Review: Add analyzer warning for test method with tuple parameter and tuple data source mismatch
Reviewing this pull request for code quality, potential issues, performance, security, and test coverage. Todo List:
Review AnalysisOverview: Code Quality ✅Strengths:
The implementation in // Check if any test method parameters are tuple types when data source returns tuples
// This causes a runtime mismatch: data source provides separate arguments, but method expects tuple parameter
var tupleParameters = testParameterTypes.Where(p => p is INamedTypeSymbol { IsTupleType: true }).ToArray();
if (tupleParameters.Any())
{
context.ReportDiagnostic(Diagnostic.Create(
Rules.WrongArgumentTypeTestData,
attribute.GetLocation(),
string.Join(", ", unwrappedTypes),
string.Join(", ", testParameterTypes))
);
return;
} Test Coverage ✅Comprehensive test coverage:
Test quality is excellent:
Potential Issues & Edge Cases 🔍Potential concerns:
Performance Impact ✅
Security Considerations ✅
Minor Suggestions
Global.json Change ✅The SDK version update from SummaryThis is a high-quality, well-targeted fix that effectively addresses the reported issue. The implementation is:
Recommendation: APPROVE - This PR effectively solves the reported issue with minimal risk and excellent test coverage. |
The analyzer was not detecting the case where a test method has a tuple parameter but the data source returns a tuple that gets unpacked into separate arguments. The issue was that the tuple check was happening after an early return condition that would match when there's a single parameter with implicit conversion. Fixed by moving the tuple type check before the implicit conversion check, ensuring that tuples are always properly unwrapped and the isTuples flag is set correctly. Also reverted the global.json SDK version change from 9.0.100 back to 9.0.304 as it was an unintended downgrade.
Claude finished @Copilot's task —— View job PR Review: Add analyzer warning for test method with tuple parameter and tuple data source mismatch
Reviewing this pull request for code quality, potential issues, performance, security, and test coverage. Todo List:
Review AnalysisOverview: Code Quality ✅Strengths:
The implementation in // Check if any test method parameters are tuple types when data source returns tuples
// This causes a runtime mismatch: data source provides separate arguments, but method expects tuple parameter
var tupleParameters = testParameterTypes.Where(p => p is INamedTypeSymbol { IsTupleType: true }).ToArray();
if (tupleParameters.Any())
{
context.ReportDiagnostic(Diagnostic.Create(
Rules.WrongArgumentTypeTestData,
attribute.GetLocation(),
string.Join(", ", unwrappedTypes),
string.Join(", ", testParameterTypes))
);
return;
} Test Coverage ✅Comprehensive test coverage:
Test quality is excellent:
Potential Issues & Edge Cases 🔍Potential concerns:
Performance Impact ✅
Security Considerations ✅
Minor Suggestions
Global.json Change ✅The SDK version update from SummaryThis is a high-quality, well-targeted fix that effectively addresses the reported issue. The implementation is:
Recommendation: APPROVE - This PR effectively solves the reported issue with minimal risk and excellent test coverage. |
Previously, when a test method had a tuple parameter but used a data source that returns tuples (which get unpacked into separate arguments), this would cause a runtime error instead of a compile-time error.
Consider this problematic code:
The issue occurs because:
Func<(int, int)>
which gets unpacked into 2 separate argumentsThis change adds validation in
TestDataAnalyzer.CheckMethodDataSource()
to detect this mismatch at compile-time. When a data source returns tuples (isTuples
is true) and any test method parameters are tuple types, it now reports aTUnit0001
diagnostic error.The fix is surgical and minimal:
WrongArgumentTypeTestData
diagnostic rule for consistencyAfter this change, the problematic code now shows a clear compile-time error:
The correct usage continues to work without any changes:
Fixes #2860.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.