IsNil (mis)behavior on pointers
Opened this issue · 1 comments
Deleted user commented
As per title. Example:
func TestWeirdness(t *testing.T) {
test := Goblin(t)
test.Describe("Pointer Weirdness", func() {
test.It("Should PASS but FAILS", func() {
var ptr *[]int
test.Assert(ptr).IsNil()
})
test.It("Should PASS but FAILS", func() {
var ptr *[2]int
test.Assert(ptr).IsNil()
})
test.It("Should PASS but FAILS", func() {
var ptr *time.Time
test.Assert(ptr).IsNil()
})
test.It("Should FAIL but PASSES", func() {
var ptr *[]int
test.Assert(ptr).IsNotNil()
})
test.It("Should FAIL but PASSES", func() {
var ptr *[2]int
test.Assert(ptr).IsNotNil()
})
test.It("Should FAIL but PASSES", func() {
var ptr *time.Time
test.Assert(ptr).IsNotNil()
})
})
}
marcosnils commented
Behavior is as expected since this is how Golang nil works with nil pointers and interfaces. Check https://blog.golang.org/laws-of-reflection