aboutsummaryrefslogtreecommitdiffstats
path: root/check
diff options
context:
space:
mode:
Diffstat (limited to 'check')
-rw-r--r--check/check.go13
-rw-r--r--check/check_test.go11
2 files changed, 23 insertions, 1 deletions
diff --git a/check/check.go b/check/check.go
index ddb9d5a..ffc4bb5 100644
--- a/check/check.go
+++ b/check/check.go
@@ -3,6 +3,7 @@ package check
import (
"errors"
"fmt"
+ "reflect"
"strings"
"github.com/eugenetriguba/checkmate"
@@ -23,7 +24,17 @@ func Nil(t checkmate.TestingT, value any, msgAndArgs ...any) bool {
msgAndArgs = []any{"expected value to be nil, got %v", value}
}
- return check(t, value == nil, msgAndArgs...)
+ isNil := false
+ val := reflect.ValueOf(value)
+ if val.Kind() == reflect.Ptr {
+ if val.IsNil() {
+ isNil = true
+ }
+ } else if value == nil {
+ isNil = true
+ }
+
+ return check(t, isNil, msgAndArgs...)
}
// NotNil checks whether the value does not equal nil.
diff --git a/check/check_test.go b/check/check_test.go
index 9c73d52..8c6087e 100644
--- a/check/check_test.go
+++ b/check/check_test.go
@@ -343,3 +343,14 @@ func TestCheckReturnValues(t *testing.T) {
}
})
}
+
+func TestCheckNilForNilPointer(t *testing.T) {
+ mockT := &cmtest.MockT{}
+ var value *cmtest.MockT = nil
+
+ passed := Nil(mockT, value)
+
+ if !passed {
+ t.Fatal("check.Nil should have returned true for nil pointer")
+ }
+}