www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - code coverage bug: do-while - cov.d

reply Ivan Cibiri <Ivan_member pathlink.com> writes:
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


begin 0644 cov.d

M8V]U;G1E<CL-" E]('=H:6QE*&-O=6YT97( /B`P*0T*"2\O('!R979I;W5S
M(&QI;F4 25, 3D]4(&-O;G-I9&5R960 8GD 8V]D92!C;W9E<F%G92`-" DO
M+RAB96-A=7-E(&]F(&UI<W-I;F< <V5M:6-O;&]N/RD-" D-" EC;W5N=&5R
M(#T
M(#X


`
end
Dec 28 2005
parent reply Don Clugston <dac nospam.com.au> writes:
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).
Dec 28 2005
parent Oskar Linde <oskar.lindeREM OVEgmail.com> writes:
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
Dec 28 2005