cpp-coveralls icon indicating copy to clipboard operation
cpp-coveralls copied to clipboard

--include or --exclude options doesn't seem to work at all

Open HerbertKoelman opened this issue 6 years ago • 3 comments

For example this excludes nothing:

coveralls --dryrun --root CMakeFiles/ --exclude-pattern "/usr/.*" --exclude-pattern "*.gtest.*"

According to the somewhat absent documentation, you would expect:

  • everything that starts with /usr/ should be excluded, but it's not
  • everything that contains gtest should be exclude, but it's not

HerbertKoelman avatar Jun 08 '19 13:06 HerbertKoelman

I'm having the same issue, --exclude-pattern is not excluding any of the directories I specify.

adam-stamand avatar Aug 15 '19 07:08 adam-stamand

I've spent a while playing with it, and got it to work for my needs. For anyone who's struggling like I did:

  • Ensure you set the root to the project root ( using the -r option). cpp-coveralls has a segment of code that discards parent directories, so if the root is set to a project subdirectory, you won't be able to get coverage on the rest of the project.

  • The excluding options apply to different stages of processing, confusingly.

    • The --exclude option will prevent files/directories from being run with gcov. Keep in mind the directories are relative to the root that you set with the -r option, even though gcov will print out paths such as "/usr/foo/bar.cpp".
    • The --exclude-pattern option is not used to determine what gets run with gcov, but instead it is used to filter out specific files/directories from being included in the report that gets sent to coveralls.io.
  • The --include option, similar to the --exclude-pattern option, is used to select specific files/directories to be included in the report. The --include option does not effect what gets run with gcov.

For my project, I have unit tests (using GTest), an example program, and benchmarking. To prevent cpp-coveralls from getting coverage of my example program and only get coverage using my unit tests, I had to be specific in my --exclude. Below is what I used in my .travis.yml to get coverage working for my project:

coveralls -r .. -i "src/" -i "test/" --exclude "utils" --exclude "benchmark" --exclude "example" --exclude "build/CMakeFiles/memory_allocator.dir/" --gcov-options '-lp' --verbose

If you want to reference anything from my project, you can find it here https://github.com/adam-stamand/memory-allocators. Hope this helps somebody.

adam-stamand avatar Aug 15 '19 12:08 adam-stamand

Which of "--exclude", "--exclude-pattern", or "--exclude-lines-pattern" would work in conjunction with the -l FILE option?

-l FILE, --lcov-file FILE
                        Upload lcov generated info file

I have a pre-existing coverage.info file. Uploading it with cpp-coveralls. Trying to exclude files with "--exclude-pattern".

The fix seems to be lcov --remove filename instead of using cpp-coveralls, for that particular step.

It would be great if @adam-stamand (or someone else) could add a new paragraph in the README that more verbosely clarifies the differences between "--exclude", "--exclude-pattern" and "--exclude-lines-pattern", since the description of all three seems to be "exclude file or directory".

sdarwin avatar Sep 17 '22 19:09 sdarwin