Ignore partial branches report with gcovr in my C++ project

I’m trying to use the codecov github action and gcovr in my C++ project

Everything is working so far however gcovr reports lots of partial covered branches.
I’m trying to find a way to generate a .svg badges that only takes line coverage into account and completelly ignore branch coverage as it is not a useful metric in my context, and generally ignore branches report completelly in codecov.

This is a discussed topic here: Frequently Asked Questions — gcovr 5.2 documentation
And gcovr may not be able to adress this issue as they discuss it here: Feature request: option to disable branch coverage · Issue #303 · gcovr/gcovr · GitHub

How can I tell codecov to ignore branches and just report lines ?

I tried playing the codecov.yml and branch option, but it does not seems to have any effect.

Here is my repository: https://github.com/mwestphal/test3
Here is my codecov: Codecov

Here is the relevant part of my github yml:

- name: Generate XML Coverage
  if: matrix.os == 'ubuntu-latest'
  working-directory: ${{github.workspace}}/source
  run: gcovr --exclude-unreachable-branches --exclude cxxopts.h --print-summary -x -o coverage.xml

- name: Upload coverage to Codecov
  if: matrix.os == 'ubuntu-latest'
  uses: codecov/codecov-action@v2
  with:
    files: ${{github.workspace}}/source/coverage.xml

Here is my codecov.yml:

parsers:
  gcov:
    branch_detection:
      conditional: no
      loop: no
      method: no
      macro: no

fixes:
  - "/source::"

Here is the typical gcovr log execution


Run gcovr --exclude-unreachable-branches --exclude cxxopts.h --print-summary -x -o coverage.xml
lines: 91.7% (3228 out of 3520)
branches: 51.7% (3513 out of 6794)

Here is a typical codecov github action log execution:

Run codecov/codecov-action@v2
/usr/bin/docker exec  d05eb9950d60cfe78f7b6c6bac74c5712ed418a2e90d5e1c9815066ee02566fc sh -c "cat /etc/*release | grep ^ID"
==> linux OS detected
https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
==> SHASUM file signed by key id 806bb28aed779869
==> Uploader SHASUM verified (efce57ce4781d3553cf00c3243e57b120a6d3d73dfa72bd6580d48159e8bfbd9  codecov)
==> Running version latest
==> Running version v0.1.9
/__w/_actions/codecov/codecov-action/v2/dist/codecov -n  -Q github-action-2.1.0 -f /__w/test3/test3/source/coverage.xml
[2021-11-08T18:27:15.581Z] ['info'] 
     _____          _
    / ____|        | |
   | |     ___   __| | ___  ___ _____   __
   | |    / _ \ / _` |/ _ \/ __/ _ \ \ / /
   | |___| (_) | (_| |  __/ (_| (_) \ V /
    \_____\___/ \__,_|\___|\___\___/ \_/

  Codecov report uploader 0.1.11
[2021-11-08T18:27:15.588Z] ['info'] => Project root located at: /__w/test3/test3
[2021-11-08T18:27:15.589Z] ['info'] -> No token specified or token is empty
[2021-11-08T18:27:15.686Z] ['info'] Searching for coverage files...
[2021-11-08T18:27:15.756Z] ['info'] => Found 1 possible coverage files:
  /__w/test3/test3/source/coverage.xml
[2021-11-08T18:27:15.756Z] ['info'] Processing /__w/test3/test3/source/coverage.xml...
[2021-11-08T18:27:15.776Z] ['info'] Detected GitHub Actions as the CI provider.
[2021-11-08T18:27:15.778Z] ['info'] Pinging Codecov: https://codecov.io/upload/v4?package=github-action-2.1.0-uploader-0.1.11&token=*******&branch=master&build=1436136901&build_url=https%3A%2F%2Fgithub.com%2Fmwestphal%2Ftest3%2Factions%2Fruns%2F1436136901&commit=e755107a249d3c7be951c6af2a17d0122da1e1b2&job=CMake+Build+Matrix&pr=&service=github-actions&slug=mwestphal%2Ftest3&name=&tag=&flags=&parent=
[2021-11-08T18:27:16.813Z] ['info'] Uploading...
[2021-11-08T18:27:17.062Z] ['info'] {"status":"success","resultURL":"https://codecov.io/github/mwestphal/test3/commit/e755107a249d3c7be951c6af2a17d0122da1e1b2"}

I know that I could use --exclude-throw-branches to reduce the number of branches, but this is not perfect and do not solve the problem fully.

Edit: Added relevant part of my code as I may modify my repository to run some tests soon.

@mwestphal I think you are looking for this

parsers:
  gcov:
    branch_detection:
      conditional: false
      loop: false

Here is my codecov.yml

parsers:
  gcov:
    branch_detection:
      conditional: no
      loop: no
      method: no
      macro: no

fixes:
  - "/source::"

It does not seem to have any effect. I will try with false instead of no.

Using false instead of no has no impact at all, I’ve edited my initial post to include all relevant information.

To me it looks like these branch_detection parameters is not allowing me to disable.

Ahhh my mistake @mwestphal. I thought this was gcov. I don’t think this is currently possible with Codecov. I’m moving this over to a feature request and will let the product team know.

I tried to use gcov or lcov instead of gcovr but was not able to. Could you give me an example of that ?

@mwestphal hmmm, that’s strange that it’s not working for you. Can you shoot over the commit SHA that didn’t work? I’m particularly interested in the gcov run.

So I was able to use lcov instead of gcovr with the following:

- name: Generate XML Coverage
  if: matrix.os == 'ubuntu-latest'
  working-directory: ${{github.workspace}}/source
  run: |
    lcov --base-directory . --directory . -c -o coverage.info
    lcov --remove coverage.info "*/dependencies/*" -o coverage.info

- name: Upload coverage to Codecov
  if: matrix.os == 'ubuntu-latest'
  uses: codecov/codecov-action@v2
  with:
    files: ${{github.workspace}}/source/coverage.info

lcov does not consider branches so I’m able to recover the coverage I’m looking for.

I was not able to use gcov as I did not figure out the gcov command line to scan my whole repository and build for all files.

1 Like