You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would also like to point out that the nil or zero value doesn't carry any information and perhaps IsZero 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.
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:
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 nil/zero value does not carry any information which you can report in the tests.
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.
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.
The errors should be descriptive by themselves, if it says "unexpected eof" and you don't understand the context, then your function has poor error handling. t.IsErrorNil(err) would actually enforce writing descriptive errors.
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):
I think this can be only about err != nil. As mentioned in the original proposal, that's very common in tests. A lot of time you don't care about the error, just that it didn't happen.
I think the message may not be needed, maybe it's ok to just stop at that line?
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?
If you find yourself using these five lines often, then it's easy to put them in your own library:
Personally, I would do something different, to make sure that the arguments to Check and t.Fatalf are different. And others would do different things too, as you've noted. The diversity in helpers is fine. Package testing only needs to provide the shared abstractions on which they all build.
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.
Method checking error on nil seems like something highly desired by other developers, and I agree with them.
Activity
gabyhelp commentedon Dec 7, 2024
Related Issues
Related Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
seankhliao commentedon Dec 7, 2024
I don't like that it encourages checks / tests to fail without context
Jorropo commentedon Dec 7, 2024
For context you can find third party implementations of this and more:
NoErrorNotNilNotZeroThey all use
...anyand unpack it intofmt.Sprintfto provide context.glossd commentedon Dec 7, 2024
@seankhliao what about the
.IsErrorNil(error)? You would see the name of the test and the error that failed it.thepudds commentedon Dec 7, 2024
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).
glossd commentedon Dec 7, 2024
@thepudds, the person asked for assertions. I feel this is a special case because the
nil/zero value does not carry any information which you can report in the tests.earthboundkid commentedon Dec 7, 2024
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.
seankhliao commentedon Dec 14, 2024
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.
glossd commentedon Dec 14, 2024
@seankhliao that Issuer is talking about helper assertion functions and has zero arguments.
The errors should be descriptive by themselves, if it says "unexpected eof" and you don't understand the context, then your function has poor error handling.
t.IsErrorNil(err)would actually enforce writing descriptive errors.thepudds commentedon Dec 14, 2024
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.
glossd commentedon Dec 14, 2024
@thepudds my proposal is about checking values that do not cary any information with IsNil, IsZero methods.
Method checking error on nil seems like something highly desired by other developers, and I agree with them.