Code coverage with Coverage.jl in vscode

Hi,
I followed the “tutorial” on https://github.com/JuliaCI/Coverage.jl

I manage to create .cov files for my local package as well as an lcov file after running the command LCOV.write("coverage-lcov.info", coverage)

Is there a way to display the report in a nice way in vscode under windows?

I have tried Coverage Gutters but it does not seem to be working. I probably don’t use it correctly…

Is there a way to render the lcov file nicely in vscode?

Thank you

3 Likes

Hey there,

Not sure if you solved your issue or not but I recently decided to do the same thing as I had codecov setup but didn’t want to have to push to github and wait for tests to run to see my code coverage, and I managed to get this working using Coverage.jl to produce a lcov.info file and use Coverage Gutters extension with it. I noticed that for Coverage Gutters the default file it looks for is “lcov.info”, so change the .info file name (call LCOV.write(“lcov.info”, coverage)) if you haven’t already.

4 Likes

I just tried Coverage.LCOV.write(filepath, coverage) does not work. Here is the complete workflow that worked for me

Julia line coverage information in VS Code

First generate .cov files:

using Pkg
Pkg.test("MyPackage"; coverage=true)

Then

using Coverage
coverage = process_folder()
open("lcov.info", "w") do io
    LCOV.write(io, coverage)
end;

Finally, open a source file in VS Code and run the command “Coverage Gutters: Display Coverage” in the VS Code Command Pallet.

4 Likes

LCOV.write(“lcov.info”, coverage)

the working call is

 LCOV.writefile(“lcov.info”, coverage)
1 Like

When I tested with the versions as of today, I needed to use the first one

LCOV.write(“lcov.info”, coverage)

It would be nice if all this workflow is directly integrated into a command in a future release of Julia’s VSCode extension.

Maybe try GitHub - JuliaCI/LocalCoverage.jl: Trivial functions for working with coverage for packages locally.
I’m using that to push coverage reports to a local Gitlab instance.

2 Likes

I have put this utility module in my .julia/config/startup.jl:

"""
    Util

`Util.test(;coverage=true)` to produce code coverage of active project. See ~/.julia/startup.jl
`Util.cleanup()` to remove .cov files.
"""
module Util
using Coverage
using Pkg

function test(;coverage=true, test_args=String[])
    Pkg.test(;coverage, julia_args=["--inline=no"], test_args)
    if coverage
        LCOV.writefile("lcov.info", process_folder())
    end
end
function cleanup()
    Coverage.clean_folder(".")
end
end # Util
2 Likes