-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcoverage.rb
49 lines (45 loc) · 1.56 KB
/
coverage.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
# -*- encoding : utf-8 -*-
SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
module COVERAGE__
INCLUDE_FILES=/gurgitate-mail.rb/
COVER = {}
def self.trace_func(event, file, line, id, binding, klass)
case event
when 'c-call', 'c-return', 'class'
return
end
COVER[file] ||= []
COVER[file][line] ||= 0
COVER[file][line] += 1
end
END {
set_trace_func(nil)
COVER.each do |file, lines|
next unless file =~ INCLUDE_FILES
if SCRIPT_LINES__.has_key?(file)
printf("--- %s\n", file)
lines = SCRIPT_LINES__[file]
covers = COVER[file]
0.upto(lines.size - 1) do |c|
line = lines[c].chomp
marked = false
if covers[c + 1]
marked = true
elsif /^\s*(?:begin\s*(?:#.*)?|ensure\s*(?:#.*)?|else\s*(?:#.*)?)$/ =~ line and covers[c + 1 + 1]
covers[c + 1] = covers[c + 1 + 1]
marked = true
elsif /^\s*(?:end|\})\s*$/ =~ line && covers[c + 1 - 1]
covers[c + 1] = covers[c + 1 - 1]
marked = true
end
if marked
printf("+ %s\n", line)
else
printf(" %s\n", line)
end
end
end
end
}
set_trace_func(COVERAGE__.method(:trace_func).to_proc)
end