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, cmd/go: go test reports wrong compiler error line numbers when using -coverprofile #6329

Closed
josharian opened this issue Sep 4, 2013 · 7 comments
Milestone

Comments

@josharian
Copy link
Contributor

What steps will reproduce the problem?

1. Create a test containing a syntax error, such as http://play.golang.org/p/cIDNFBtU7Z
2. go test .
3. go test . -coverprofile=c.out


What is the expected output?

Both invocations of go test report the syntax error in the same place.


What do you see instead?

$ go test .
...
./simpletest.go:8: undefined: hi
...

$ go test . -coverprofile=c.out
...
/var/folders/jw/xrvq7wz95p5bwvjyx9yc2npm09k844/T/go-build500502516/.../simpletest.go:9:
undefined: hi
...


Note that with -coverprofile, the error is (incorrectly) reported as being on line 9.

Which version are you using?  (run 'go version')

go version devel +6b0ef65315eb Wed Sep 04 13:26:49 2013 -0700 darwin/amd64


Please provide any additional information below.

Introduced since go 1.1.1.
@robpike
Copy link
Contributor

robpike commented Sep 5, 2013

Comment 1:

The source rewriting done by the coverage tool, coupled with the inability to add line
directives to the output via the AST, makes this very hard if not exactly impossible to
fix. Since the coverage tool isn't much use until your program can be compiled and run,
the problem isn't worth the attention a fix would require.
If it becomes possible to add comments to the AST through go/ast, this will be easy to
fix, but I suspect a new ast package will be the real place to fix this.

Labels changed: added priority-someday, removed priority-triage.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 2:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 4:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 5:

Labels changed: added repo-tools.

sarahhodne added a commit to travis-ci/worker that referenced this issue Jan 19, 2015
There's a bug in Go cover that causes the line numbers to get rewritten
(golang/go#6329), so in order to debug runtime panics we'd need a way
to run the tests without the coverage tool and get the right line
number for where the panic happens.
@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title go.tools/cmd/cover, cmd/go: go test reports wrong syntax error line numbers when using -coverprofile x/tools/cmd/cover, cmd/go: go test reports wrong syntax error line numbers when using -coverprofile Apr 14, 2015
@rsc rsc modified the milestones: Unreleased, Unplanned Apr 14, 2015
@rsc rsc removed the repo-tools label Apr 14, 2015
@gopherbot
Copy link

CL https://golang.org/cl/38640 mentions this issue.

gopherbot pushed a commit that referenced this issue May 22, 2017
Due to the fact that -cover injects additional code to the original
source, tests run with -cover will often have incorrect line numbers.

Also includes docs for -list regexp missed by ba8ff87

Updates #6329

Change-Id: I87f0618ac31e96071bca61055cc17c0cbdee208a
Reviewed-on: https://go-review.googlesource.com/38640
Reviewed-by: Rob Pike <r@golang.org>
@rsc rsc modified the milestones: Unreleased, Go1.10 Nov 10, 2017
@rsc rsc changed the title x/tools/cmd/cover, cmd/go: go test reports wrong syntax error line numbers when using -coverprofile cmd/cover, cmd/go: go test reports wrong syntax error line numbers when using -coverprofile Nov 10, 2017
@rsc rsc changed the title cmd/cover, cmd/go: go test reports wrong syntax error line numbers when using -coverprofile cmd/cover, cmd/go: go test reports wrong compiler error line numbers when using -coverprofile Nov 10, 2017
@gopherbot
Copy link

Change https://golang.org/cl/77151 mentions this issue: cmd/cover: add //line comment pointing to original file

@gopherbot
Copy link

Change https://golang.org/cl/77150 mentions this issue: cmd/cover: modify source as text, not as AST

gopherbot pushed a commit that referenced this issue Nov 16, 2017
Now that cover does not modify the formatting of the original file
or add any newline characters, we can make it print a //line comment
pointing back at the original, and compiler errors and panics will
report accurate line numbers.

Fixes #6329.
Fixes #15757.

Change-Id: I7b0e386112c69beafe69e0d47c5f9e9abc87c0f5
Reviewed-on: https://go-review.googlesource.com/77151
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@golang golang locked and limited conversation to collaborators Nov 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants