Skip to content

TestDataAnalyzer: detect Func<T> by symbol instead of display-string prefix #7380

Open

Description

@thomhurst

TestDataAnalyzer detects Func<T> by calling ToDisplayString().StartsWith("System.Func<", StringComparison.Ordinal). This allocates a display string during analysis and relies on formatting instead of symbol identity.

Current code

Following merged PR #7347 (#7227), the three checks are:

  • Two property-injection checks in src/TUnit.Analyzers/TestDataAnalyzer.cs, using funcType and funcTypeForError.
  • TryUnwrapFunc in the same file, called while peeling the supported data-row wrappers.

Both automated reviewers raised this as non-blocking on #7347 (review comment). That prerequisite has merged; this issue is available for implementation.

Acceptance criteria

  • Resolve System.Func`1 once per compilation with Compilation.GetTypeByMetadataName("System.Func`1").
  • Compare OriginalDefinition with SymbolEqualityComparer.Default in all three checks, as the analyzer already does for TestDataRow<T>.
  • Preserve the existing wrapper-peeling order and property-injection behavior.
  • Add analyzer cases for Func<TestDataRow<(int, int)>> and TestDataRow<Func<(int, int)>> against an (int a, int b) test signature. These are regression coverage for the existing tuple expansion after wrapper peeling; there is no known defect in that ordering.
  • Run the relevant TUnit.Analyzers.Tests coverage.

Activity

  1. added
    performancePerformance optimization
    P3Low: cleanup, minor enhancement, or rare edge case
    on Nov 2, 2026
  2. thomhurst commented on Nov 2, 2026

    @thomhurst
    OwnerAuthor

    Triage update: #7347 has merged and #7227 is closed. TryUnwrapFunc is now on origin/main and still uses the display-string prefix, as do both property-injection checks. Removed the completed prerequisite link and incorporated the tuple-wrapper regression cases into the acceptance criteria.

  3. thomhurst commented on Nov 2, 2026

    @thomhurst
    OwnerAuthor

    An extra item from the Claude review of #7347 (comment 6570666000), to cover alongside the symbol-based Func<T> match: add analyzer tests for tuples inside the wrappers, for example Func<TestDataRow<(int, int)>> and TestDataRow<Func<(int, int)>> against a (int a, int b) test signature. UnwrapTypes still runs its tuple expansion after the fixed Func → TestDataRow → Func peel, so there is no known defect. The tests would lock that ordering in, and changing TryUnwrapFunc would touch the same path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low: cleanup, minor enhancement, or rare edge caseenhancementNew feature or requestperformancePerformance optimization

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions