www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - -cov causes div by zero if file has no executable lines

reply Don Clugston <dac nospam.com.au> writes:
For example, a file consisting only of typedefs.

When it prints "Module xxx is nn% covered" at runtime
it crashes when calculating the percentage, because it's 0/0.
I think it should report 100% coverage.
Dec 08 2005
parent reply Don Clugston <dac nospam.com.au> writes:
Don Clugston wrote:
 For example, a file consisting only of typedefs.
 
 When it prints "Module xxx is nn% covered" at runtime
 it crashes when calculating the percentage, because it's 0/0.
 I think it should report 100% coverage.

Bug is in cover.d line 174. ------ fwritefln(flst, "%s is %s%% covered", c.filename, (nyes * 100) / (nyes + nno)); --------- Easy fix is to add this line above it: if (nyes+nno==0) nyes=1; // avoid div by zero
Dec 09 2005
parent reply Hasan Aljudy <hasan.aljudy gmail.com> writes:
Don Clugston wrote:
 Don Clugston wrote:
 
 For example, a file consisting only of typedefs.

 When it prints "Module xxx is nn% covered" at runtime
 it crashes when calculating the percentage, because it's 0/0.
 I think it should report 100% coverage.

Bug is in cover.d line 174. ------ fwritefln(flst, "%s is %s%% covered", c.filename, (nyes * 100) / (nyes + nno)); --------- Easy fix is to add this line above it: if (nyes+nno==0) nyes=1; // avoid div by zero

I think that would be somewhat hackish, what if we needed the real value of nyes later? how about something more like: auto temp = nyes + nno; //pick a better name than temp auto coverage = (!temp)? 100 : (nyes * 100) / temp; fwritefln(flst, "%s is %s%% covered", c.filename, coverage );
Dec 10 2005
parent Derek Parnell <derek psych.ward> writes:
On Sat, 10 Dec 2005 01:43:27 -0700, Hasan Aljudy wrote:

 Don Clugston wrote:
 Don Clugston wrote:
 
 For example, a file consisting only of typedefs.

 When it prints "Module xxx is nn% covered" at runtime
 it crashes when calculating the percentage, because it's 0/0.
 I think it should report 100% coverage.

Bug is in cover.d line 174. ------ fwritefln(flst, "%s is %s%% covered", c.filename, (nyes * 100) / (nyes + nno)); --------- Easy fix is to add this line above it: if (nyes+nno==0) nyes=1; // avoid div by zero

I think that would be somewhat hackish, what if we needed the real value of nyes later? how about something more like: auto temp = nyes + nno; //pick a better name than temp auto coverage = (!temp)? 100 : (nyes * 100) / temp; fwritefln(flst, "%s is %s%% covered", c.filename, coverage );

I was thinking along similar lines... if (nyes+nno==0) { fwritefln(flst, "%s does not need coverage.", c.filename); } else { fwritefln(flst, "%s is %s%% covered", c.filename, (nyes * 100) / (nyes + nno)); } -- Derek Parnell Melbourne, Australia 10/12/2005 9:47:35 PM
Dec 10 2005