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: clarify the format of cover profile generated with go test -coverprofile #40251

Open
hyangah opened this issue Jul 16, 2020 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@hyangah
Copy link
Contributor

hyangah commented Jul 16, 2020

Processing the coverage profile generated from go test -coverprofile to integrate it with editors,
we need clarification of the output format.

The profile looks like

mode: set
mvdan.cc/xurls/v2/xurls.go:56.35,59.25 3 1
...

and the first element of each item (link) is often called FileName, but this is not the true file name.

Code here determines what this is. It is either the import path and the base file name, or the absolute path (isn't it platform dependent?)

See how go tool cover -html=... parses the profile output. Any editor integration work requires to implement the same to associate the coverage info with the source code.

This detail is hidden deep in the source code. We need to document this.
The cover tool documentation can be the first place users would search.

cc @ianthehat @pjweinbgo @jayconrod

@hyangah hyangah changed the title cmd/go: clarify the format of cover profile generated with go test -coverprofile cmd/cover: clarify the format of cover profile generated with go test -coverprofile Jul 16, 2020
@andybons andybons added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 16, 2020
@andybons andybons added this to the Unplanned milestone Jul 16, 2020
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
@tianon
Copy link
Contributor

tianon commented Mar 13, 2024

FWIW, I found

// First line is "mode: foo", where foo is "set", "count", or "atomic".
// Rest of file is in the format
// encoding/base64/base64.go:34.44,37.40 3 1
// where the fields are: name.go:line.column,line.column numberOfStatements count
really useful when digging into this (the closest thing to documentation I have found so far inside or outside the code).

@tianon
Copy link
Contributor

tianon commented Mar 13, 2024

Amusingly, https://go.googlesource.com/proposal/+/master/design/51430-revamp-code-coverage.md#coverage-data-file-format is some amount of documentation for this apparently "legacy" format as well. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants