Skip to content

test: ErrorIs should support having both err and target be nil#177

Merged
shoenig merged 1 commit intoshoenig:mainfrom
SpikesDivZero:error-is-nil
Feb 26, 2025
Merged

test: ErrorIs should support having both err and target be nil#177
shoenig merged 1 commit intoshoenig:mainfrom
SpikesDivZero:error-is-nil

Conversation

@SpikesDivZero
Copy link
Contributor

@SpikesDivZero SpikesDivZero commented Feb 25, 2025

Go's built-in errors.Is returns true when both target and err are nil, but this library marks the test as a failure.

I came across this while writing a table-based test, in which I had to work around this by writing:

test.True(t, errors.Is(err, tt.wantErrIs))
// -- OR --
if tt.wantErrIs == nil {
	test.Nil(t, err)
} else {
	test.ErrorIs(t, err, tt.wantErrIs)
}

After this change is applied, the test code can be reduced to a clear statement instead.

Go's builtin errors.Is returns true when both target and err are nil.
Copy link
Owner

@shoenig shoenig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; thanks @SpikesDivZero!

@shoenig shoenig merged commit 6ae4c8d into shoenig:main Feb 26, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants