Thread overview
code coverage bug: do-while - cov.d
Dec 28, 2005
Ivan Cibiri
Dec 28, 2005
Don Clugston
Dec 28, 2005
Oskar Linde
December 28, 2005
Hello,

I thing that there is a small bug in code coverage in dmd v0.141.

If you compile code in attached file cov.d (dmd cov.d -cov) and run the program,
you get this output:

|int main() {
1|        int counter = 20;
|        do {
20|                --counter;
0000000|        } while(counter > 0)
|        // previous line IS NOT considered by code coverage
|        //(because of missing semicolon?)
|
1|        counter = 20;
|        do {
20|                --counter;
1|        } while(counter > 0);
|        // if you add semicolon,
|        // previous line IS considered by code coverage
|
1|        return 0;
|}
cov.d is 85% covered

Problem is with do-while statement (while part), as you can see from the listing
file, because it is not corectly considered as executed (zero times or once ?).

Ivan


December 28, 2005
Ivan Cibiri wrote:
> 1|        int counter = 20;
> |        do {
> 20|                --counter;
> 0000000|        } while(counter > 0)
> |        // previous line IS NOT considered by code coverage |        //(because of missing semicolon?)
> |        1|        counter = 20;

> Problem is with do-while statement (while part), as you can see from the listing
> file, because it is not corectly considered as executed (zero times or once ?).

I don't think this is a code-coverage bug. Isn't it a bug to leave out the semicolon? I don't think it should compile at all.

And it looks to me as though the syntax in statement.html is wrong.

DoStatement:
	do Statement while () Expression

Surely this should be:
        do Statement while ( Expression)

and ditto for "for", etc. (Maybe these typos were introduced when changing to Ddoc).

December 28, 2005
Don Clugston wrote:
> Ivan Cibiri wrote:
> 
>> 1|        int counter = 20;
>> |        do {
>> 20|                --counter;
>> 0000000|        } while(counter > 0)
>> |        // previous line IS NOT considered by code coverage |        //(because of missing semicolon?)
>> |        1|        counter = 20;
> 
> 
>> Problem is with do-while statement (while part), as you can see from the listing
>> file, because it is not corectly considered as executed (zero times or once ?).
> 
> 
> I don't think this is a code-coverage bug. Isn't it a bug to leave out the semicolon? I don't think it should compile at all.

No, it is correct. according to the spec, do statements do not end with a semicolon. The semicolon will be considered an empty statement, and therefore counted once.

The bug is the condition in the do-while loop that never gets counted, the lines containing while should be counted 20 and 21 times respectively. Consider:

       |void main() {
      1|  int n = 20;
       |  do {
     20|   ;
0000000|  } while (--n)
       |}
test.d is 66% covered

This is not correct. test.d should be fully covered.

> And it looks to me as though the syntax in statement.html is wrong.
> 
> DoStatement:
>     do Statement while () Expression
> 
> Surely this should be:
>         do Statement while ( Expression)

Yes, this seems wrong. Maybe its just a newly invented notation. :)

/Oskar