-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: testing: testing.T.IsNil #70719
Comments
I don't like that it encourages checks / tests to fail without context |
@seankhliao what about the |
Hi @glossd, I suspect this has already been proposed, discussed, and declined. Would you mind at least skimming the discussions in the issues linked by the @gabyhelp robot above (for example, #7009) to help check if that suspicion is true, as well as review this FAQ: https://go.dev/doc/faq#testing_framework Also note that in the interests of efficiency and to help avoid re-hashing old discussions, the Go project generally does not reconsider prior proposal decisions unless there is significant new information (as described for example in the "Reconsideration" section here). |
@thepudds, the person asked for assertions. I feel this is a special case because the |
I wrote my own assertion library, and I don't think this makes sense for the standard library. In my own code, I'm happy to follow my own philosophy about test errors and how they should be reported. For the standard library though, I feel like there should really just be universal, low level tools people can use to build their own systems instead of something that imposes its own opinion on users. |
This comment was marked as resolved.
This comment was marked as resolved.
I think this is a dupe of #7009, and for the same reason we encourage error wrapping with details, we encourage failing tests with sufficient context. a test failure with a non nil error like "unexpected eof" is not very informative on its own. |
@seankhliao that Issuer is talking about helper assertion functions and has zero arguments. |
Hi @glossd, did you have a chance to at least skim through all the prior issues that the @gabybot found, as requested above? Also, would you say that there is overlap with your proposal and comments like #45650 (comment):
Would you say that the rationale for closing #45650 in #45650 (comment) for example would apply to your proposal here as well? In other words, even if you view some of the details as being different, does that rationale still apply despite any differences?
In any event, I do believe your proposal has been discussed before and that Sean is correct to close this. |
@thepudds my proposal is about checking values that do not cary any information with IsNil, IsZero methods. |
Proposal Details
Go Wiki explains that assertions are bad because they either
Often, in tests, we need to check the errors on
nil
. If it's not, it indicates a function failure.This is a classic way of handling errors in tests.
I propose to add the
IsNil
method to the common testing type.It would result in code like this:
I would also like to point out that the
nil
or zero value doesn't carry any information and perhapsIsZero
method should be added as well.However, to prevent any possible abuse of assertions, we could limit the parameter type to the error interface.
E.g.
The text was updated successfully, but these errors were encountered: