testify icon indicating copy to clipboard operation
testify copied to clipboard

Nil is handled poorly

Open anacrolix opened this issue 8 years ago • 3 comments

assert.Nil passes on a value of (*int)(nil), I believe the function digs too deep on the value. It seems that assert.Nil should do the equivalent of value == nil, but instead the decision is deferred to reflect.Value.IsNil.

https://github.com/anacrolix/wat/blob/master/nil_test.go#L16 is an example of the unexpected behaviour.

anacrolix avatar Sep 13 '17 14:09 anacrolix

Here's an example of where I wasn't able to use assert.Nil because it gave unexpected behaviour: https://github.com/anacrolix/torrent/blob/master/utp_test.go#L12

anacrolix avatar Sep 13 '17 14:09 anacrolix

Nil pointers getting silently wrapped into a non-nil interfaces is a go feature that has bitten us a few times. Can be tricky to spot and it'd be great if our favorite testing library made this easy to catch.

rowanseymour avatar Nov 09 '22 16:11 rowanseymour

I actually don't know if it handles this case differently, but I'll shill https://github.com/frankban/quicktest instead. @rowanseymour

anacrolix avatar Nov 10 '22 05:11 anacrolix