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

Add support for Go/Golang coverage reports #303

Open
adrienjoly opened this issue Apr 14, 2021 · 6 comments
Open

Add support for Go/Golang coverage reports #303

adrienjoly opened this issue Apr 14, 2021 · 6 comments

Comments

@adrienjoly
Copy link

Is your feature request related to a problem? Please describe.
Go/Golang coverage reports do not seem directly supported by this extension.

Describe the solution you'd like
It would be awesome if the extension could understand the report generated by go test, out of the box.

Describe alternatives you've considered
I tested another extension that was supposed to display the coverage of .go files, but it failed with an error message at startup.

Additional context
Here's a workaround that I used successfully to make Vscode Coverage Gutters display the coverage of my go files, run the following command:

$ go test -v -coverprofile=go-coverage.out -covermode=atomic -coverpkg=./... ./... && go run github.com/richardlt/gocover-cobertura < go-coverage.out > coverage.xml

... then, re-activate the "watch" if necessary. You should get something like that:

image

@ryanluker
Copy link
Owner

@adrienjoly Thanks for submitting an issue!
Do you know what coverage format the go test outputs the results in?
We might be able to simply add another parser type to the already existing set (jacoco, cobertura, lcov, etc).

@adrienjoly
Copy link
Author

adrienjoly commented Apr 18, 2021 via email

@munnik
Copy link

munnik commented Apr 25, 2021

I have https://facebook.github.io/watchman/ configured to convert the go coverage to lcov format using https://github.com/jandelgado/gcov2lcov

[
    "trigger",
    ".",
    {
        "name": "coverage",
        "expression": [
            "anyof",
            [
                "match",
                "go-nmea.coverprofile",
                "wholename"
            ]
        ],
        "command": [
            "/home/munnik/go/bin/gcov2lcov",
            "-infile=go-nmea.coverprofile",
            "-outfile=lcov.info"
        ]
    }
]

This works great and the go-nmea.coverprofile file gets update the lcov.info is updated immediately.

@ryanluker
Copy link
Owner

ryanluker commented Apr 25, 2021

@munnik Thanks for that work around, it should help users in the meantime until we get around to implementing the go coverage format natively in the extension! cc @adrienjoly

@williammartin
Copy link

For anyone coming to this now, who isn't that familiar with watchman (like myself), the easiest way I found to make use of the workaround above was the watchman-make[1] command:

watchman-make -p 'coverage.out' --run "gcov2lcov -infile=coverage.out -outfile=lcov.info"

And since I had watchman already installed I also just left it in the background running the tests on save like so:

watchman-make -p '**/*.go' --run "go test -coverprofile=coverage.out ./..."

1: https://facebook.github.io/watchman/docs/watchman-make.html

@ryanluker
Copy link
Owner

@williammartin Thanks for the extra info 👍🏻, I am sure someone will find the above valuable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants