Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2025
Merged

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

merged 1 commit into from
Feb 26, 2025

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