-
Notifications
You must be signed in to change notification settings - Fork 27
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
make IsNil guard against nil underlying errors #64
Conversation
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.
LGTM
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.
Looks good with soem changes. Thanks!
checker.go
Outdated
@@ -73,6 +73,34 @@ func (c *equalsChecker) Check(got interface{}, args []interface{}, note func(key | |||
return nil | |||
} | |||
|
|||
// NilError is a Checker that checks whether an error value is nil. |
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.
I'd call it IsNilError
:
- it is similar to IsNil that we already have;
- it will show up in autocompletion as an alternative to IsNil;
- all other checkers are 3rd person verbs.
checker.go
Outdated
} | ||
return errors.New("got 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.
What do you think about hinting using this in the Equals checker when got is an error and want is nil?
We could add a hint with a note() for example.
checker_test.go
Outdated
expectedNegateFailure: ` | ||
error: | ||
bad check: value is not an 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.
Add a check with a nil concrete error type?
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.
Looks good with a doc change.
I think this is a great way to go. Thanks!
doc.go
Outdated
@@ -214,6 +222,18 @@ For instance: | |||
c.Assert("these are the voyages", qt.Matches, `these are .*`) | |||
c.Assert(net.ParseIP("1.2.3.4"), qt.Matches, `1.*`) | |||
|
|||
NilError |
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.
Please remove this and modify IsNil doc.
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
Almost everyone that uses quicktest for the first time uses IsNil to check for errors, but there's a subtle mistake in doing so because an error with a nil underlying value is not considered to be nil for the usual `err != nil` error checking. This change alters the semantics of `IsNil` to guard against this case. If you really do want to check that a error-implementing value is nil, you can still use qt.Equals. Also add package-level docs for ContentEquals.
Almost everyone that uses quicktest for the first time uses
IsNil to check for errors, but there's a subtle mistake in doing so
because an error with a nil underlying value is not considered
to be nil for the usual
err != nil
error checking.This change alters the semantics of
IsNil
to guard againstthis case. If you really do want to check that a error-implementing
value is nil, you can still use qt.Equals.
Also add package-level docs for ContentEquals.