Unit Testing in Action
Walter Bright
newshound2 at digitalmars.com
Sat Oct 21 22:50:51 UTC 2017
On 10/21/2017 6:14 AM, Martin Nowak wrote:
> On Friday, 20 October 2017 at 21:26:35 UTC, qznc wrote:
>> * coverage is not sufficiently solved. The author suggests to reformat code so
>> short-circuit evaluations become multiple lines?
>
> If you can use gdc or ldc, branch coverage should be supported out of the box.
> Other tools support regions to be marked as unreachable, e.g
> GCOVR_EXCL_START/GCOVR_EXCL_STOP.
> I'd also err on the side that unittests themselves should not be part of
> coverage, but an option in druntime and more metadata from dmd might solve this.
>
> Filed under https://issues.dlang.org/show_bug.cgi?id=17923.
Not sure what is meant by branch coverage.
Consider:
x = 2;
if (x == 1 || x == 2)
Coverage would give:
1| x = 2;
2| if (x == 1 || x == 2)
I.e. the second line gets an execution count of 2. By contrast,
1| x = 1;
1| if (x == 1 || x == 2)
What's happening here is each of the operands of || are considered to be
separate statements as far as coverage analysis goes. It becomes clearer if it
is reformatted as:
1| x = 2;
1| if (x == 1 ||
1| x == 2)
or:
3| x = 2; if (x == 1 || x == 2)
It's usually possible to trivially suss out the coverage of the clauses by
looking at the preceding and succeeding line counts. Putting the clauses on
separate lines also works. If there's a better way to display the various
counts, please add it to the bugzilla report.
More information about the Digitalmars-d-announce
mailing list