-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/cover: //line directives frequently handled incorrectly #41222
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
Comments
@golang/tools-team |
I was looking into this a little bit and here is some more background information... According to the Go Programming Language Reference, line directives can be of
The I suppose one approach would be to just fix it for WDYT? |
Change https://go.dev/cl/447957 mentions this issue: |
Go's line directive can cause the coverage data to include bogus line/column info. The extension naively assumed the coverage data position info is always valid and line/column numbers are 1-based sane numbers. Of course, that's not always true any more. The example in #2453 generated the following coverage data. mode: set blah/blah.go:3.16,5.2 1 1 blah/blah.go:7.16,9.2 1 1 blah/blah.go:13.16,98989.0 2 1 blah/blah.go:98992.0,98993.0 2 1 blah/blah.go:98989.0,98991.0 1 0 The column values were 0. The extension blindly converted them to 0-based positions by subtracting 1. This illegal range eventually made the vscode to throw an exception eventually. I think the go test -cover shouldn't use the bogus line/col info in coverage profile, but that is another issue. It does not make sense to map such bogus numbers, so, this CL filters them out. For golang/go#41222 Fixes #2453 Change-Id: I31a28fecae0a01406e0dc32c48dca1fb4f7b6f0c Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/447957 Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Peter Weinberger <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
(This combines #35781, #33690, #25280, and golang/vscode-go#603)
Source files that contain //line directives confuse the coverage tool, prducing coverage output that is unhelpful or confusing to users.
For instance, a short main.go (import path
foo.gak
) with first linesproduces a coverage file:
If the first line is changed to
the coverage file changes to:
This file does not refer to
con.go
, and the ranges are wrong (or, at best, imprecise) for that file, and completely wrong formain.go
.A minimal improvement would be for the coverage tool to change user's
//line
directives to bare//
comments, so that the coverage data corresponds to the file presented to the tool. [Getting results that point to files mentioned in//line
directives would require changing the format of the tables in the generated code, at least. Even then the results might be peculiar, for instance if the generated file were run through go fmt.]The text was updated successfully, but these errors were encountered: