-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: NotSame was returning true for non-pointers #1738
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
Conversation
The code was different that the comment. Also, it's a different behavior than the other asserters: - NotImplements fails and returns false for nil - NotElementsMatch fails and returns false for non-lists - NotEqual fails and returns false for invalid arguments - NotContains fails and returns false if a length cannot be computed - NotSubset fails and returns false if the objects are not comparable
Previous tests where very basic, and checked only the returned values. Checking the failure messages is way more important, as it helps to avoid regressions in the future.
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.
Do not remove the existing testsuites.
I want to be able to see that with your changes the existing testsuite still pass, and your new tests also.
result: false, | ||
resultErrMsg: "Not same: \n" + | ||
fmt.Sprintf("expected: %v %#v\n", p1, p1) + | ||
fmt.Sprintf("actual : %v %#v\n", p1bis, p1bis), |
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.
- Use a single
fmt.Sprintf
expression for the whole string. - Use indexed formats like
%#[1]v
to remove parameter duplication (we should do that also in Same/NotSame code, but in a separate PR). - Use
%p
like in the tested code
result: false, | ||
resultErrMsg: "Not same: \n" + | ||
fmt.Sprintf("expected: %v %#v\n", p1, p1) + | ||
fmt.Sprintf("actual : %v %#v\n", p2, p2), |
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.
- Use a single
fmt.Sprintf
expression for the whole string. - Use indexed formats like
%#[1]v
to remove parameter duplication (we should do that also in Same/NotSame code, but in a separate PR). - Use
%p
like in the tested code
expected: p1, | ||
result: false, | ||
resultErrMsg: "Expected and actual point to the same object: " + | ||
fmt.Sprintf("%v %#v\n", p1, p1), |
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.
- Use a single
fmt.Sprintf
expression for the whole string. - Use indexed formats like
%#[1]v
to remove parameter duplication (we should do that also in Same/NotSame code, but in a separate PR). - Use
%p
like in the tested code
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.
we should do that also in Same/NotSame code, but in a separate PR
Done with #1742
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.
expected: p1, | ||
result: false, | ||
resultErrMsg: "Expected and actual point to the same object: " + | ||
fmt.Sprintf("%v %#v\n", p1, p1), |
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.
we should do that also in Same/NotSame code, but in a separate PR
Done with #1742
I'm closing this PR and I will split it in two PRs. This will also allow me to switch to my fork. |
Some follow-ups: I started working locally on the changes that could land in a new PR. The more I work on the changes, the more doubtful I am if I was going in the right direction with this PR. I mean, I'm no longer sure NotSame was not OK, and the others (NotImplements,NotElementsMatch,NotEqual, NotContains, NotSubset…) weren't the ones to fix in fact |
I feel like I faced the same issue that @olivergondza had with Unless I'm wrong Oliver came to the same conclusion than mine: captureTestingT cannot be used with negative asserters like NotSame and co. Could you confirm Oliver and share your thoughts about this struct? Also I'm curious about what you said about other label than errors. Please note, I'm aware of the code you talked about and the loop on label to look for the one holding I'm just unsure what are the other labels you talked about. I feel like I should conduct a refactoring of captureTestingT, that could help to handle negative asserter like NotSame, and the other I listed in my previous post above this one. Thanks |
Glad I am not alone who was fighting with this :) Long story short, I ended up using explicit assertions on The reason
My PR introduced the whole new label for panic, that it does not examine, obviously. And I also needed contains / not contains on the entire unparsed "mismatch" message. I have spent some time looking into refactoring But as long as I can get the entire message, I am fine using |
Thanks for your detailed reply. I do feel like there are room for improvement yes. cc @brackendawson @dolmen You are right, the panic has to be handled differently. I'm still interested if you could open a PR for a refactoring suggestion of checkResultAndErrMsg |
Summary
The code was different than the comment, and the code behavior was different from other asserters
Changes
Motivation
NotSame had a different behavior than the other asserters:
Nothing returns true, and Fail.
Related to #1660, #1661, #1664
NotSame
should fail if args are not pointers #1661