confusing use of "unexpected success" when no errors are involved
mvdan opened this issue · 3 comments
https://go.dev/play/p/XftIYAoec8W
with v0.14.1, I see:
=== RUN TestNil
prog.go:11:
error:
unexpected success
got:
(*int)(nil)
[...]
=== RUN TestNonNil
prog.go:16:
error:
got non-nil value
got:
&int(0)
[...]
TestNonNil works fine, but TestNil tells me "unexpected success". I got that message in a long test and I was really confused - what was succeeding? The line in question wasn't comparing error values at all.
I think it should say "got nil value" if the type in question does not satisfy the error
interface.
The Not checker returns "unexpected success" when the wrapped checker succeeds.
I agree the message might be confusing. Not(Nil)
(or NotNil
) are used so often that perhaps it's a good idea to provide a better and less generic error for the specific case, which is what is done by the linked PR. Could you please take a look?
Left a review :)
Tagged as v1.14.2