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).
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.
The text was updated successfully, but these errors were encountered:
This is due to an underlying bug, maybe, in go/printer. Probably the right thing to do is not to use go/printer at all and just insert the counter manipulation into the original file text (knowing the positions from go/ast). That would solve a few problems related to comments as well. But that's a pretty invasive change and won't happen for Go 1.8 or maybe even beyond. Marking Go1.9Early so we look at this early in the Go 1.9 cycle.
Note that when you do run the test you gave, the file names are different in the output as well: the line number in the -cover output refers to the cover-generated source file as well, so it's technically accurate. Of course, that source file has been deleted, so it's not terribly useful.
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.
Run-TryBot: Russ Cox <email@example.com>
Reviewed-by: Ian Lance Taylor <firstname.lastname@example.org>