vscode-coverage-gutters icon indicating copy to clipboard operation
vscode-coverage-gutters copied to clipboard

Add support for Go/Golang coverage reports

Open adrienjoly opened this issue 3 years ago • 6 comments

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

adrienjoly avatar Apr 14 '21 08:04 adrienjoly

@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).

ryanluker avatar Apr 18 '21 16:04 ryanluker

Unfortunately, I believe that Go uses its own format, for coverage reports...

You can find some pointers on how to convert to more standard formats, on this stackoverflow page: https://stackoverflow.com/questions/31413281/golang-coverprofile-output-format/39453143

adrienjoly avatar Apr 18 '21 18:04 adrienjoly

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.

munnik avatar Apr 25 '21 09:04 munnik

@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

ryanluker avatar Apr 25 '21 23:04 ryanluker

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

williammartin avatar Mar 26 '22 13:03 williammartin

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

ryanluker avatar Mar 28 '22 23:03 ryanluker