digitalmars.D.bugs - -cov causes div by zero if file has no executable lines
- Don Clugston <dac nospam.com.au> Dec 08 2005
- Don Clugston <dac nospam.com.au> Dec 09 2005
- Hasan Aljudy <hasan.aljudy gmail.com> Dec 10 2005
- Derek Parnell <derek psych.ward> Dec 10 2005
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
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
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
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








Derek Parnell <derek psych.ward>