From cca6d0469952cfb6b8185ca93795a2f759e7f18c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20Soul=C3=A9?= Date: Sat, 23 Mar 2024 23:15:04 +0100 Subject: [PATCH] fix: as smuggle hook can return nil, check for nil just after MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime Soulé --- td/equal.go | 20 ++++++++++---------- td/t_hooks.go | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/td/equal.go b/td/equal.go index 7a611ad2..1445fdbe 100644 --- a/td/equal.go +++ b/td/equal.go @@ -140,16 +140,9 @@ func deepValueEqual(ctx ctxerr.Context, got, expected reflect.Value) (err *ctxer expected = op } - if !got.IsValid() || !expected.IsValid() { - if got.IsValid() == expected.IsValid() { - return - } - return nilHandler(ctx, got, expected) - } - - // Check if a Smuggle hook matches got type - if handled, e := ctx.Hooks.Smuggle(&got); handled { - if e != nil { + if got.IsValid() { + // Check if a Smuggle hook matches got type + if handled, e := ctx.Hooks.Smuggle(&got); handled && e != nil { // ctx.BooleanError is always false here as hooks cannot be set globally return ctx.CollectError(&ctxerr.Error{ Message: e.Error(), @@ -159,6 +152,13 @@ func deepValueEqual(ctx ctxerr.Context, got, expected reflect.Value) (err *ctxer } } + if !got.IsValid() || !expected.IsValid() { + if got.IsValid() == expected.IsValid() { + return + } + return nilHandler(ctx, got, expected) + } + // Check if a Cmp hook matches got & expected types if handled, e := ctx.Hooks.Cmp(got, expected); handled { if e == nil { diff --git a/td/t_hooks.go b/td/t_hooks.go index e85e8679..8126ca1e 100644 --- a/td/t_hooks.go +++ b/td/t_hooks.go @@ -16,8 +16,8 @@ import ( // Each function in fns has to be a function with the following // possible signatures: // -// func (got A, expected A) bool -// func (got A, expected A) error +// func (got, expected A) bool +// func (got, expected A) error // // First arg is always got, and second is always expected. //