Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to focus lcov code coverage reports to just one or two directories?

I recently started using lcov to visualize my code coverage. It's a great tool.

One thing I'm noticing is that it generates code coverage reports for all the files that I'm using - including those that I'm not interested in. For example, it will give me code coverage reports for boost and mysql++ files.

Is there an easy way to force lcov to only generate coverage reports for specific files?

I have tried using the -k parameter like so:

 /usr/bin/lcov -q -c -i -b . -d .obj -k src/ -k include/ -o app_base.info  {run unit tests now}  /usr/bin/lcov -q -c -b . -d .obj -k src/ -k include/ -o app_test.info /usr/bin/lcov -q -a app_base.info -a app_test.info -o app_total.info /usr/bin/genhtml -q -o lcov_output_directory app_total.info 

(Meaning that I only want coverage files for the "include" and "src" directories.)

However, this doesn't seem to work. The report still shows me all the extraneous files. Any suggestions are very much appreciated. Thanks!

like image 472
Runcible Avatar asked May 08 '09 00:05

Runcible


People also ask

What is difference between GCOV and LCOV?

Lcov is a graphical front-end for gcov. It collects gcov data for multiple source files and creates HTML pages containing the source code annotated with coverage information. It also adds overview pages for easy navigation within the file structure. Lcov supports statement, function, and branch coverage measurement.

How do I enable branch coverage in LCOV?

You need to re-enable it by either: editing your ~/. lcovrc file (copied from /etc/lcovrc) to change lcov_branch_coverage setting to 1. adding --rc lcov_branch_coverage=1 to your lcov command lines.

How do I view LCOV?

You just need to install the Dart and lcov-info packages. Then you load your project folder and press Ctrl+Alt+c , coverage will be displayed with a summary of the whole projects coverage and also with specific line highlighting.


1 Answers

I used the --no-external flag together with the --directory flag to exclude unwanted files.

The definition of external from the man:

External source files are files which are not located in one of the directories specified by --directory or --base-directory.

So my command looked like this:

$ lcov  --directory src -c -o report.info --no-external Capturing coverage data from src Found gcov version: 4.2.1 Scanning src for .gcda files ... Found 4 data files in src Processing src/C####.gcda   ignoring data for external file /usr/include/c++/4.2.1/bits/allocator.h 
like image 157
peetasan Avatar answered Sep 29 '22 15:09

peetasan