diff --git a/assert/assertions.go b/assert/assertions.go index 899e9f4..831db83 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -362,6 +362,9 @@ func isEmpty(object interface{}) bool { } case reflect.Ptr: { + if objValue.IsNil() { + return true + } switch object.(type) { case *time.Time: return object.(*time.Time).IsZero() diff --git a/assert/assertions_test.go b/assert/assertions_test.go index e7d3ad1..46dc3fb 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -4,6 +4,7 @@ import ( "errors" "io" "math" + "os" "reflect" "regexp" "testing" @@ -580,6 +581,9 @@ func TestEmpty(t *testing.T) { mockT := new(testing.T) chWithValue := make(chan struct{}, 1) chWithValue <- struct{}{} + var ti *time.Time + var s *string + var f *os.File True(t, Empty(mockT, ""), "Empty string is empty") True(t, Empty(mockT, nil), "Nil is empty") @@ -587,6 +591,9 @@ func TestEmpty(t *testing.T) { True(t, Empty(mockT, 0), "Zero int value is empty") True(t, Empty(mockT, false), "False value is empty") True(t, Empty(mockT, make(chan struct{})), "Channel without values is empty") + True(t, Empty(mockT, s), "Nil string pointer is empty") + True(t, Empty(mockT, f), "Nil os.File pointer is empty") + True(t, Empty(mockT, ti), "Nil time.Time pointer is empty") False(t, Empty(mockT, "something"), "Non Empty string is not empty") False(t, Empty(mockT, errors.New("something")), "Non nil object is not empty")