Thread overview | ||||||
---|---|---|---|---|---|---|
|
December 09, 2005 -cov causes div by zero if file has no executable lines | ||||
---|---|---|---|---|
| ||||
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. |
December 09, 2005 Re: -cov causes div by zero if file has no executable lines | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don Clugston | 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
|
December 10, 2005 Re: -cov causes div by zero if file has no executable lines | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don Clugston | 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 );
|
December 10, 2005 Re: -cov causes div by zero if file has no executable lines | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hasan Aljudy | 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 |
Copyright © 1999-2021 by the D Language Foundation