ryanluker / vscode-coverage-gutters

Display test coverage generated by lcov and xml - works with many languages
https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters
MIT License
464 stars 90 forks source link

Add support for Go/Golang coverage reports #303

Open adrienjoly opened 3 years ago

adrienjoly commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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

munnik commented 3 years ago

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 commented 3 years ago

@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 commented 2 years ago

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 commented 2 years ago

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