Skip to content
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

Add assertion for NotErrorAs #1129

Merged
merged 4 commits into from
Oct 4, 2024

Conversation

palsivertsen
Copy link
Contributor

Summary

The library had implementations for ErrorIs, ErrorAs and NotErrorIs but
was missing a NotErrorAs implementation. This PR adds a NotErrorAs
function, which is the inverse of the ErrorAs function.

Changes

  • Adds NotErrorAs function and test
  • Improves existing tests (TestErrorIs, TestNotErrorIs and TestErrorAs) by comparing assertion result and testing.T flag.
  • Clarifies documentation for existing NotErrorIs function

Motivation

There's already an inverse of ErrorIs, ErrorAs should have an inverse as well.

Related issues

Closes #1066

@palsivertsen palsivertsen changed the title Not error as Add assertion for NotErrorAs Nov 30, 2021
@Antonboom
Copy link

+1 for this PR.
and take a look to #1137

@dolmen dolmen added enhancement pkg-assert Change related to package testify/assert pkg-require Change related to package testify/require labels Mar 7, 2024
}

// NotErrorAsf asserts that at none of the errors in err's chain matches target.
// This is the inverse of the ErrorAs function.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// This is the inverse of the ErrorAs function.
// This is the opposite of the ErrorAs function.

Copy link
Collaborator

Choose a reason for hiding this comment

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

None of the other negative assertions refer to their counterpart in this way. The description of their function is sufficient. Just drop this line.

assert/assertion_forward.go Outdated Show resolved Hide resolved
@mmorel-35
Copy link
Contributor

Hi @dolmen ,
Any chance this can be reviewed/merged soon?

@brackendawson
Copy link
Collaborator

brackendawson commented Oct 3, 2024

Commented on @mmorel-35 's review, I'm happy merging once resolved. This also needs a re-base. This also needs coordinating with #1646. if @palsivertsen is no longer around then feel free to open a new PR based on their commit @mmorel-35.

palsivertsen pushed a commit to palsivertsen/testify that referenced this pull request Oct 4, 2024
palsivertsen pushed a commit to palsivertsen/testify that referenced this pull request Oct 4, 2024
@palsivertsen
Copy link
Contributor Author

@brackendawson Rebased on master and addressed review feedback. Also fixed a typo.

Copy link
Collaborator

@brackendawson brackendawson left a comment

Choose a reason for hiding this comment

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

Sorry for the tennis, one more change to that doc-string. I think this slightly left field behaviour needs writing down.

@@ -2149,6 +2149,23 @@ func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{
), msgAndArgs...)
}

// NotErrorAs asserts that none of the errors in err's chain matches target.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// NotErrorAs asserts that none of the errors in err's chain matches target.
// NotErrorAs asserts that none of the errors in err's chain matches target, but if so, sets target to that error value.

palsivertsen pushed a commit to palsivertsen/testify that referenced this pull request Oct 4, 2024
palsivertsen and others added 4 commits October 4, 2024 12:43
The library already had assertions for `ErrorIs`, `NotErrorIs` and
`ErrorAs`. This commit adds the `NotErrorAs` assertion which is the
inverse of `ErrorAs`.
Checks that the assertion result matches what's set in `testing.T`.
Copy link
Collaborator

@brackendawson brackendawson left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for your contribution.

@brackendawson brackendawson merged commit 7f48972 into stretchr:master Oct 4, 2024
8 checks passed
@palsivertsen palsivertsen deleted the not-error-as branch October 4, 2024 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement pkg-assert Change related to package testify/assert pkg-require Change related to package testify/require
Projects
None yet
Development

Successfully merging this pull request may close these issues.

testify {assert|require} packages seem to be missing NotErrorAs methods.
5 participants