digitalmars.D.bugs - [Issue 4153] New: Code coverage output improvement
- d-bugmail puremagic.com (96/96) May 03 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4153
- d-bugmail puremagic.com (30/30) May 05 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4153
- d-bugmail puremagic.com (27/27) Jun 08 2011 http://d.puremagic.com/issues/show_bug.cgi?id=4153
http://d.puremagic.com/issues/show_bug.cgi?id=4153
Summary: Code coverage output improvement
Product: D
Version: unspecified
Platform: x86
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: bearophile_hugs eml.cc
In the output text file of the code coverage the counts before the lines can
become misaligned if very long loops execute some lines many times.
For example this D2 code:
import std.stdio: writeln;
int sqr(int x) {
return x * x;
}
void main() {
int tot;
for(int i; i < 100000000; i++)
tot += 1;
writeln("hello world ", tot);
}
Produces this misaligned code coverage output (dmd 2.044) that's harder to
read:
|import std.stdio: writeln;
|int sqr(int x) {
0000000| return x * x;
|}
|void main() {
1| int tot;
200000002| for(int i; i < 100000000; i++)
100000000| tot += 1;
1| writeln("hello world ", tot);
|}
test.d is 80% covered
So I suggest three changes in this file:
1) To use ============ instead of "0000000" because among the other numbers my
eyes spot a sequence of equal signs better than a sequence of zeros.
2) Automatic column size management, so if the numbers grow the code coverage
output keeps its vertical alignment.
3) Formatting counts with underscores to separate thousands and improve
readability of large counts: 1_000_000.
I have used this little (a bit cryptic) Python script to do such processing
(but I'd like dmd to do something similar by itself):
filename = "some_file_name"
def thousands(n, separator="_"):
sign = "-" if n < 0 else ""
n = str(abs(n))[::-1]
parts = [n[i:i+3] for i in xrange(0, len(n), 3)]
return sign + separator.join(parts)[::-1]
lines = file(filename+ ".lst").readlines()[:-1]
parts = [line.split("|", 1) for line in lines]
for i, line in enumerate(parts):
line[0] = line[0].strip()
if line[0] and line[0] != "0000000":
line[0] = thousands(int(line[0]))
for p1, p2 in parts:
p2b = "|" + p2.rstrip()
if p1:
if p1 == "0000000":
print ("=" * n) + p2b
else:
print p1.rjust(n) + p2b
else:
print (" " * n) + p2b
The output of that Python script when remove_last=None :
|import std.stdio: writeln;
|int sqr(int x) {
===========| return x * x;
|}
|void main() {
1| int tot;
200_000_002| for(int i; i < 100000000; i++)
100_000_000| tot += 1;
1| writeln("hello world ", tot);
|}
Extra: I have often found that I further like to divide the counts by one
thousand or even one million, to better show only very large counts):
|import std.stdio: writeln;
|int sqr(int x) {
===| return x * x;
|}
|void main() {
| int tot;
200| for(int i; i < 100000000; i++)
100| tot += 1;
| writeln("hello world ", tot);
|}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 03 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4153
Improved version of the Python script:
filename = "test"
def thousands(n, separator="_"):
sign = "-" if n < 0 else ""
n = str(abs(n))[::-1]
parts = [n[i:i+3] for i in xrange(0, len(n), 3)]
return sign + separator.join(parts)[::-1]
lines = [l.rstrip() for l in file(filename+ ".lst")][:-1]
parts = [l.split("|", 1) for l in lines]
divisor = 10 ** (counts_divisor_thousands * 3)
for count, code in parts:
count = count.strip()
if count and count != "0000000":
count = thousands(int(count) / divisor)
ncols = max(len(count) for count, code in parts)
for count, code in parts:
if count:
if count == "0000000":
print ("=" * ncols) + "|" + code
else:
print count.rjust(ncols) + "|" + code
else:
print (" " * ncols) + "|" + code
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 05 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4153
kennytm gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kennytm gmail.com
Component|DMD |druntime
The coverage output is a druntime issue (and phobos for 1.x). For example, to
display '=======' instead of '0000000', you apply this patch:
diff --git a/src/rt/cover.d b/src/rt/cover.d
index 2ed5696..c72ee2f 100644
--- a/src/rt/cover.d
+++ b/src/rt/cover.d
-184,7 +184,7 shared static ~this()
if( c.valid[i] )
{
nno++;
- fprintf( flst, "0000000|%.*s\n", line.length, line.ptr
);
+ fprintf( flst, "=======|%.*s\n", line.length, line.ptr
);
}
else
{
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 08 2011









d-bugmail puremagic.com 