[Issue 4153] New: Code coverage output improvement
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon May 3 05:24:42 PDT 2010
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 at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2010-05-03 05:24:40 PDT ---
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]))
n = max(len(p1) for p1, p2 in parts) # len of the maximum number
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: -------
More information about the Digitalmars-d-bugs
mailing list