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

cmd/cover: go test coverprofile wrong path at panic backtrace #20909

Closed
minaevmike opened this issue Jul 5, 2017 · 3 comments
Closed

cmd/cover: go test coverprofile wrong path at panic backtrace #20909

minaevmike opened this issue Jul 5, 2017 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@minaevmike
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.8.3 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/prog/GO"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build530360851=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

i make a simpe code to reproduce
file i.go

package sample
type I interface {
	Test()
}

type iI struct {

}

func (_ *iI) Test() {
	panic("t")
}

file sample_test.go

package sample

import "testing"

func Test_Panic(t *testing.T) {
	I := &iI{}
	I.Test()
}

What did you expect to see?

if i run this test without coverage i have normal panic backtrace

root@mike:~/prog/GO/src/github.com/minaevmike/sample/ss# go test
--- FAIL: Test_Panic (0.00s)
panic: t [recovered]
	panic: t

goroutine 5 [running]:
testing.tRunner.func1(0xc420072410)
	/usr/local/go/src/testing/testing.go:622 +0x29d
panic(0x50ad40, 0xc42000ee40)
	/usr/local/go/src/runtime/panic.go:489 +0x2cf
github.com/minaevmike/sample/ss.(*iI).Test(0x5ef6a0)
	/root/prog/GO/src/github.com/minaevmike/sample/ss/i.go:11 +0x64
github.com/minaevmike/sample/ss.Test_Panic(0xc420072410)
	/root/prog/GO/src/github.com/minaevmike/sample/ss/sample_test.go:7 +0x3b
testing.tRunner(0xc420072410, 0x5422e8)
	/usr/local/go/src/testing/testing.go:657 +0x96
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:697 +0x2ca
exit status 2
FAIL	github.com/minaevmike/sample/ss	0.003s

What did you see instead?

but if i run this test with coverprofile i have

root@mike:~/prog/GO/src/github.com/minaevmike/sample/ss# go test -v -coverprofile=c.out
=== RUN   Test_Panic
--- FAIL: Test_Panic (0.00s)
panic: t [recovered]
	panic: t

goroutine 5 [running]:
testing.tRunner.func1(0xc420072410)
	/usr/local/go/src/testing/testing.go:622 +0x29d
panic(0x50bde0, 0xc420012e40)
	/usr/local/go/src/runtime/panic.go:489 +0x2cf
github.com/minaevmike/sample/ss.(*iI).Test(0x5f06c0)
	github.com/minaevmike/sample/ss/_test/_obj_test/i.go:12 +0x6e
github.com/minaevmike/sample/ss.Test_Panic(0xc420072410)
	/root/prog/GO/src/github.com/minaevmike/sample/ss/sample_test.go:7 +0x3b
testing.tRunner(0xc420072410, 0x5434c8)
	/usr/local/go/src/testing/testing.go:657 +0x96
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:697 +0x2ca
exit status 2
FAIL	github.com/minaevmike/sample/ss	0.003s

So from this backtrace i can't undestand the line of code where panic was throw.
As i can undestand this path github.com/minaevmike/sample/ss/_test/_obj_test/i.go:12 is relative path to /tmp/go-build* dir. But it's impossible to detect the right folder. And this only happens when i run go test with coverprofile

@bradfitz bradfitz changed the title go test coverprofile wrong path at panic backtrace cmd/cover: go test coverprofile wrong path at panic backtrace Jul 5, 2017
@bradfitz bradfitz added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 5, 2017
@bradfitz bradfitz added this to the Go1.10 milestone Jul 5, 2017
@robpike
Copy link
Contributor

robpike commented Jul 5, 2017

I'm not sure I understand. Are you saying that it says line 12 rather than line 11? That's the only difference I can see. That is a known and documented issue: The line numbers for crashes and test reports are incorrect when covering is enabled.

@minaevmike
Copy link
Contributor Author

Yes, you're right. line 12 rather then line11. This behaviour make tests harder to debug in case of panic. I don't know how go test works inside, but mb it's possible to print full path to the file like /tmp/go-build123/github.com/minaevmike/sample/ss/_test/_obj_test/i.go:12 or recover this panic and map this path to the source path.

@robpike
Copy link
Contributor

robpike commented Jul 6, 2017

As "go help testflag" says,

BUG: If a compilation or test fails with coverage enabled,
the reported line numbers may be incorrect.

It's all but impossible to fix because of the way the go/ast package handles comments.

Unfortunate but unfixable.

However, there is some optimism that it can be fixed, according to #15757, of which this issue is a duplicate.

@robpike robpike closed this as completed Jul 6, 2017
@golang golang locked and limited conversation to collaborators Jul 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants