14

I am wondering if there is the possibility to tell lcov to ignore some lines in a source files, ie. do not report them as unvisited. I am looking for a solution that can be put in the code itself, like:

int some_method(char some_var, char some_other_var)
{
    if(some_var == 'A')
    {
         if(some_other_var == 'B')
         {
               /* do some real stuff here */
         }
         else
         {
                LCOV_DO_NOT_REPORT_NEXT_LINE // **<-- this?? **
                NOT_IMPLEMENTED("A*")
         }
    }
    else
    {
         NOT_IMPLEMENTED("*")
    }

And the necessary background:

A big piece of code like the one above is being tested in a series of unit tests, but since this code is still under development there are a lot of NOT_IMPLEMENTED("A*") macros which just put a message on the screen with the line number/filename and exit the application. There are no tests for the not implemented branches, obviously they will be written when the feature is implemented.

However lcov reports these NOT_IMPLEMENTED lines and they look very ugly in the coverage report (ie: they make a high ratio of red lines).

Is what I ask for possible, or we just should live with this?

Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167
  • Any reason for having empty branches if you're not going to do anything with them yet? – PomfCaster Apr 24 '14 at 08:55
  • @PomfCaster all the empty branches have a macro `NOT_IMPLEMENTED` which indicate that in that branch there will be a functionality – Ferenc Deak Apr 24 '14 at 12:00
  • Possible duplicate of [How do I tell gcov to ignore un-hittable lines of C++ code?](https://stackoverflow.com/questions/3555083/how-do-i-tell-gcov-to-ignore-un-hittable-lines-of-c-code) – Machta Nov 02 '17 at 10:25

1 Answers1

23

You can use the following as comments in the source.

From http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php

  • LCOV_EXCL_LINE
    • Lines containing this marker will be excluded.
  • LCOV_EXCL_START
    • Marks the beginning of an excluded section. The current line is part of this section.
  • LCOV_EXCL_STOP
    • Marks the end of an excluded section. The current line not part of this section.
PomfCaster
  • 812
  • 1
  • 7
  • 12