testify icon indicating copy to clipboard operation
testify copied to clipboard

Equal diff prints uints in hex format

Open momoneko opened this issue 8 years ago • 5 comments
trafficstars

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

momoneko avatar Feb 14 '17 12:02 momoneko

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)

ryanguest avatar Mar 02 '17 21:03 ryanguest

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?

momoneko avatar Mar 06 '17 10:03 momoneko

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.

mvdkleijn avatar Apr 07 '20 14:04 mvdkleijn

Seems like the time is abstract.

zdraganov avatar Aug 27 '21 08:08 zdraganov

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.

dolmen avatar Jul 06 '23 19:07 dolmen