Summary
Adding code to coverage reports makes it look like we’re going backwards instead of showing that we’re covering more.
Description
I have a project with existing coverage data for JavaScript sources. I’m adding coverage tests for the C++ sources as well. Combining the new coverage info shows the absolute coverage has decreased dramatically (because the C++ code is less covered on average than the JS). However I have only added lines of code to coverage. So coverage has not truly decreased.
Now I’m looking to merge my high level project changes and the codecov CI check is blocking merging. I realize an admin should be able to bypass this check, but it would be nice if this check was a little more “soft”.
As it stands, this also slightly addresses the issue of simply adding a lot of code to the codebase. I appreciate the goal of keeping the percent coverage on an upward trend but that can be a detriment to adding useful features.
My intent here is just to spark this discussion if it hasn’t already been addressed. Maybe an option doesn’t make sense but adjusting the visuals/graphs to more accurately reflect the changes might be nice. For instance, the sunburst/icicle graphs could more clearly reflect the blocks of code that were added to coverage.
Examples
serialport:master
← cinderblock:cpp-coverage
opened 08:54PM - 06 Sep 21 UTC
Coverage tests are wonderful.
This PR adds support for running coverage tests… on this package's [**C++** sources](https://codecov.io/gh/serialport/node-serialport/tree/4f4d9e89698a311ab6bb6c8504c09820e3109357/packages/bindings/src) _alongside_ **JavaScript**'s!
| | [Before](https://codecov.io/gh/serialport/node-serialport/tree/c8ca2fcb789955d3f4ad9dc9a8bdd4dff1e8cb4a) | [After](https://codecov.io/gh/serialport/node-serialport/tree/4f4d9e89698a311ab6bb6c8504c09820e3109357) | [Change](https://app.codecov.io/gh/serialport/node-serialport/compare/2314/tree) |
| --- | ---: | ---: | ---: |
| Covered Lines | 1 019 | 1 397 | + 37% |
| Uncovered Lines | 96 | 1 219 | + 1 170% |
| Tracked Lines | 1 115 | 2 616 | + 135% |
| Coverage | 91% | 53% | ⚠️- 42% |
| Sunburst | [](https://codecov.io/gh/serialport/node-serialport/commit/c8ca2fcb789955d3f4ad9dc9a8bdd4dff1e8cb4a/graphs/sunburst) | Update: codecov broke this image!<br/>[ ](https://codecov.io/gh/serialport/node-serialport/commit/33bc2401ed2a9611d5642ac2372e54c53d67d6b3/graphs/sunburst)| |
### [Before](https://codecov.io/gh/serialport/node-serialport/tree/c8ca2fcb789955d3f4ad9dc9a8bdd4dff1e8cb4a/packages/bindings)
[](https://codecov.io/gh/serialport/node-serialport/tree/c8ca2fcb789955d3f4ad9dc9a8bdd4dff1e8cb4a/packages/bindings)
### [After](https://codecov.io/gh/serialport/node-serialport/tree/33bc2401ed2a9611d5642ac2372e54c53d67d6b3/packages/bindings)
Update: codecov broke this image!<br/>
[](https://codecov.io/gh/serialport/node-serialport/tree/33bc2401ed2a9611d5642ac2372e54c53d67d6b3/packages/bindings)
### Platforms & Issues
Initially, I'd like to get coverage reports working on **Linux** and **macOS**. **Windows** looks like it will be a little more involved and could be added after initial merging of this PR.
- [x] Linux
- [x] Test
- [x] macOS
- [x] Install missing `libgcov`
- [x] Link to `libgcov` correctly
- [x] Test
- [x] Windows
- [x] `MSBuild.exe`'s `gcov` equivalent: [**OpenCppCoverage**](https://github.com/OpenCppCoverage/OpenCppCoverage)
- [x] Convert to something `codedev` can read - `cobertura`✔️
- [x] Write `package.json#scripts` and update workflows
----
### macOS
Thoughts on the "correct" way to make coverage reports on **macOS** would be appreciated. While it works, it could probably be improved.
On **Linux**, `apt install -y gcc` also installs `libgcov.a` (via dependency `libgcc-9-dev:amd64: /usr/lib/gcc/x86_64-linux-gnu/9/libgcov.a`). I've tried installing `gcovr` and `gcc` with `brew` to see if they provide the missing libraries to no avail.
~A CI test shows that `libgcov.a` is available on the system. So maybe it's just an `LD_LIBRARY_PATH` setting that needs to be set in `bindings.gyp`?~
```log
> find /usr -name 'libgcov.*'
/usr/local/lib/gcc/9/gcc/x86_64-apple-darwin19/9.4.0/libgcov.a
/usr/local/Cellar/gcc@10/10.3.0/lib/gcc/10/gcc/x86_64-apple-darwin19/10.3.0/libgcov.a
/usr/local/Cellar/gcc/11.2.0/lib/gcc/11/gcc/x86_64-apple-darwin19/11.2.0/libgcov.a
/usr/local/Cellar/gcc@9/9.4.0/lib/gcc/9/gcc/x86_64-apple-darwin19/9.4.0/libgcov.a
```
_Note: the above was run after `brew install gcc`, which probably isn't necessary and probably added a few of these._
#### Update 1
Adding `-L /usr/local/lib/gcc/9/gcc/x86_64-apple-darwin19/9.4.0` to the linker seems to have gotten it to compile on macOS, but when I run it, no `gcda` files seem to be generated... https://github.com/cinderblock/node-serialport/runs/3528420934?check_suite_focus=true
#### Update 2
Found a minimally working setup. Some improvements could probably be made.
```gyp
'xcode_settings': {
'GCC_GENERATE_TEST_COVERAGE_FILES': ['YES'],
'GCC_INSTRUMENT_PROGRAM_FLOW_ARCS': ['YES'],
'OTHER_CFLAGS+': [
'-fprofile-arcs -ftest-coverage',
],
'OTHER_LDFLAGS+': [
'-fprofile-arcs -ftest-coverage',
# There has to be a better way to do this...
'-L/usr/local/lib/gcc/9/gcc/x86_64-apple-darwin19/9.4.0',
],
},
```
----
### Windows
As for coverage tests on **Windows**, I'm not sure where to start. I'm sure there is an equivalent to `gcc`'s `gcov` but I haven't had the time to look yet.
#### Update 1
Some possibly helpful tools/links:
- ✔️[OpenCppCoverage](https://github.com/OpenCppCoverage/OpenCppCoverage)
- [Official Instructions for Visual Studio](https://docs.microsoft.com/en-us/visualstudio/test/using-code-coverage-to-determine-how-much-code-is-being-tested?view=vs-2019) - Probably not. Only works on Enterprise versions of Visual Studio.
- [Lcov for Windows](http://macqueen.us/lcov.html)
- [RKTracer](https://www.rkvalidate.com/rktracer-knowledge-base/generate-code-coverage-for-msbuild-c-cpp-projects) - Paid
- [CPPCoverage](https://github.com/atlaste/CPPCoverage) - [Maybe?](https://github.com/atlaste/CPPCoverage/issues/35#issuecomment-918122847)
#### Update 2
**CPPCoverage** is running, but not generating coverage information yet for some reason.
```bat
npm run rebuild -- -- --debug
# https://github.com/atlaste/CPPCoverage/raw/c4b5ed0e39007295ea98e120b7f4b127681fe998/CoverageExt/Resources/Coverage-x64.exe
.\Coverage-x64.exe -p . -- npm.cmd test
```
#### Update 3
[**OpenCppCoverage**](https://github.com/OpenCppCoverage/OpenCppCoverage) works!
```bat
npm i -D npm
npm run rebuild -- -- --debug
OpenCppCoverage.exe --modules "*.node" --source "packages\bindings\src\*" -- node test.js
```
Time to format the data in a way that codecov likes and then package this up into the branch!