From 9e778b539c1d79c03223c4e07b9ac92b41dc1a74 Mon Sep 17 00:00:00 2001 From: Wesley Spikes Date: Tue, 25 Feb 2025 12:04:52 -0800 Subject: [PATCH] test: ErrorIs target and err both nil should pass Go's builtin errors.Is returns true when both target and err are nil. --- internal/assertions/assertions.go | 2 +- must/must_test.go | 4 ++++ test_test.go | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/assertions/assertions.go b/internal/assertions/assertions.go index 585790e..d6254e1 100644 --- a/internal/assertions/assertions.go +++ b/internal/assertions/assertions.go @@ -164,7 +164,7 @@ func EqError(err error, msg string) (s string) { } func ErrorIs(err error, target error) (s string) { - if err == nil { + if err == nil && target != nil { s = "expected non-nil error; got nil\n" return } diff --git a/must/must_test.go b/must/must_test.go index c3e7b49..2acf11f 100644 --- a/must/must_test.go +++ b/must/must_test.go @@ -165,6 +165,10 @@ func TestErrorIs_nil(t *testing.T) { ErrorIs(tc, nil, err) } +func TestErrorIs_nil_nil(t *testing.T) { + ErrorIs(t, nil, nil) +} + type FakeError string func (e FakeError) Error() string { diff --git a/test_test.go b/test_test.go index db6d857..2d12fd0 100644 --- a/test_test.go +++ b/test_test.go @@ -163,6 +163,10 @@ func TestErrorIs_nil(t *testing.T) { ErrorIs(tc, nil, err) } +func TestErrorIs_nil_nil(t *testing.T) { + ErrorIs(t, nil, nil) +} + type FakeError string func (e FakeError) Error() string {