Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
cmd/cover, cmd/go: go test reports wrong compiler error line numbers when using -coverprofile #6329
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.
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.
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 <email@example.com>
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 <firstname.lastname@example.org> Reviewed-by: Ian Lance Taylor <email@example.com>