-
Notifications
You must be signed in to change notification settings - Fork 2
/
test-all-cov.rb
65 lines (62 loc) · 1.3 KB
/
test-all-cov.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require "coverage.so"
def expand_tab(str, tabstop=8)
col = 0
str.gsub(/(\t+)|[^\t]+/) {
if $1
' ' * (($1.length * tabstop) - (col + 1) % tabstop)
else
$&
end
}
end
at_exit {
r = Coverage.result
fs = r.keys.sort.reject {|f|
%r{lib/tb[/.]} !~ f
}
if !fs.empty?
if $stdout.tty?
out = IO.popen(['less', '-S', '-j20', '+/ 0:'], 'w')
else
out = $stdout
end
pat = nil
fs[0].chars.to_a.reverse_each {|ch|
if !pat
pat = "#{Regexp.escape(ch)}?"
else
pat = "(?:#{Regexp.escape(ch)}#{pat})?"
end
}
pat = Regexp.compile(pat)
prefix_len = fs[0].length
fs.each {|f|
l = pat.match(f).end(0)
prefix_len = l if l < prefix_len
}
prefix = fs[0][0, prefix_len]
prefix.sub!(%r{[^/]+\z}, '')
fs.each {|f|
next if %r{lib/tb[/.]} !~ f
f0 = f[prefix.length..-1]
ns = r[f]
max = ns.compact.max
w = max.to_s.length
fmt1 = "%s %#{w}d:%s"
fmt2 = "%s #{" " * w}:%s"
File.foreach(f).with_index {|line, i|
line = expand_tab(line)
if ns[i]
out.puts fmt1 % [f0, ns[i], line]
else
out.puts fmt2 % [f0, line]
end
}
}
if out != $stdout
out.close
end
end
}
Coverage.start
load 'test-all.rb'