xunit
xunit copied to clipboard
Display the types of unequal items in collections
(Adapted from #2452)
When two items appear equal but are not because of type differences, the assertion message shows this type difference:
Assert.Equal<object>(3, 3L);
Assert.Equal() Failure
Expected: 3 (System.Int32)
Actual: 3 (System.Int64)
However, when the two items in question are in a collection, the message shows the position but no type information:
Assert.Equal(new object[] { 1, 2, 3 }, new object[] { 1, 2, 3L });
Assert.Equal() Failure
↓ (pos 2)
Expected: [1, 2, 3]
Actual: [1, 2, 3]
↑ (pos 2)
I'm guessing this is probably the best output format (but I'm open to other suggestions):
Assert.Equal() Failure
↓ (pos 2, type System.Int32)
Expected: [1, 2, 3]
Actual: [1, 2, 3]
↑ (pos 2, type System.Int64)
We only want the type to be printed when the types don't match; so unequal values with the same type should print like this:
Assert.Equal() Failure
↓ (pos 2)
Expected: [1, 2, 3]
Actual: [1, 2, 4]
↑ (pos 2)
not this:
Assert.Equal() Failure
↓ (pos 2, type System.Int32)
Expected: [1, 2, 3]
Actual: [1, 2, 4]
↑ (pos 2, type System.Int32)
I'm going to grab this one and make it happen ;)