mirror of https://github.com/stretchr/testify.git
Merge pull request #239 from anacrolix/master
Avoid panic when calling EqualValues with nilpull/240/head
commit
82616deabd
|
@ -51,8 +51,11 @@ func ObjectsAreEqualValues(expected, actual interface{}) bool {
|
|||
}
|
||||
|
||||
actualType := reflect.TypeOf(actual)
|
||||
if actualType == nil {
|
||||
return false
|
||||
}
|
||||
expectedValue := reflect.ValueOf(expected)
|
||||
if expectedValue.Type().ConvertibleTo(actualType) {
|
||||
if expectedValue.IsValid() && expectedValue.Type().ConvertibleTo(actualType) {
|
||||
// Attempt comparison after type conversion
|
||||
return reflect.DeepEqual(expectedValue.Convert(actualType).Interface(), actual)
|
||||
}
|
||||
|
|
|
@ -132,6 +132,12 @@ func TestObjectsAreEqual(t *testing.T) {
|
|||
if !ObjectsAreEqualValues(uint32(10), int32(10)) {
|
||||
t.Error("ObjectsAreEqualValues should return true")
|
||||
}
|
||||
if ObjectsAreEqualValues(0, nil) {
|
||||
t.Fail()
|
||||
}
|
||||
if ObjectsAreEqualValues(nil, 0) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue