-
Notifications
You must be signed in to change notification settings - Fork 8
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
nil-compare: false positives for assert.Equal(t, nil, value)
(slice, channel)
#36
Comments
I wonder if the testsuite has a check that really executes the original test and the "fixed" test to verify that the behavior of testify is the same. |
@dolmen, hi!
Before I just checked in playground, but from this issue I introduced some code (show you later). About issue. It looks like func ObjectsAreEqual(expected, actual interface{}) bool {
if expected == nil || actual == nil {
return expected == actual // You cannot do this, because
// expected and actual are interfaces
}
var nilChan chan struct{}
fmt.Println(nilChan == nil) // true
fmt.Println(any(nilChan) == any(nil)) // false Also it affects |
Whether there is a bug in Testify or not (that might be fixed in the future), testifylint should aim to work with Testify as it is now and even as it was in the past, because we can expect that users are applying (and will continue to apply) testifylint on codebases that still run older versions of Testify. |
Totally agree, but not in this case. I dove deeper into your example and it's really a misuse of testify itself.
It could be difficult, because some checkers use only fresh testify functions and features. Thanks for issue! 🤝 |
assert.Equal(t, nil, []int(nil))
can't be replaced withassert.Nil(t, []int(nil))
: the behaviour of testify is different, sonil-compare
should not replace it.Same issue for
assert.Equal(t, nil, value)
ifvalue
is of typechan struct{}
.See on the Go Playground: https://go.dev/play/p/jUxLF4j-w89
Note: I found this issue when applying
testifylint
on packagegithub.com/stretchr/testify/mock
: https://github.com/stretchr/testify/blob/db8608ed63f5bd9abdd03f669f5bb80569c114b6/mock/mock_test.go#L765The text was updated successfully, but these errors were encountered: