-
Notifications
You must be signed in to change notification settings - Fork 212
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 EquateErrors helper #178
Conversation
cmp/cmpopts/equate.go
Outdated
@@ -123,3 +124,36 @@ func (a timeApproximator) compare(x, y time.Time) bool { | |||
// Note: time.Time doesn't have AfterOrEqual method hence the negation. | |||
return !x.Add(a.margin).Before(y) | |||
} | |||
|
|||
// AnyError is an error that matches all other non-nil errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AnyError matches itself as well, so perhaps "...that matches any non-nil error."?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
cmp/cmpopts/equate.go
Outdated
func (anyError) Is(err error) bool { return err != nil } | ||
|
||
// EquateErrors returns a Comparer option that determines errors to be equal | ||
// if errors.Is reports them to be equal. The AnyError error can be used to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"...if errors.Is reports them to match."
I've been trying (not always successfully) to use the verb "match" for the test performed by errors.Is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
The EquateErrors helper equates errors according to errors.Is. We also declare a sentinel AnyError value that matches any non-nil error value. This adds a dependency on golang.org/x/xerrors so that we can continue to suppport go1.8, which is our current minimally supported version of Go.
The EquateErrors helper equates errors according to errors.Is.
We also declare a sentinel AnyError value that matches any
non-nil error value.
This adds a dependency on golang.org/x/xerrors so that we can
continue to suppport go1.8, which is our current minimally
supported version of Go.
Fixes #89