Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR changes the tests to record their code coverage, using the Tarpaulin tool and source-based coverage (xd009642/tarpaulin#549).
Local Usage
Now when running
make test
it will record the code coverage, and print that out:It will also create a
tarpaulin-report.html
file, which can be opened to see the coverage line-by-line.I was also able to install the Coverage Gutters VS Code extension, which picked up the coverage file and showed the information inline:
Codecov
It uploads the results to Codecov so that it is easy to see over time how coverage evolves, and also for each PR how it impacts the code coverage. This is useful when refactoring or implementing new features, to make sure all branches are covered.
I enabled it on my fork, to test it out, which you can browse here:
In order to upload to Codecov, I found I had to set the token, otherwise, I would get a 404 error. This is a known bug with Codecov (codecov/codecov-action#557, codecov/feedback#126). I made the token public, instead of setting it privately so that it would be used on any PRs from forks as well (codecov/codecov-action#557 (comment)).
Before merging this, if you choose to keep this approach, you would have to make an account on Codecov, add this project, and update the token in this PR with your token for this repo. Making the token public does present some security risk (anyone would be able to submit coverage for this repo) which would have to be weighed against the advantage of allowing PRs from forks to have their coverage submitted (and compared).
Alternative using grcov
I did want to note that I did try using the
RUSTFLAGS='-Cinstrument-coverage'
env variable directly and then using grcov to convert to lcov and HTML, instead of using Tarpaulin. This does have support for branches, which is nice, but I found the lcov generation to inaccurate (mozilla/grcov#860).It also requires installing the
llvm-tools-preview
component, since it uses that to do the coverage generation, whereas Tarpaulin reimplemented what they needed in rust.Performance
I also noticed that using this coverage increased the testing time from ~2 second to ~13 second on my local machine, once things were cached. The alternative above using
instrument-coverage
directly takes ~5 seconds.