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

Panic when calling t.Log(assert.Check()) #195

Closed
cbandy opened this issue Mar 21, 2020 · 2 comments · May be fixed by #210
Closed

Panic when calling t.Log(assert.Check()) #195

cbandy opened this issue Mar 21, 2020 · 2 comments · May be fixed by #210
Labels
Milestone

Comments

@cbandy
Copy link

cbandy commented Mar 21, 2020

The following test panics in logFailureFromBool on go version go1.13.4 linux/amd64.

func Test(t *testing.T) {
  t.Log(assert.Check(t, false))
}

It looks like the playground doesn't allow reading the source file... This is the stack when I run this locally: https://play.golang.org/p/p-JFFPJ8Y6U

--- FAIL: Test (0.00s)
    test.go:10: assertion failed: expression is false: false
panic: runtime error: index out of range [1] with length 1 [recovered]
        panic: runtime error: index out of range [1] with length 1

goroutine 18 [running]:
testing.tRunner.func1(0xc000108100)
        /home/bandychris/.local/go/src/testing/testing.go:874 +0x3a3
panic(0x59d0a0, 0xc0000a6200)
        /home/bandychris/.local/go/src/runtime/panic.go:679 +0x1b2
gotest.tools/v3/assert.logFailureFromBool(0x5e7de0, 0xc000108100, 0x0, 0x0, 0x0)
        /home/bandychris/go/pkg/mod/gotest.tools/v3@v3.0.2/assert/assert.go:169 +0x331
gotest.tools/v3/assert.assert(0x5e7de0, 0xc000108100, 0xc000117ee8, 0x5bc3c0, 0x56d860, 0x6decc0, 0x0, 0x0, 0x0, 0x4df200)
        /home/bandychris/go/pkg/mod/gotest.tools/v3@v3.0.2/assert/assert.go:112 +0xea
gotest.tools/v3/assert.Check(0x5e7de0, 0xc000108100, 0x56d860, 0x6decc0, 0x0, 0x0, 0x0, 0x5e766500)
        /home/bandychris/go/pkg/mod/gotest.tools/v3@v3.0.2/assert/assert.go:245 +0xf8
main.Test(0xc000108100)
        /home/bandychris/test.go:11 +0xbb
testing.tRunner(0xc000108100, 0x5bc418)
        /home/bandychris/.local/go/src/testing/testing.go:909 +0xc9
created by testing.(*T).Run
        /home/bandychris/.local/go/src/testing/testing.go:960 +0x350
exit status 2
@dnephin dnephin added the bug label Mar 21, 2020
@dnephin
Copy link
Member

dnephin commented Mar 21, 2020

Thank you for the bug report! I think I see what is happening. The source lookup makes an assumption that the assert.Check() is the first function on the line, but that is not always true, as your example shows.

I think it should be possible to examine the function name to ensure the correct function is being returned.

@dnephin
Copy link
Member

dnephin commented Aug 6, 2022

This panic was fixed a couple years ago in #196, so I'm going to close this issue. I've had another PR open (#210) with a more involved fix to find the right line. If this problem comes up again we can look at merging that PR.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants