Skip to content

[Bug]: GenerateAssertion drops parameter default values from generated extension method #4826

@ascott18

Description

@ascott18

Description

The following code is a compilation error because the source generated extension method has lost the true default value of the exact parameter.

public class UnitTest1
{
    [Test]
    public async Task TestWithMemberData()
    {
        string[] items = new[] { "food", "bard" };
        await Assert.That(items).ContainsMessage("foo"); // ERROR: parameter `bool exact` expected
    }
}

public static partial class Assertions
{
    [EditorBrowsable(EditorBrowsableState.Never)]
    [GenerateAssertion(ExpectationMessage = "to contain message '{needle}'")]
    public static bool ContainsMessage(this IEnumerable<string> strings, string needle, bool exact = true)
    {
        return strings.Any(x => exact ? x == needle : x.Contains(needle));
    }
}

Expected Behavior

Source generated extension preserves parameter defaults.

Actual Behavior

Parameter defaults lost

Steps to Reproduce

See above code

TUnit Version

1.15.0

.NET Version

NET 10

Operating System

Windows

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

Additional Context

No response

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions