golang/go

cmd/cover, cmd/go: go test reports wrong compiler error line numbers when using -coverprofile

josharian opened this issue · 7 comments

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.

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 commented

Comment 2:

Labels changed: added go1.3maybe.

rsc commented

Comment 4:

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

rsc commented

Comment 5:

Labels changed: added repo-tools.

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

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

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