Skip to content

TUnit0001 rejects convertible typed rows before optional test parameters #7617

Closed

Description

@thomhurst

Summary

TUnit0001 rejects a typed method data source whose row converts implicitly to the first test parameter when later test parameters are optional. The equivalent erased source runs successfully. Users cannot expose the concrete source type to Native AOT conversion generation without suppressing the analyzer.

Reproduction

using System.Collections.Generic;
using TUnit.Core;

public class Tests
{
    public sealed class Row
    {
        public static implicit operator (int, int)(Row value) => (25, 26);
    }
    public static IEnumerable<Row> Rows() => [new Row()];
    [Test, MethodDataSource(nameof(Rows))]
    public void Test((int, int) pair, int extra = 5) { }
}

Build with the analyzer enabled. Removing extra, or returning an erased IEnumerable<object[]> row containing the Row instance, avoids the diagnostic.

Expected and actual

Expected: accept the valid row-to-first-parameter conversion with the optional tail omitted. Actual: TUnit0001 reports that Row does not match (int, int), int. Keep rejection of required trailing parameters, and cover generated, reflection and Native AOT execution with the typed source.

Environment

SDK 10.0.403, net10.0. Observed while validating #7608 at c986b78; main at 3dfd584 still has the same analyzer conversion/count path. #7418 concerns optional parameters on the source method itself, which is a different case.

Please accept a convertible typed row when remaining test parameters may be omitted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium: edge case, mode divergence, flaky test, or workaround existsbugSomething isn't workingin-progressWork is in progress

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions