relevance-rcov 0.8.5.2 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rcov.rb +12 -990
- data/lib/rcov/call_site_analyzer.rb +225 -0
- data/lib/rcov/code_coverage_analyzer.rb +268 -0
- data/lib/rcov/coverage_info.rb +36 -0
- data/lib/rcov/differential_analyzer.rb +116 -0
- data/lib/rcov/file_statistics.rb +334 -0
- data/lib/rcov/formatters/base_formatter.rb +5 -6
- data/lib/rcov/formatters/full_text_report.rb +3 -10
- data/lib/rcov/formatters/html_coverage.rb +190 -201
- data/lib/rcov/formatters/html_erb_template.rb +1 -84
- data/lib/rcov/formatters/text_coverage_diff.rb +7 -13
- data/lib/rcov/formatters/text_report.rb +0 -4
- data/lib/rcov/lowlevel.rb +14 -13
- data/lib/rcov/rcovtask.rb +21 -22
- data/lib/rcov/templates/screen.css +37 -34
- data/lib/rcov/version.rb +3 -3
- metadata +6 -1
@@ -1,12 +1,12 @@
|
|
1
1
|
module Rcov
|
2
|
-
|
3
2
|
class BaseFormatter # :nodoc:
|
4
3
|
require 'pathname'
|
5
4
|
require 'mkmf'
|
6
5
|
ignore_files = [/\A#{Regexp.escape(Pathname.new(::Config::CONFIG['libdir']).cleanpath.to_s)}/, /\btc_[^.]*.rb/, /_test\.rb\z/, /\btest\//, /\bvendor\//, /\A#{Regexp.escape(__FILE__)}\z/]
|
7
6
|
|
8
|
-
DEFAULT_OPTS = {:ignore => ignore_files, :sort => :name, :sort_reverse => false,
|
9
|
-
|
7
|
+
DEFAULT_OPTS = { :ignore => ignore_files, :sort => :name, :sort_reverse => false,
|
8
|
+
:output_threshold => 101, :dont_ignore => [], :callsite_analyzer => nil, \
|
9
|
+
:comments_run_by_default => false }
|
10
10
|
|
11
11
|
def initialize(opts = {})
|
12
12
|
options = DEFAULT_OPTS.clone.update(opts)
|
@@ -17,7 +17,7 @@ module Rcov
|
|
17
17
|
@sort_criterium = case options[:sort]
|
18
18
|
when :loc then lambda{|fname, finfo| finfo.num_code_lines}
|
19
19
|
when :coverage then lambda{|fname, finfo| finfo.code_coverage}
|
20
|
-
else lambda{|fname, finfo| fname}
|
20
|
+
else lambda { |fname, finfo| fname }
|
21
21
|
end
|
22
22
|
@sort_reverse = options[:sort_reverse]
|
23
23
|
@output_threshold = options[:output_threshold]
|
@@ -101,6 +101,7 @@ module Rcov
|
|
101
101
|
end
|
102
102
|
|
103
103
|
private
|
104
|
+
|
104
105
|
def cross_references_for(filename, lineno)
|
105
106
|
return nil unless @callsite_analyzer
|
106
107
|
@callsite_index ||= build_callsite_index
|
@@ -163,7 +164,5 @@ module Rcov
|
|
163
164
|
ref_blocks << [refs, label, format_called_ref]
|
164
165
|
end
|
165
166
|
end
|
166
|
-
|
167
167
|
end
|
168
|
-
|
169
168
|
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Rcov
|
2
|
-
|
3
2
|
class FullTextReport < BaseFormatter # :nodoc:
|
4
3
|
DEFAULT_OPTS = {:textmode => :coverage}
|
5
|
-
|
4
|
+
|
6
5
|
def initialize(opts = {})
|
7
6
|
options = DEFAULT_OPTS.clone.update(opts)
|
8
7
|
@textmode = options[:textmode]
|
@@ -16,7 +15,7 @@ module Rcov
|
|
16
15
|
puts filename
|
17
16
|
puts "=" * 80
|
18
17
|
lines = SCRIPT_LINES__[filename]
|
19
|
-
|
18
|
+
|
20
19
|
unless lines
|
21
20
|
# try to get the source code from the global code coverage
|
22
21
|
# analyzer
|
@@ -26,9 +25,8 @@ module Rcov
|
|
26
25
|
lines = data[0]
|
27
26
|
end
|
28
27
|
end
|
29
|
-
|
28
|
+
|
30
29
|
(lines || []).each_with_index do |line, i|
|
31
|
-
|
32
30
|
case @textmode
|
33
31
|
when :counts
|
34
32
|
puts "%-70s| %6d" % [line.chomp[0,70], fileinfo.counts[i]]
|
@@ -43,13 +41,8 @@ module Rcov
|
|
43
41
|
puts "#{prefix}#{line}"
|
44
42
|
end
|
45
43
|
end
|
46
|
-
|
47
44
|
end
|
48
|
-
|
49
45
|
end
|
50
|
-
|
51
46
|
end
|
52
|
-
|
53
47
|
end
|
54
|
-
|
55
48
|
end
|
@@ -1,255 +1,244 @@
|
|
1
1
|
module Rcov
|
2
|
-
|
3
2
|
class HTMLCoverage < BaseFormatter # :nodoc:
|
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
|
-
end
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
DEFAULT_OPTS = {:color => false, :fsr => 30, :destdir => "coverage",
|
6
|
+
:callsites => false, :cross_references => false,
|
7
|
+
:charset => nil }
|
8
|
+
|
9
|
+
def initialize(opts = {})
|
10
|
+
options = DEFAULT_OPTS.clone.update(opts)
|
11
|
+
super(options)
|
12
|
+
@dest = options[:destdir]
|
13
|
+
@color = options[:color]
|
14
|
+
@fsr = options[:fsr]
|
15
|
+
@do_callsites = options[:callsites]
|
16
|
+
@do_cross_references = options[:cross_references]
|
17
|
+
@span_class_index = 0
|
18
|
+
@charset = options[:charset]
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute
|
22
|
+
return if @files.empty?
|
23
|
+
FileUtils.mkdir_p @dest
|
24
|
+
css_file = File.expand_path("#{File.dirname(__FILE__)}/../templates/screen.css")
|
25
|
+
FileUtils.cp(css_file, File.join(@dest, "screen.css"))
|
26
|
+
|
27
|
+
create_index(File.join(@dest, "index.html"))
|
28
|
+
|
29
|
+
each_file_pair_sorted do |filename, fileinfo|
|
30
|
+
create_file(File.join(@dest, mangle_filename(filename)), fileinfo)
|
33
31
|
end
|
32
|
+
end
|
34
33
|
|
35
|
-
|
34
|
+
private
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
def num_lines
|
44
|
-
@o.num_lines
|
45
|
-
end
|
46
|
-
|
47
|
-
def num_code_lines
|
48
|
-
@o.num_code_lines
|
49
|
-
end
|
50
|
-
|
51
|
-
def code_coverage
|
52
|
-
@o.code_coverage
|
53
|
-
end
|
36
|
+
class SummaryFileInfo # :nodoc:
|
37
|
+
def initialize(obj)
|
38
|
+
@o = obj
|
39
|
+
end
|
54
40
|
|
55
|
-
|
56
|
-
|
57
|
-
|
41
|
+
def num_lines
|
42
|
+
@o.num_lines
|
43
|
+
end
|
58
44
|
|
59
|
-
|
60
|
-
|
61
|
-
|
45
|
+
def num_code_lines
|
46
|
+
@o.num_code_lines
|
47
|
+
end
|
62
48
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
def name
|
68
|
-
"TOTAL"
|
69
|
-
end
|
49
|
+
def code_coverage
|
50
|
+
@o.code_coverage
|
51
|
+
end
|
70
52
|
|
53
|
+
def code_coverage_for_report
|
54
|
+
code_coverage * 100
|
71
55
|
end
|
72
56
|
|
73
|
-
def
|
74
|
-
|
75
|
-
|
76
|
-
:generated_on => Time.now,
|
77
|
-
:rcov => Rcov,
|
78
|
-
:formatter => self,
|
79
|
-
:output_threshold => @output_threshold,
|
80
|
-
:files => files)
|
57
|
+
def total_coverage
|
58
|
+
@o.total_coverage
|
59
|
+
end
|
81
60
|
|
82
|
-
|
61
|
+
def total_coverage_for_report
|
62
|
+
total_coverage * 100
|
83
63
|
end
|
84
64
|
|
85
|
-
|
86
|
-
|
87
|
-
doc = Rcov::Formatters::HtmlErbTemplate.new('detail.html.erb', :title => fileinfo.name,
|
88
|
-
:generated_on => Time.now,
|
89
|
-
:rcov => Rcov,
|
90
|
-
:formatter => self,
|
91
|
-
:output_threshold => @output_threshold,
|
92
|
-
:fileinfo => fileinfo)
|
93
|
-
File.open(destfile, "w") { |f| f.puts doc.render }
|
65
|
+
def name
|
66
|
+
"TOTAL"
|
94
67
|
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_index(destname)
|
71
|
+
files = [SummaryFileInfo.new(self)] + each_file_pair_sorted.map{|k,v| v}
|
72
|
+
doc = Rcov::Formatters::HtmlErbTemplate.new('index.html.erb', :title => 'C0 Coverage Information - RCov',
|
73
|
+
:generated_on => Time.now,
|
74
|
+
:rcov => Rcov,
|
75
|
+
:formatter => self,
|
76
|
+
:output_threshold => @output_threshold,
|
77
|
+
:files => files)
|
78
|
+
File.open(destname, "w") { |f| f.puts doc.render }
|
79
|
+
end
|
95
80
|
|
81
|
+
def create_file(destfile, fileinfo)
|
82
|
+
doc = Rcov::Formatters::HtmlErbTemplate.new('detail.html.erb', :title => fileinfo.name,
|
83
|
+
:generated_on => Time.now,
|
84
|
+
:rcov => Rcov,
|
85
|
+
:formatter => self,
|
86
|
+
:output_threshold => @output_threshold,
|
87
|
+
:fileinfo => fileinfo)
|
88
|
+
File.open(destfile, "w") { |f| f.puts doc.render }
|
89
|
+
end
|
96
90
|
end
|
97
91
|
|
98
92
|
class HTMLProfiling < HTMLCoverage # :nodoc:
|
93
|
+
DEFAULT_OPTS = {:destdir => "profiling"}
|
94
|
+
def initialize(opts = {})
|
95
|
+
options = DEFAULT_OPTS.clone.update(opts)
|
96
|
+
super(options)
|
97
|
+
@max_cache = {}
|
98
|
+
@median_cache = {}
|
99
|
+
end
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
super(options)
|
104
|
-
@max_cache = {}
|
105
|
-
@median_cache = {}
|
106
|
-
end
|
101
|
+
def default_title
|
102
|
+
"Bogo-profile information"
|
103
|
+
end
|
107
104
|
|
108
|
-
|
109
|
-
|
105
|
+
def default_color
|
106
|
+
if @color
|
107
|
+
"rgb(179,205,255)"
|
108
|
+
else
|
109
|
+
"rgb(255, 255, 255)"
|
110
110
|
end
|
111
|
+
end
|
111
112
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
else
|
116
|
-
"rgb(255, 255, 255)"
|
117
|
-
end
|
118
|
-
end
|
113
|
+
def output_color_table?
|
114
|
+
false
|
115
|
+
end
|
119
116
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
idx = 100 if idx > 100
|
140
|
-
"run#{idx}"
|
141
|
-
else
|
142
|
-
nil
|
143
|
-
end
|
117
|
+
def span_class(sourceinfo, marked, count)
|
118
|
+
full_scale_range = @fsr # dB
|
119
|
+
nz_count = sourceinfo.counts.select{|x| x && x != 0}
|
120
|
+
nz_count << 1 # avoid div by 0
|
121
|
+
max = @max_cache[sourceinfo] ||= nz_count.max
|
122
|
+
#avg = @median_cache[sourceinfo] ||= 1.0 *
|
123
|
+
# nz_count.inject{|a,b| a+b} / nz_count.size
|
124
|
+
median = @median_cache[sourceinfo] ||= 1.0 * nz_count.sort[nz_count.size/2]
|
125
|
+
max ||= 2
|
126
|
+
max = 2 if max == 1
|
127
|
+
if marked == true
|
128
|
+
count = 1 if !count || count == 0
|
129
|
+
idx = 50 + 1.0 * (500/full_scale_range) * Math.log(count/median) / Math.log(10)
|
130
|
+
idx = idx.to_i
|
131
|
+
idx = 0 if idx < 0
|
132
|
+
idx = 100 if idx > 100
|
133
|
+
"run#{idx}"
|
134
|
+
else
|
135
|
+
nil
|
144
136
|
end
|
145
|
-
|
137
|
+
end
|
146
138
|
end
|
147
139
|
|
148
140
|
class RubyAnnotation < BaseFormatter # :nodoc:
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
end
|
141
|
+
DEFAULT_OPTS = { :destdir => "coverage" }
|
142
|
+
def initialize(opts = {})
|
143
|
+
options = DEFAULT_OPTS.clone.update(opts)
|
144
|
+
super(options)
|
145
|
+
@dest = options[:destdir]
|
146
|
+
@do_callsites = true
|
147
|
+
@do_cross_references = true
|
148
|
+
|
149
|
+
@mangle_filename = Hash.new{ |h,base|
|
150
|
+
h[base] = Pathname.new(base).cleanpath.to_s.gsub(%r{^\w:[/\\]}, "").gsub(/\./, "_").gsub(/[\\\/]/, "-") + ".rb"
|
151
|
+
}
|
152
|
+
end
|
153
|
+
|
154
|
+
def execute
|
155
|
+
return if @files.empty?
|
156
|
+
FileUtils.mkdir_p @dest
|
157
|
+
each_file_pair_sorted do |filename, fileinfo|
|
158
|
+
create_file(File.join(@dest, mangle_filename(filename)), fileinfo)
|
168
159
|
end
|
160
|
+
end
|
169
161
|
|
170
|
-
|
162
|
+
private
|
171
163
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
end
|
181
|
-
result
|
164
|
+
def format_lines(file)
|
165
|
+
result = ""
|
166
|
+
format_line = "%#{file.num_lines.to_s.size}d"
|
167
|
+
file.num_lines.times do |i|
|
168
|
+
line = file.lines[i].chomp
|
169
|
+
marked = file.coverage[i]
|
170
|
+
count = file.counts[i]
|
171
|
+
result << create_cross_refs(file.name, i+1, line, marked) + "\n"
|
182
172
|
end
|
173
|
+
result
|
174
|
+
end
|
183
175
|
|
184
|
-
|
176
|
+
def create_cross_refs(filename, lineno, linetext, marked)
|
185
177
|
return linetext unless @callsite_analyzer && @do_callsites
|
186
178
|
ref_blocks = []
|
187
179
|
_get_defsites(ref_blocks, filename, lineno, linetext, ">>") do |ref|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
180
|
+
if ref.file
|
181
|
+
ref.file.sub!(%r!^./!, '')
|
182
|
+
where = "at #{mangle_filename(ref.file)}:#{ref.line}"
|
183
|
+
else
|
184
|
+
where = "(C extension/core)"
|
185
|
+
end
|
186
|
+
"#{ref.klass}##{ref.mid} " + where + ""
|
195
187
|
end
|
196
188
|
_get_callsites(ref_blocks, filename, lineno, linetext, "<<") do |ref| # "
|
197
|
-
|
198
|
-
|
199
|
-
"in #{ref.klass}##{ref.mid}"
|
189
|
+
ref.file.sub!(%r!^./!, '')
|
190
|
+
"#{mangle_filename(ref.file||'C code')}:#{ref.line} " + "in #{ref.klass}##{ref.mid}"
|
200
191
|
end
|
201
192
|
|
202
193
|
create_cross_reference_block(linetext, ref_blocks, marked)
|
203
|
-
|
194
|
+
end
|
204
195
|
|
205
|
-
|
206
|
-
|
207
|
-
|
196
|
+
def create_cross_reference_block(linetext, ref_blocks, marked)
|
197
|
+
codelen = 75
|
198
|
+
if ref_blocks.empty?
|
208
199
|
if marked
|
209
|
-
|
200
|
+
return "%-#{codelen}s #o" % linetext
|
210
201
|
else
|
211
|
-
|
202
|
+
return linetext
|
212
203
|
end
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
204
|
+
end
|
205
|
+
ret = ""
|
206
|
+
@cross_ref_idx ||= 0
|
207
|
+
@known_files ||= sorted_file_pairs.map{|fname, finfo| normalize_filename(fname)}
|
208
|
+
ret << "%-#{codelen}s # " % linetext
|
209
|
+
ref_blocks.each do |refs, toplabel, label_proc|
|
219
210
|
unless !toplabel || toplabel.empty?
|
220
|
-
|
211
|
+
ret << toplabel << " "
|
221
212
|
end
|
222
213
|
refs.each do |dst|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
214
|
+
dstfile = normalize_filename(dst.file) if dst.file
|
215
|
+
dstline = dst.line
|
216
|
+
label = label_proc.call(dst)
|
217
|
+
if dst.file && @known_files.include?(dstfile)
|
218
|
+
ret << "[[" << label << "]], "
|
219
|
+
else
|
220
|
+
ret << label << ", "
|
221
|
+
end
|
231
222
|
end
|
232
|
-
end
|
233
|
-
|
234
|
-
ret
|
235
|
-
end
|
236
|
-
|
237
|
-
def create_file(destfile, fileinfo)
|
238
|
-
#body = format_lines(fileinfo)
|
239
|
-
#File.open(destfile, "w") do |f|
|
240
|
-
#f.puts body
|
241
|
-
#f.puts footer(fileinfo)
|
242
|
-
#end
|
243
223
|
end
|
224
|
+
ret
|
225
|
+
end
|
244
226
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
s << "# Local " "Variables:\n" "# mode: " "rcov-xref\n" "# End:\n"
|
252
|
-
end
|
227
|
+
def create_file(destfile, fileinfo)
|
228
|
+
#body = format_lines(fileinfo)
|
229
|
+
#File.open(destfile, "w") do |f|
|
230
|
+
#f.puts body
|
231
|
+
#f.puts footer(fileinfo)
|
232
|
+
#end
|
253
233
|
end
|
254
234
|
|
235
|
+
def footer(fileinfo)
|
236
|
+
s = "# Total lines : %d\n" % fileinfo.num_lines
|
237
|
+
s << "# Lines of code : %d\n" % fileinfo.num_code_lines
|
238
|
+
s << "# Total coverage : %3.1f%%\n" % [ fileinfo.total_coverage*100 ]
|
239
|
+
s << "# Code coverage : %3.1f%%\n\n" % [ fileinfo.code_coverage*100 ]
|
240
|
+
# prevents false positives on Emacs
|
241
|
+
s << "# Local " "Variables:\n" "# mode: " "rcov-xref\n" "# End:\n"
|
242
|
+
end
|
243
|
+
end
|
255
244
|
end
|