-
-
Notifications
You must be signed in to change notification settings - Fork 111
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Description
When running the TUnit NUnit migration code fixer, methods containing ref, in, or out parameters are incorrectly converted to async Task methods. This causes compilation errors because C# does not allow async methods to have ref, in, or out parameters.
Steps to Reproduce
- Create a project with NUnit tests that have helper methods with
reforoutparameters - Add TUnit packages
- Run
dotnet format analyzers --severity info --diagnostics TUNU0001 - Build the project
Expected Behavior
Methods with ref, in, or out parameters should NOT be converted to async methods. The assertions inside them should remain synchronous or the migration should leave them untouched.
Actual Behavior
Methods with ref/out parameters are converted to async, causing build errors:
error CS1988: Async methods cannot have ref, in or out parameters
Example
Before migration:
private static void HandleRealized(object sender, object expected, ref bool realized, string message)
{
Assert.AreSame(AsVirtual(expected), sender, message);
realized = true;
}After migration (current - broken):
private async static Task HandleRealized(object sender, object expected, ref bool realized, string message)
{
await Assert.That(sender).IsSameReferenceAs(AsVirtual(expected)).Because(message);
realized = true;
}Expected after migration:
Option 1 - Don't convert to async:
private static void HandleRealized(object sender, object expected, ref bool realized, string message)
{
Assert.That(sender).IsSameReferenceAs(AsVirtual(expected)).Because(message).Wait();
realized = true;
}Option 2 - Leave unchanged for manual migration:
// Original code left unchanged - manual migration required due to ref parameter
private static void HandleRealized(object sender, object expected, ref bool realized, string message)
{
Assert.AreSame(AsVirtual(expected), sender, message);
realized = true;
}Impact
This is a critical issue because it generates code that cannot compile.
Environment
- TUnit version: 1.9.91
- .NET version: .NET 8.0
- OS: Windows
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working