-
-
Notifications
You must be signed in to change notification settings - Fork 108
fix: expand migration code fixer attribute support #4353
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
NUnit improvements:
- Add [Values] -> [Matrix] conversion
- Add [Range] -> [MatrixRange<int>] conversion
- Add [ValueSource] -> [MatrixSourceMethod] conversion
- Add [NonParallelizable] -> [NotInParallel] conversion
- Add [Parallelizable(ParallelScope.None)] -> [NotInParallel] conversion
- Fix [Parallelizable] being removed before ParallelScope.None could be detected
- Add [Repeat] preservation (same name in TUnit)
MSTest improvements:
- Fix [Priority] -> [Property("Priority", "N")] (was keeping wrong attribute name)
- Fix [TestCategory] -> [Property("Category", "X")] attribute name
- Add [Owner] -> [Property("Owner", "Name")] conversion
- Add [ExpectedException(typeof(T))] -> Assert.ThrowsAsync<T>() body transformation
Co-Authored-By: Claude Opus 4.5 <[email protected]>
SummaryExpands migration code fixers to support additional MSTest and NUnit attributes, including parameter-level data attributes, parallelization control, and exception expectations. Critical Issues1. Async lambda bug in ExpectedException conversion (MSTestMigrationCodeFixProvider.cs:928-933) The Problem code: var lambda = SyntaxFactory.ParenthesizedLambdaExpression(
SyntaxFactory.ParameterList(),
SyntaxFactory.Block(originalStatements)
);If var lambda = SyntaxFactory.ParenthesizedLambdaExpression(
asyncKeyword: hasAwait ? SyntaxFactory.Token(SyntaxKind.AsyncKeyword) : default,
SyntaxFactory.ParameterList(),
SyntaxFactory.Block(originalStatements)
);Where bool hasAwait = originalStatements.Any(s => s.DescendantNodes().OfType<AwaitExpressionSyntax>().Any());Test coverage needed: Add a test case with an async method: [TestMethod]
[ExpectedException(typeof(ArgumentException))]
public async Task TestMethodAsync()
{
await Task.Delay(1);
throw new ArgumentException("test");
}SuggestionsNone - the rest of the implementation looks solid. Verdict
|
- Fix hard-coded int type in NUnit Range conversion: now infers type from literal arguments (double, float, long, uint, ulong) - Add NUnit Sequential attribute handling: removed since TUnit's default behavior with Matrix is combinatorial - Add NUnit Combinatorial attribute handling: removed (default behavior) - Add MSTest DirectoryAssert.Exists/DoesNotExist conversion - Add MSTest FileAssert.Exists/DoesNotExist conversion All 336 NUnit and 124 MSTest migration tests pass. Co-Authored-By: Claude Opus 4.5 <[email protected]>
SummaryExpands migration code fixers with additional attribute conversions for NUnit and MSTest frameworks, including parameter-level data attributes, parallelization control, and exception expectations. Critical Issues1. Async lambda bug in ExpectedException conversion remains unresolved (MSTestMigrationCodeFixProvider.cs) The previous review identified a critical bug where the lambda created in WrapBodyInThrowsAsync is not marked as async when the original method body contains await expressions. This issue has NOT been fixed in the current PR. Problem: When converting an async method with [ExpectedException], the generated code will have a non-async lambda containing await expressions, causing a compiler error. Required fix: The code must check if originalStatements contain await expressions, and if so, add the async modifier to the lambda using SyntaxFactory.Token(SyntaxKind.AsyncKeyword). Missing test coverage: The PR lacks a test case for async methods with [ExpectedException]. The only test is for a synchronous method. SuggestionsNone - the other conversions (Values→Matrix, Range→MatrixRange, NonParallelizable→NotInParallel, etc.) look correct and follow TUnit patterns. Previous Review StatusThe critical async lambda issue from the previous review (2026-01-13T01:23:26Z) remains unaddressed. While the PR was updated 10 minutes after the review, the fix was not applied. Verdict |
When converting [ExpectedException] on async methods, the generated lambda now correctly uses the async modifier if the original method body contains await expressions. This addresses the code review feedback on PR #4353 about the critical async lambda issue. Co-Authored-By: Claude Opus 4.5 <[email protected]>
SummaryExpands migration code fixers with additional attribute conversions for NUnit and MSTest frameworks, including parameter-level data attributes, parallelization control, and exception expectations. Critical Issues1. Operator precedence bug in InferRangeType (NUnitMigrationCodeFixProvider.cs, line ~187 in diff) The condition for detecting 'd'/'D' suffix has an operator precedence issue: if (tokenText.EndsWith("d", StringComparison.OrdinalIgnoreCase) ||
tokenText.EndsWith("D", StringComparison.OrdinalIgnoreCase) && \!tokenText.StartsWith("0x", StringComparison.OrdinalIgnoreCase))The if (tokenText.EndsWith("d", StringComparison.OrdinalIgnoreCase) ||
(tokenText.EndsWith("D", StringComparison.OrdinalIgnoreCase) && \!tokenText.StartsWith("0x")))This means lowercase 'd' suffix would match even for hex literals (though unlikely in practice). Should be: if ((tokenText.EndsWith("d", StringComparison.OrdinalIgnoreCase) ||
tokenText.EndsWith("D", StringComparison.OrdinalIgnoreCase)) &&
\!tokenText.StartsWith("0x", StringComparison.OrdinalIgnoreCase))However, on reflection, the hex check may be unnecessary - C# doesn't allow 'd' suffix on hex literals, so this would be caught as invalid syntax before the migration tool runs. Consider removing the hex check entirely or adding parentheses for clarity. SuggestionsNone - the rest of the implementation is solid. Good work on:
Previous Review StatusThe critical async lambda bug has been successfully fixed. The code now:
Verdict✅ APPROVE - The operator precedence issue is minor and unlikely to cause real-world problems since invalid syntax would be caught before migration. Everything else looks excellent. |
Summary
Expands the migration code fixers with additional attribute conversions for NUnit and MSTest frameworks.
NUnit Improvements
ShouldRemoveAttributeprematurely removing[Parallelizable]beforeConvertAttributecould handleParallelScope.NoneMSTest Improvements
Assert.ThrowsAsync<T>()- Complex transformationTest plan
🤖 Generated with Claude Code