aboutsummaryrefslogtreecommitdiffstats
path: root/check/check.go
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2024-02-11 11:13:25 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2024-02-11 11:13:25 -0500
commit3e98972271b4880bf40bf9c98564fce5bf1879d0 (patch)
tree4ca4e97accdba3a6a1e3bab7e9ce846745961ff8 /check/check.go
parentRelease v0.3.0 (diff)
downloadcheckmate-3e98972271b4880bf40bf9c98564fce5bf1879d0.zip
Add nil pointer check for Nil functions
Diffstat (limited to 'check/check.go')
-rw-r--r--check/check.go13
1 files changed, 12 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.