-cov LOC is inadequate for 1 liner branching; need a metric based on branching

Walter Bright newshound2 at digitalmars.com
Sun Feb 11 21:32:11 UTC 2018


On 2/5/2018 11:32 AM, Timothee Cour wrote:
> just filed https://issues.dlang.org/show_bug.cgi?id=18377:
> 
> `dmd -cov -run main.d` shows 100% coverage; this is misleading since a
> branch is not taken:
> 
> ```
> void main(){
>    int a;
>    if(false) a+=10;
> }
> ```

Consider how -cov works today:

   2|  x = 3; y = 4;
   1|  ++x;

The first line has a count of 2, because there are two statements and each 
contributes one increment to the line.

   1|  x = 3; // reference count
   2|  if (true && false) c;
   3|  if (true && true) c;
   1|  if (false && b) c;

The sequence points are each counted separately. So, by comparing with the 
'reference count', you can see which sequence points are executed. Also, if one 
finds that unattractive, the code can be organized like:

   1|  if (true &&
   1|      false)
   0|     c;

and the separate counts will be revealed instead of aggregated.

I agree that this is not ideal, however:

1. it works
2. it is simple and robust
3. the display to the user is simple
4. it's easy to aggregate multiple runs together with simple text processing code
5. one can 'fix' it with a stylistic change in the formatting of the source code

Any further improvement would be a large increase in complexity of the 
implementation, and I don't know of reasonable way to present this to the user 
in a textual format.

Is it worth it? I don't think so. Like builtin unittests, the big win with -cov 
is it is *trivial* to use, which encourages its adoption. It's a 99% solution, 
with 99% of the benefits, with 1% of the implementation effort. We should be 
expending effort elsewhere than putting an additional 99% effort to squeeze out 
that last 1% of benefit.


More information about the Digitalmars-d mailing list