Skip to content

Commit 9e778b5

Browse files
committed
test: ErrorIs target and err both nil should pass
Go's builtin errors.Is returns true when both target and err are nil.
1 parent e20ba67 commit 9e778b5

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

internal/assertions/assertions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func EqError(err error, msg string) (s string) {
164164
}
165165

166166
func ErrorIs(err error, target error) (s string) {
167-
if err == nil {
167+
if err == nil && target != nil {
168168
s = "expected non-nil error; got nil\n"
169169
return
170170
}

must/must_test.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ func TestErrorIs_nil(t *testing.T) {
163163
ErrorIs(tc, nil, err)
164164
}
165165

166+
func TestErrorIs_nil_nil(t *testing.T) {
167+
ErrorIs(t, nil, nil)
168+
}
169+
166170
type FakeError string
167171

168172
func (e FakeError) Error() string {

0 commit comments

Comments
 (0)