1

I have the line lcov -c -i -d . -o cov_init.infowhich captures the coverage data from an initial point of zero from a directory but I want it to ignore some directories. I was thinking of using a conditional statement but I'm new to using linux and not sure on how to write the conditional statement regarding the directories that I don't want lcov to display

newbie_at_linux
  • 35
  • 1
  • 2
  • 8
  • Have you tried something like `iconv .... | grep -E -v '/path1/to/exclude|/path2/to/exclude|/path3/to/exclude|....'` ? Get 1 dir to work, then add more, separated by `|` (the `grep` "OR"` operator). Good luck. – shellter Jun 13 '16 at 16:48
  • @shellter can you give me more detail on the syntax. For instance why is written like /path1/to/exclude – newbie_at_linux Jun 13 '16 at 17:49
  • `/path1/to/exclude`, etc are strictly a place holders. You'll have to review your `iconv` output, decide which directories you want to exclude, and then assemble a list like `/path1/...|/path2/...|....` The `-v` option means "skip lines that contain the search targets" (a negative grep, if you like). You might need to experiment with a small file to understand how regular grep works, then `grep -v srchTarg`, and then `grep -E -v 'excludeTarg1|excludeTarg2|...`. Then apply that knowledge to your `iconv` output. Good luck. – shellter Jun 13 '16 at 18:19
  • And see this answer for a good intro to basic (non `-v`) greps : http://unix.stackexchange.com/a/37316/6122 . Good luck. – shellter Jun 13 '16 at 18:51

1 Answers1

0

If you want to exclude all external sources (e.g., system/standard libraries) from your coverage reports, use the --no-external option in the LCOV command, e.g.:

lcov -c -i -d . --no-external -o cov_init.info

If you want to be more specific, use the --remove option to explicitly specify what to remove from your tracefile. The syntax is lcov --remove tracefile pattern1 [pattern2...] -o new_tracefile, e.g.:

lcov --remove cov_init.info "/path1/to/exclude*" "/local/package/lib/*" -o cov_init2.info

Note that pattern is interpreted as shell pattern/wildcard, not as regex.

Luv2code
  • 1,079
  • 8
  • 14