Skip to content

cmd/cover: go test reports panics on wrong line when using -covermode #15757

Closed
@sarahhodne

Description

@sarahhodne
  1. What version of Go are you using (go version)?

Reproduced on both:

  • go version go1.6.2 linux/amd64
  • go version devel +3b50adb Thu May 19 18:40:53 2016 +0000 linux/amd64
  1. What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/henrik/gopath"
GORACE=""
GOROOT="/home/henrik/.gimme/versions/go"
GOTOOLDIR="/home/henrik/.gimme/versions/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build860467575=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
  1. What did you do?

Project to reproduce is at https://github.com/henrikhodne/go-cover-test-panic (requires multiple files, otherwise I'd use play.golang.org).

  1. What did you expect to see?

I'd expect the stack trace from go test with and without -covermode=count to report the panic on the same line (foo.go:7).

  1. What did you see instead?

When enabling the coverage tool (go test -covermode=count ./...), the stack trace indicates that the panic is on foo.go:9, which is incorrect (probably due to the way the coverage tool injects code to mark lines as called?)

Interestingly, the line numbers are correct when I move the Foo() function into foo_test.go.
#6329 might be related.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions