-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assert: NotNil accepts non-nillable types and doesn't fail #570
Comments
@dnephin that sounds good. Do you want to issue a PR? |
All the above will be nil, it could be a case where the function returns a value and we generally check its not nil. I wouldn't mind adding a log, but failing a test, would make the contract differ. |
@devdinu the contract should be different. This is a bug, not a feature request. The problem is this: if kind >= reflect.Chan && kind <= reflect.Slice If kind is not in that range, Some examples: require.NotNil(t, "foo")
require.NotNil(t, "")
require.NotNil(t, 0)
require.NotNil(t, 1)
require.NotNil(t, mystruct{}) None of these fail the test. This is broken. #584 looks like the correct fix. |
#584 would fail the following test which currently passes. type something struct{}
func (s something) Error() string {
return "fail"
}
func foo() error {
return something{}
}
func TestNotNilWithError(t *testing.T) {
err := foo()
NotNil(t, err)
} If we were to do something like this, we would need something that works with |
testify/assert/assertions.go
Lines 390 to 410 in b89eecf
isNil
will always return false, soNotNil
will always return true for int, string, struct, etc.I would expect it to error with "invalid type".
The text was updated successfully, but these errors were encountered: