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: //line directives frequently handled incorrectly #41222

Open
pjweinb opened this issue Sep 4, 2020 · 1 comment
Open

cmd/cover: //line directives frequently handled incorrectly #41222

pjweinb opened this issue Sep 4, 2020 · 1 comment

Comments

@pjweinb
Copy link

@pjweinb pjweinb commented Sep 4, 2020

(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 lines

//
package main

produces a coverage file:

mode: set
foo.gak/main.go:6.10,8.26 2 1
foo.gak/main.go:12.2,12.19 1 1
foo.gak/main.go:8.26,11.3 2 1
foo.gak/main.go:12.19,13.21 1 0

If the first line is changed to

//line con.go:8

the coverage file changes to:

mode: set
foo.gak/main.go:12.0,14.0 2 1
foo.gak/main.go:18.0,18.0 1 1
foo.gak/main.go:14.0,17.0 2 1
foo.gak/main.go:18.0,19.0 1 0

This file does not refer to con.go, and the ranges are wrong (or, at best, imprecise) for that file, and completely wrong for main.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.]

@andybons
Copy link
Member

@andybons andybons commented Sep 8, 2020

@andybons andybons added this to the Unplanned milestone Sep 8, 2020
@pjweinb pjweinb added the Proposal label Sep 9, 2020
@ianlancetaylor ianlancetaylor modified the milestones: Unplanned, Backlog Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.