-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
NotSame
should fail if args are not pointers
#1661
Comments
This is a simple bug, the signature of func samePointers(first, second interface{}) (same bool, ok bool) |
I'd love to take this up. Could you assign this to me? |
Thank you. Im looking into the issue. |
Hi @brackendawson , |
…nercloud/fleeting-plugin-hetzner!175) This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/stretchr/testify](https://github.com/stretchr/testify) | require | minor | `v1.9.0` -> `v1.10.0` | --- ### Release Notes <details> <summary>stretchr/testify (github.com/stretchr/testify)</summary> ### [`v1.10.0`](https://github.com/stretchr/testify/releases/tag/v1.10.0) [Compare Source](stretchr/testify@v1.9.0...v1.10.0) #### What's Changed ##### Functional Changes - Add PanicAssertionFunc by [@​fahimbagar](https://github.com/fahimbagar) in stretchr/testify#1337 - assert: deprecate CompareType by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1566 - assert: make YAML dependency pluggable via build tags by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1579 - assert: new assertion NotElementsMatch by [@​hendrywiranto](https://github.com/hendrywiranto) in stretchr/testify#1600 - mock: in order mock calls by [@​ReyOrtiz](https://github.com/ReyOrtiz) in stretchr/testify#1637 - Add assertion for NotErrorAs by [@​palsivertsen](https://github.com/palsivertsen) in stretchr/testify#1129 - Record Return Arguments of a Call by [@​jayd3e](https://github.com/jayd3e) in stretchr/testify#1636 - assert.EqualExportedValues: accepts everything by [@​redachl](https://github.com/redachl) in stretchr/testify#1586 ##### Fixes - assert: make tHelper a type alias by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1562 - Do not get argument again unnecessarily in Arguments.Error() by [@​TomWright](https://github.com/TomWright) in stretchr/testify#820 - Fix time.Time compare by [@​myxo](https://github.com/myxo) in stretchr/testify#1582 - assert.Regexp: handle \[]byte array properly by [@​kevinburkesegment](https://github.com/kevinburkesegment) in stretchr/testify#1587 - assert: collect.FailNow() should not panic by [@​marshall-lee](https://github.com/marshall-lee) in stretchr/testify#1481 - mock: simplify implementation of FunctionalOptions by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1571 - mock: caller information for unexpected method call by [@​spirin](https://github.com/spirin) in stretchr/testify#1644 - suite: fix test failures by [@​stevenh](https://github.com/stevenh) in stretchr/testify#1421 - Fix issue [#​1662](stretchr/testify#1662) (comparing infs should fail) by [@​ybrustin](https://github.com/ybrustin) in stretchr/testify#1663 - NotSame should fail if args are not pointers [#​1661](stretchr/testify#1661) by [@​sikehish](https://github.com/sikehish) in stretchr/testify#1664 - Increase timeouts in Test_Mock_Called_blocks to reduce flakiness in CI by [@​sikehish](https://github.com/sikehish) in stretchr/testify#1667 - fix: compare functional option names for indirect calls by [@​arjun-1](https://github.com/arjun-1) in stretchr/testify#1626 ##### Documantation, Build & CI - .gitignore: ignore "go test -c" binaries by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1565 - mock: improve doc by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1570 - mock: fix FunctionalOptions docs by [@​snirye](https://github.com/snirye) in stretchr/testify#1433 - README: link out to the excellent testifylint by [@​brackendawson](https://github.com/brackendawson) in stretchr/testify#1568 - assert: fix typo in comment by [@​JohnEndson](https://github.com/JohnEndson) in stretchr/testify#1580 - Correct the EventuallyWithT and EventuallyWithTf example by [@​JonCrowther](https://github.com/JonCrowther) in stretchr/testify#1588 - CI: bump softprops/action-gh-release from 1 to 2 by [@​dependabot](https://github.com/dependabot) in stretchr/testify#1575 - mock: document more alternatives to deprecated AnythingOfTypeArgument by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1569 - assert: Correctly document EqualValues behavior by [@​brackendawson](https://github.com/brackendawson) in stretchr/testify#1593 - fix: grammar in godoc by [@​miparnisari](https://github.com/miparnisari) in stretchr/testify#1607 - .github/workflows: Run tests for Go 1.22 by [@​HaraldNordgren](https://github.com/HaraldNordgren) in stretchr/testify#1629 - Document suite's lack of support for t.Parallel by [@​brackendawson](https://github.com/brackendawson) in stretchr/testify#1645 - assert: fix typos in comments by [@​alexandear](https://github.com/alexandear) in stretchr/testify#1650 - mock: fix doc comment for NotBefore by [@​alexandear](https://github.com/alexandear) in stretchr/testify#1651 - Generate better comments for require package by [@​Neokil](https://github.com/Neokil) in stretchr/testify#1610 - README: replace Testify V2 notice with [@​dolmen](https://github.com/dolmen)'s V2 manifesto by [@​hendrywiranto](https://github.com/hendrywiranto) in stretchr/testify#1518 #### New Contributors - [@​fahimbagar](https://github.com/fahimbagar) made their first contribution in stretchr/testify#1337 - [@​TomWright](https://github.com/TomWright) made their first contribution in stretchr/testify#820 - [@​snirye](https://github.com/snirye) made their first contribution in stretchr/testify#1433 - [@​myxo](https://github.com/myxo) made their first contribution in stretchr/testify#1582 - [@​JohnEndson](https://github.com/JohnEndson) made their first contribution in stretchr/testify#1580 - [@​JonCrowther](https://github.com/JonCrowther) made their first contribution in stretchr/testify#1588 - [@​miparnisari](https://github.com/miparnisari) made their first contribution in stretchr/testify#1607 - [@​marshall-lee](https://github.com/marshall-lee) made their first contribution in stretchr/testify#1481 - [@​spirin](https://github.com/spirin) made their first contribution in stretchr/testify#1644 - [@​ReyOrtiz](https://github.com/ReyOrtiz) made their first contribution in stretchr/testify#1637 - [@​stevenh](https://github.com/stevenh) made their first contribution in stretchr/testify#1421 - [@​jayd3e](https://github.com/jayd3e) made their first contribution in stretchr/testify#1636 - [@​Neokil](https://github.com/Neokil) made their first contribution in stretchr/testify#1610 - [@​redachl](https://github.com/redachl) made their first contribution in stretchr/testify#1586 - [@​ybrustin](https://github.com/ybrustin) made their first contribution in stretchr/testify#1663 - [@​sikehish](https://github.com/sikehish) made their first contribution in stretchr/testify#1664 - [@​arjun-1](https://github.com/arjun-1) made their first contribution in stretchr/testify#1626 **Full Changelog**: stretchr/testify@v1.9.0...v1.10.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yOC4wIiwidXBkYXRlZEluVmVyIjoiMzkuMjguMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
#### Description Fix the TestPerfCounter_Reset that is failing consistently. ```terminal === FAIL: . TestPerfCounter_Reset (0.00s) watcher_test.go:131: Error Trace: D:/a/opentelemetry-collector-contrib/opentelemetry-collector-contrib/pkg/winperfcounters/watcher_test.go:131 Error: Both arguments must be pointers Test: TestPerfCounter_Reset ``` Root case: after upgrading `testify` circa of 2 weeks ago, since it included: > NotSame should fail if args are not pointers stretchr/testify#1661 by @sikehish in stretchr/testify#1664 See https://github.com/stretchr/testify/releases #### Testing Local test run Co-authored-by: Antoine Toulme <[email protected]>
Hi! What about slices? As now Thus - |
This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/stretchr/testify](https://github.com/stretchr/testify) | require | minor | `v1.9.0` -> `v1.10.0` | --- ### Release Notes <details> <summary>stretchr/testify (github.com/stretchr/testify)</summary> ### [`v1.10.0`](https://github.com/stretchr/testify/releases/tag/v1.10.0) [Compare Source](stretchr/testify@v1.9.0...v1.10.0) #### What's Changed ##### Functional Changes - Add PanicAssertionFunc by [@​fahimbagar](https://github.com/fahimbagar) in stretchr/testify#1337 - assert: deprecate CompareType by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1566 - assert: make YAML dependency pluggable via build tags by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1579 - assert: new assertion NotElementsMatch by [@​hendrywiranto](https://github.com/hendrywiranto) in stretchr/testify#1600 - mock: in order mock calls by [@​ReyOrtiz](https://github.com/ReyOrtiz) in stretchr/testify#1637 - Add assertion for NotErrorAs by [@​palsivertsen](https://github.com/palsivertsen) in stretchr/testify#1129 - Record Return Arguments of a Call by [@​jayd3e](https://github.com/jayd3e) in stretchr/testify#1636 - assert.EqualExportedValues: accepts everything by [@​redachl](https://github.com/redachl) in stretchr/testify#1586 ##### Fixes - assert: make tHelper a type alias by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1562 - Do not get argument again unnecessarily in Arguments.Error() by [@​TomWright](https://github.com/TomWright) in stretchr/testify#820 - Fix time.Time compare by [@​myxo](https://github.com/myxo) in stretchr/testify#1582 - assert.Regexp: handle \[]byte array properly by [@​kevinburkesegment](https://github.com/kevinburkesegment) in stretchr/testify#1587 - assert: collect.FailNow() should not panic by [@​marshall-lee](https://github.com/marshall-lee) in stretchr/testify#1481 - mock: simplify implementation of FunctionalOptions by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1571 - mock: caller information for unexpected method call by [@​spirin](https://github.com/spirin) in stretchr/testify#1644 - suite: fix test failures by [@​stevenh](https://github.com/stevenh) in stretchr/testify#1421 - Fix issue [#​1662](stretchr/testify#1662) (comparing infs should fail) by [@​ybrustin](https://github.com/ybrustin) in stretchr/testify#1663 - NotSame should fail if args are not pointers [#​1661](stretchr/testify#1661) by [@​sikehish](https://github.com/sikehish) in stretchr/testify#1664 - Increase timeouts in Test_Mock_Called_blocks to reduce flakiness in CI by [@​sikehish](https://github.com/sikehish) in stretchr/testify#1667 - fix: compare functional option names for indirect calls by [@​arjun-1](https://github.com/arjun-1) in stretchr/testify#1626 ##### Documantation, Build & CI - .gitignore: ignore "go test -c" binaries by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1565 - mock: improve doc by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1570 - mock: fix FunctionalOptions docs by [@​snirye](https://github.com/snirye) in stretchr/testify#1433 - README: link out to the excellent testifylint by [@​brackendawson](https://github.com/brackendawson) in stretchr/testify#1568 - assert: fix typo in comment by [@​JohnEndson](https://github.com/JohnEndson) in stretchr/testify#1580 - Correct the EventuallyWithT and EventuallyWithTf example by [@​JonCrowther](https://github.com/JonCrowther) in stretchr/testify#1588 - CI: bump softprops/action-gh-release from 1 to 2 by [@​dependabot](https://github.com/dependabot) in stretchr/testify#1575 - mock: document more alternatives to deprecated AnythingOfTypeArgument by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1569 - assert: Correctly document EqualValues behavior by [@​brackendawson](https://github.com/brackendawson) in stretchr/testify#1593 - fix: grammar in godoc by [@​miparnisari](https://github.com/miparnisari) in stretchr/testify#1607 - .github/workflows: Run tests for Go 1.22 by [@​HaraldNordgren](https://github.com/HaraldNordgren) in stretchr/testify#1629 - Document suite's lack of support for t.Parallel by [@​brackendawson](https://github.com/brackendawson) in stretchr/testify#1645 - assert: fix typos in comments by [@​alexandear](https://github.com/alexandear) in stretchr/testify#1650 - mock: fix doc comment for NotBefore by [@​alexandear](https://github.com/alexandear) in stretchr/testify#1651 - Generate better comments for require package by [@​Neokil](https://github.com/Neokil) in stretchr/testify#1610 - README: replace Testify V2 notice with [@​dolmen](https://github.com/dolmen)'s V2 manifesto by [@​hendrywiranto](https://github.com/hendrywiranto) in stretchr/testify#1518 #### New Contributors - [@​fahimbagar](https://github.com/fahimbagar) made their first contribution in stretchr/testify#1337 - [@​TomWright](https://github.com/TomWright) made their first contribution in stretchr/testify#820 - [@​snirye](https://github.com/snirye) made their first contribution in stretchr/testify#1433 - [@​myxo](https://github.com/myxo) made their first contribution in stretchr/testify#1582 - [@​JohnEndson](https://github.com/JohnEndson) made their first contribution in stretchr/testify#1580 - [@​JonCrowther](https://github.com/JonCrowther) made their first contribution in stretchr/testify#1588 - [@​miparnisari](https://github.com/miparnisari) made their first contribution in stretchr/testify#1607 - [@​marshall-lee](https://github.com/marshall-lee) made their first contribution in stretchr/testify#1481 - [@​spirin](https://github.com/spirin) made their first contribution in stretchr/testify#1644 - [@​ReyOrtiz](https://github.com/ReyOrtiz) made their first contribution in stretchr/testify#1637 - [@​stevenh](https://github.com/stevenh) made their first contribution in stretchr/testify#1421 - [@​jayd3e](https://github.com/jayd3e) made their first contribution in stretchr/testify#1636 - [@​Neokil](https://github.com/Neokil) made their first contribution in stretchr/testify#1610 - [@​redachl](https://github.com/redachl) made their first contribution in stretchr/testify#1586 - [@​ybrustin](https://github.com/ybrustin) made their first contribution in stretchr/testify#1663 - [@​sikehish](https://github.com/sikehish) made their first contribution in stretchr/testify#1664 - [@​arjun-1](https://github.com/arjun-1) made their first contribution in stretchr/testify#1626 **Full Changelog**: stretchr/testify@v1.9.0...v1.10.0 </details> --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC44MC4wIiwidXBkYXRlZEluVmVyIjoiMzguODAuMCIsInRhcmdldEJyYW5jaCI6Im1hc3RlciIsImxhYmVscyI6W119--> See merge request alpine/infra/build-server-status!18
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. |
https://go.dev/play/p/4kJugQJZmaG package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCaseA(t *testing.T) {
s1 := []string{"a"}
s2 := []string{"a"}
assert.Equal(t, s1, s2)
assert.NotSame(t, s1, s2)
}
func matchString(a, b string) (bool, error) {
return a == b, nil
}
func main() {
testSuite := []testing.InternalTest{
{
Name: "TestCaseA",
F: TestCaseA,
},
}
testing.Main(matchString, testSuite, nil, nil)
} This change has broken a number of tests I have that ensure an |
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. func TestCaseA(t *testing.T) {
s1 := []string{"a"}
s1b := s1
s2 := []string{"a"}
assert.Same(t, s1, s1b) // false
assert.Same(t, s1, s2) // false
assert.NotSame(t, s1, s1b) // true
assert.NotSame(t, s1, s2) // true
} 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. |
#### Description Fix the TestPerfCounter_Reset that is failing consistently. ```terminal === FAIL: . TestPerfCounter_Reset (0.00s) watcher_test.go:131: Error Trace: D:/a/opentelemetry-collector-contrib/opentelemetry-collector-contrib/pkg/winperfcounters/watcher_test.go:131 Error: Both arguments must be pointers Test: TestPerfCounter_Reset ``` Root case: after upgrading `testify` circa of 2 weeks ago, since it included: > NotSame should fail if args are not pointers stretchr/testify#1661 by @sikehish in stretchr/testify#1664 See https://github.com/stretchr/testify/releases #### Testing Local test run Co-authored-by: Antoine Toulme <[email protected]>
Ah, seeing that this uncovers the actual behavior, and is not a change to that behavior, changes things. Thanks for your explanation. |
#### Description Fix the TestPerfCounter_Reset that is failing consistently. ```terminal === FAIL: . TestPerfCounter_Reset (0.00s) watcher_test.go:131: Error Trace: D:/a/opentelemetry-collector-contrib/opentelemetry-collector-contrib/pkg/winperfcounters/watcher_test.go:131 Error: Both arguments must be pointers Test: TestPerfCounter_Reset ``` Root case: after upgrading `testify` circa of 2 weeks ago, since it included: > NotSame should fail if args are not pointers stretchr/testify#1661 by @sikehish in stretchr/testify#1664 See https://github.com/stretchr/testify/releases #### Testing Local test run Co-authored-by: Antoine Toulme <[email protected]>
Discussed in #1660
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?
The text was updated successfully, but these errors were encountered: