Skip to content
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

Forward assertion error is confusing when mistakenly calling with *testing.T #119

Closed
willfaught opened this issue Jan 14, 2015 · 2 comments

Comments

@willfaught
Copy link
Contributor

When you write this:

assert.Equal(t, a, b)

but you really meant this:

assert.Equal(a, b)

because above you did this:

assert := assert.New(t)

then you get this confusing panic, which seems to indicate that you're passing in a type that you're obviously not (string):

panic: interface conversion: interface is *Foo, not string [recovered]
    panic: interface conversion: interface is *Foo, not string

goroutine 8 [running]:
testing.func·006()
    /usr/local/Cellar/go/1.4/libexec/src/testing/testing.go:441 +0x181
github.com/stretchr/testify/assert.messageFromMsgAndArgs(0xc2080a1e98, 0x1, 0x1, 0x0, 0x0)
    /Users/Will/src/github.com/stretchr/testify/assert/assertions.go:105 +0x7b
github.com/stretchr/testify/assert.Fail(0x9135d8, 0xc2080402d0, 0xc2080ba500, 0x488, 0xc2080a1e98, 0x1, 0x1, 0x58)
    /Users/Will/src/github.com/stretchr/testify/assert/assertions.go:139 +0x4d
github.com/stretchr/testify/assert.Equal(0x9135d8, 0xc2080402d0, 0x49a3c0, 0xc2080402d0, 0x49ed80, 0xc208040510, 0xc2080a1e98, 0x1, 0x1, 0xc2080c3d01)
    /Users/Will/src/github.com/stretchr/testify/assert/assertions.go:194 +0x18a
github.com/stretchr/testify/assert.(*Assertions).Equal(0xc20802b200, 0x49a3c0, 0xc2080402d0, 0x49ed80, 0xc208040510, 0xc2080a1e98, 0x1, 0x1, 0x1)
    /Users/Will/src/github.com/stretchr/testify/assert/forward_assertions.go:38 +0x87
[...]

I think in this case it assumes the third argument is the assertion description and so expects a string type.

Perhaps the panic description could be made more helpful if it checked whether the first argument had type *testing.T and said something more helpful, like a hint that you shouldn't do that.

Note that this kind of problem happens (to me) often when I've written a lot of non-forward assertions, and then decide to use them but don't switch them all.

@bzon
Copy link

bzon commented Jun 20, 2018

I just got this error. Test are inconsistent. My travis build fails with the panic: interface conversion error` but the test in my local works just fine.

@willfaught
Copy link
Contributor Author

Closing due to no activity.

@willfaught willfaught closed this as not planned Won't fix, can't repro, duplicate, stale Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants