Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unsafe.Pointer to Nil/NotNil checks #872

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,8 @@ func isNil(object interface{}) bool {
[]reflect.Kind{
reflect.Chan, reflect.Func,
reflect.Interface, reflect.Map,
reflect.Ptr, reflect.Slice},
reflect.Ptr, reflect.Slice,
reflect.UnsafePointer},
kind)

if isNilableKind && value.IsNil() {
Expand Down
9 changes: 7 additions & 2 deletions assert/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"
"testing"
"time"
"unsafe"
)

var (
Expand Down Expand Up @@ -424,7 +425,9 @@ func TestNotNil(t *testing.T) {
if NotNil(mockT, (*struct{})(nil)) {
t.Error("NotNil should return false: object is (*struct{})(nil)")
}

if NotNil(mockT, (unsafe.Pointer)(nil)) {
t.Error("NotNil should return false for empty unsafe.Pointer")
}
}

func TestNil(t *testing.T) {
Expand All @@ -440,7 +443,9 @@ func TestNil(t *testing.T) {
if Nil(mockT, new(AssertionTesterConformingObject)) {
t.Error("Nil should return false: object is not nil")
}

if !Nil(mockT, (unsafe.Pointer)(nil)) {
t.Error("Nil should return true for empty unsafe.Pointer")
}
}

func TestTrue(t *testing.T) {
Expand Down