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
{{ message }}
Repository navigation
NotSame should fail if args are not pointers #1661
Originally posted by n4nn31355 October 16, 2024
It's confusing and error-prone that NotSame checks nothing if any of the values is not a pointer.
Is there a reason for this, or may we consider it a bug that needs an issue?
a := struct{ byte }{}
require.NotSame(t, a, a) // Doesn't fail
require.NotSame(t, &a, &a) // Fails
```</div>
Hi! What about slices? As now NotSame will not work with slices due to samePointers checking if variables are pointers which is not the case with slice.
Thus - samePointers should probably support reflect.SliceHeader for slices?
At testify v1.9.0, when passing slices to Same it will always fail, when passing slices to NotSame it will always pass. Your test in no way ensured that your helper clones the data.
According to the docs, use of non-pointers with Same and NotSame is not valid. The change in v1.10.0 is that the invalid use is now an error.
If you want Same and NotSame to be changed to work with pointer-like types as well as pointers then that would be a new issue. I wouldn't be opposed to it being implemented.
Activity
brackendawson commentedon Oct 16, 2024
This is a simple bug, the signature of
samePointersneeds to be changed to:sikehish commentedon Oct 16, 2024
I'd love to take this up. Could you assign this to me?
sikehish commentedon Oct 17, 2024
Thank you. Im looking into the issue.
sikehish commentedon Oct 17, 2024
Hi @brackendawson ,
I've raised a PR #1664 , do let me know if any changes need to be made.
NotSame should fail if args are not pointers stretchr#1661 (stretchr#…
fix(deps): update module github.com/stretchr/testify to v1.10.0 (hetz…
[chore] Fix TestPerfCounter_Reset test (#36726)
janisbiz commentedon Dec 10, 2024
Hi! What about slices? As now
NotSamewill not work with slices due tosamePointerschecking if variables are pointers which is not the case with slice.Thus -
samePointersshould probably supportreflect.SliceHeaderfor slices?merge: deps: update module github.com/stretchr/testify to v1.10.0
brackendawson commentedon Dec 14, 2024
Do you have an example that shows the regression @janisbiz?
I believe Same and NotSame would statically fail and not fail when you passed slices to them, so they never actually tested anything.
If you want to open a PR or Issue to make them work for slices & maps as I think you expected them to, then I think we'd be happy to accept that.
phughes-scwx commentedon Dec 16, 2024
https://go.dev/play/p/4kJugQJZmaG
This change has broken a number of tests I have that ensure an
http.Headerhelper "clones" data, and therefore also fails for maps.brackendawson commentedon Dec 16, 2024
At testify v1.9.0, when passing slices to Same it will always fail, when passing slices to NotSame it will always pass. Your test in no way ensured that your helper clones the data.
playground
According to the docs, use of non-pointers with Same and NotSame is not valid. The change in v1.10.0 is that the invalid use is now an error.
If you want Same and NotSame to be changed to work with pointer-like types as well as pointers then that would be a new issue. I wouldn't be opposed to it being implemented.
[chore] Fix TestPerfCounter_Reset test (open-telemetry#36726)
phughes-scwx commentedon Dec 17, 2024
Ah, seeing that this uncovers the actual behavior, and is not a change to that behavior, changes things. Thanks for your explanation.
[chore] Fix TestPerfCounter_Reset test (open-telemetry#36726)
Fix tests failing with stretchr/testify@v1.10.0
NotSame should fail if args are not pointers stretchr#1661 (stretchr#…
[chore] Fix TestPerfCounter_Reset test (open-telemetry#36726)
Introduce model.AssertNotSameMap (#34058)