-
Notifications
You must be signed in to change notification settings - Fork 149
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
Generate coverage output for Gitlab/Cobertura? #468
Comments
Sure, I won't have time to implement it myself in the near term, but I'd be happy to review a PR to add support for it. |
@TheButlah I just ran into the same thing myself! There is actually this Python project that converts from lcov to cobertura: Since I'm using the (un"slim") official Rust docker image on GitlabCI, Python 3 is already available. Right after running - curl -O https://raw.githubusercontent.com/eriwen/lcov-to-cobertura-xml/master/lcov_cobertura/lcov_cobertura.py && chmod +x lcov_cobertura.py
- ./lcov_cobertura.py lcov.info This solves my needs for now, but is obviously less efficient than simply generating cobertura directly in grcov. |
@brycefisher Does it work fine with Gitlab CI? What about function name mangling? |
It does!! It works great. You can see test code coverage within the merge request UI...kind of awesome! Not my ideal solution (and adds a dependency to use Python for testing an otherwise pure Rust project), but its a decent workaround for the moment. RE: function name mangling, I've only worked with pure Rust -- no extern "C" style FFI or anything. Do you have a good test case in mind that would verify if name mangling works out of the box? |
Thanks a lot @brycefisher that works great! By any chance, did you find a way to also integrate the coverage summary, see #556 ? |
|
Uses the new llvm source-base coverage from nightly to generate coverage reports: - full html report as artifact - cobertura report for gitlab MR integration - output coverage summary for gitlab parsing Here is the regexp to set in gitlab as "Test coverage parsing": \s*lines\.*:\s*([\d\.]+%) Ignore sys crates when calculating coverage are those are fully generated anyway. Resources: - https://github.com/marco-c/rust-code-coverage-sample - mozilla/grcov#468 (comment) - https://www.greycastle.se/how-to-show-flutter-test-coverage-in-gitlab-ci/
Uses the new llvm source-base coverage from nightly to generate coverage reports: - full html report as artifact - cobertura report for gitlab MR integration - output coverage summary for gitlab parsing Here is the regexp to set in gitlab as "Test coverage parsing": \s*lines\.*:\s*([\d\.]+%) Resources: - https://github.com/marco-c/rust-code-coverage-sample - mozilla/grcov#468 (comment) - https://www.greycastle.se/how-to-show-flutter-test-coverage-in-gitlab-ci/
@brycefisher When I use the python (3) script on my
Any advice on what could be wrong here? Thanks. Edit: Here's a fix... only splitting once for
|
Cool! My original snippet pulled from |
Yep, thanks for mentioning that conversion script! Could you help with an issue related to GitLab? I export the generated all:
extends:
- .unit-test
script:
# Generate Cobertura report
- grcov "${COVERAGE_ZIP_NAME}" \
--source-dir . \
--binary-path ./target/debug/ \
--output-path "${COVERAGE_OUTPUT_PATH}/lcov.info" \
--output-type lcov \
--branch \
--llvm \
--ignore-not-existing \
--keep-only "mycoolcrate-*"
# Use a cargo extension to correct the code coverage results... removes extranous counts.
- rust-covfix -o "${COVERAGE_OUTPUT_PATH}/lcov.info" "${COVERAGE_OUTPUT_PATH}/lcov.info"
# outputs cobertura report at "./coverage.xml"
- python3 scripts/lcov_cobertura.py "${COVERAGE_OUTPUT_PATH}/lcov.info"
artifacts:
reports:
cobertura: coverage.xml Do I need to use the
|
Also, is there anyway to use an |
Okay, so there's two parts:
|
Oh! One more thing, i think that you also have to have a baseline from the target branch before this stuff starts being helpful. So maybe merge a trivial branch to master, or do a MR against a feature branch. Can't remember where the docs spell that out on GitlabCI.... |
You're right, the code coverage results are visible in the merge requests! I completely overlooked those green/red lines next to each line... thanks for the tip! 😄
So, for getting the code coverage result for the badge (or somehow visible on the "Overview" page of each merge request?), I have to run the quoted What's the parsing regex you used in your project settings? Do you think that |
Yeah, here what I have: |
Using the quoted + python3 scripts/lcov_cobertura.py target/debug/coverage/lcov.info
+ grep '<coverage branch-rate="' coverage.xml
+ sed -e 's/.* branch-rate="\(.\)\.\(..\)\(.\).*/Test coverage \1\2.\3%/'
Test coverage 011.2% Perhaps one of the capture groups is unnecessary? |
This seems to work alright! # raw branch-rate value
local branch_rate
branch_rate=$(grep '<coverage branch-rate="\(.*\)"' coverage.xml | sed -e 's/.* branch-rate="\(.*\)" branches-covered.*/\1/')
# multiply by 100 with bash syntax
local coverage
coverage=$(printf %.2f "$(echo "$branch_rate * 100" | bc -l)")
# format with %
echo "Test coverage ${coverage}%"
|
FYI: #599 tries to implement this for grcov. Please give it a try 🙏 |
Uses the new llvm source-base coverage from nightly to generate coverage reports: - full html report as artifact - cobertura report for gitlab MR integration - output coverage summary for gitlab parsing Here is the regexp to set in gitlab as "Test coverage parsing": \s*lines\.*:\s*([\d\.]+%) Resources: - https://github.com/marco-c/rust-code-coverage-sample - mozilla/grcov#468 (comment) - https://www.greycastle.se/how-to-show-flutter-test-coverage-in-gitlab-ci/
Cobertura output was implemented, it'd be great if one of you could add some docs in README.md to explain how to use it in GitLab (just like the "grcov with Travis" section). |
Would it be possible to add support for generating Cobertura xml coverage reports? Gitlab's coverage reporting uses Cobertura's format.
It appears as though tarpaulin supports cobertura, so it would be good if
grcov
could too.The text was updated successfully, but these errors were encountered: