testify
testify copied to clipboard
Equal diff prints uints in hex format
Equal and EqualValues print uints in hex format when showing diff. It would be much more useful to see 1701, instead of 0x6a5.
Error Trace: equality_test:34
Error: Not equal:
expected: float64(1700)
received: uint(0x6a5)
Messages: Expecting prices to be equal
For formatting the units, it looks like the current code uses:
%T(%#v)
I think you are suggesting moving to something like
%T(%v)
The following shows the difference in outputs:
| %T(%#v) | %T(%v) |
|---|---|
| string("1700") | string(1700) |
| int(1700) | int(1700) |
| float64(1700) | float64(1700) |
| uint(0x6a4) | uint(1700) |
Yeah, that makes sense. The problem with changing that is that structs will no longer print with visible keys. This might be a problem with the way Go formats uints.
Maybe using spew for the formatting might help?
Makes sense to me. Spew is already a dependency for Testify anyway. When I have time, I'll check if there's already a PR for this.
Seems like the time is abstract.
Here is a runnable test case: https://go.dev/play/p/QAkHgivpe3X
func Test(t *testing.T) {
assert.Equal(t, float64(1700), uint(1700))
}
Output with v1.8.4:
=== RUN Test
prog_test.go:11:
Error Trace: /tmp/sandbox3990837469/prog_test.go:11
Error: Not equal:
expected: float64(1700)
actual : uint(0x6a4)
Test: Test
--- FAIL: Test (0.00s)
FAIL
This issue still exists in v1.8.4.