mirror of
https://github.com/stretchr/testify.git
synced 2025-05-31 11:42:44 +00:00
Don't panic when underlying type is not .IsNil()-able (eg. string)
This commit is contained in:
parent
3df0bce8cb
commit
d35afcda84
@ -173,9 +173,13 @@ func NotNil(t *testing.T, object interface{}, msgAndArgs ...interface{}) bool {
|
|||||||
|
|
||||||
if object == nil {
|
if object == nil {
|
||||||
success = false
|
success = false
|
||||||
} else if reflect.ValueOf(object).IsNil() {
|
} else {
|
||||||
|
value := reflect.ValueOf(object)
|
||||||
|
kind := value.Kind()
|
||||||
|
if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() {
|
||||||
success = false
|
success = false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !success {
|
if !success {
|
||||||
|
|
||||||
@ -201,9 +205,13 @@ func Nil(t *testing.T, object interface{}, msgAndArgs ...interface{}) bool {
|
|||||||
|
|
||||||
if object == nil {
|
if object == nil {
|
||||||
return true
|
return true
|
||||||
} else if reflect.ValueOf(object).IsNil() {
|
} else {
|
||||||
|
value := reflect.ValueOf(object)
|
||||||
|
kind := value.Kind()
|
||||||
|
if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(message) > 0 {
|
if len(message) > 0 {
|
||||||
t.Errorf("\r%s\r\tLocation:\t%s\n\r\tError:\t\tExpected nil, but got: %#v\n\r\tMessages:\t%s\n\r", getWhitespaceString(), CallerInfo(), object, message)
|
t.Errorf("\r%s\r\tLocation:\t%s\n\r\tError:\t\tExpected nil, but got: %#v\n\r\tMessages:\t%s\n\r", getWhitespaceString(), CallerInfo(), object, message)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user