mirror of https://github.com/stretchr/testify.git
Merge pull request #232 from stretchr/issue-136
Fix #136 - Empty returns true for nil pointerspull/239/head
commit
a76410419d
|
@ -362,6 +362,9 @@ func isEmpty(object interface{}) bool {
|
||||||
}
|
}
|
||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
{
|
{
|
||||||
|
if objValue.IsNil() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
switch object.(type) {
|
switch object.(type) {
|
||||||
case *time.Time:
|
case *time.Time:
|
||||||
return object.(*time.Time).IsZero()
|
return object.(*time.Time).IsZero()
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -580,6 +581,9 @@ func TestEmpty(t *testing.T) {
|
||||||
mockT := new(testing.T)
|
mockT := new(testing.T)
|
||||||
chWithValue := make(chan struct{}, 1)
|
chWithValue := make(chan struct{}, 1)
|
||||||
chWithValue <- struct{}{}
|
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, ""), "Empty string is empty")
|
||||||
True(t, Empty(mockT, nil), "Nil 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, 0), "Zero int value is empty")
|
||||||
True(t, Empty(mockT, false), "False 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, 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, "something"), "Non Empty string is not empty")
|
||||||
False(t, Empty(mockT, errors.New("something")), "Non nil object is not empty")
|
False(t, Empty(mockT, errors.New("something")), "Non nil object is not empty")
|
||||||
|
|
Loading…
Reference in New Issue