Skip to content

[Bug]: IsEquivalentTo broken for value types #4358

@davidmehren

Description

@davidmehren

Description

Value Types like ValueTuple are compared using Equals during IsEquivalentTo, which is incorrect, as these can contain objects that contain references.

Expected Behavior

Tuples that contain structurally equal objects are asserted as equal, even when they contain non-record reference types.

Actual Behavior

Tuples that contain structurally equal objects are asserted as non-equal

Steps to Reproduce

See reproducer at https://github.com/davidmehren/TUnitIgnoreTypeRepro/blob/broken-equivalence/Tests.cs

Thing.Numbers is a non-record reference type inside a record and needs to be compared structurally.

TUnit Version

1.10.0

.NET Version

.NET 10.0.1

Operating System

Linux

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

████████╗██╗   ██╗███╗   ██╗██╗████████╗
╚══██╔══╝██║   ██║████╗  ██║██║╚══██╔══╝
   ██║   ██║   ██║██╔██╗ ██║██║   ██║
   ██║   ██║   ██║██║╚██╗██║██║   ██║
   ██║   ╚██████╔╝██║ ╚████║██║   ██║
   ╚═╝    ╚═════╝ ╚═╝  ╚═══╝╚═╝   ╚═╝

   TUnit v1.10.0.0 | 64-bit | Fedora Linux 43 (Workstation Edition) | linux-x64 | .NET 10.0.1 | Microsoft Testing Platform v2.0.2

   Engine Mode: SourceGenerated

fehlerhaft Fails (24ms)
  TUnit.Engine.Exceptions.TestFailedException: AssertionException: Expected (foo, bar to be equivalent to (bar, foo)
  but Property  did not match
  Expected: (Thing { Name = Foo, Numbers = System.Int32[] }, Thing { Name = Foo, Numbers = System.Int32[] })
  Received: (Thing { Name = Foo, Numbers = System.Int32[] }, Thing { Name = Foo, Numbers = System.Int32[] })
  
  at Assert.That((foo, bar)).IsEquivalentTo((bar, foo))

Testlaufzusammenfassung: Fehler! - bin/Debug/net10.0/TUnitIgnoreTypeRepro.dll (net10.0|x64)
  gesamt: 1
  fehlerhaft: 1
  erfolgreich: 0
  übersprungen: 0
  Dauer: 186ms

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

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions