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.
@@ -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
- :output_threshold => 101, :dont_ignore => [], :callsite_analyzer => nil, :comments_run_by_default => false}
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
- require 'fileutils'
5
-
6
- DEFAULT_OPTS = {:color => false, :fsr => 30, :destdir => "coverage",
7
- :callsites => false, :cross_references => false,
8
- :charset => nil }
9
-
10
- def initialize(opts = {})
11
- options = DEFAULT_OPTS.clone.update(opts)
12
- super(options)
13
- @dest = options[:destdir]
14
- @color = options[:color]
15
- @fsr = options[:fsr]
16
- @do_callsites = options[:callsites]
17
- @do_cross_references = options[:cross_references]
18
- @span_class_index = 0
19
- @charset = options[:charset]
20
- end
21
-
22
- def execute
23
- return if @files.empty?
24
- FileUtils.mkdir_p @dest
25
- css_file = File.expand_path("#{File.dirname(__FILE__)}/../templates/screen.css")
26
- FileUtils.cp(css_file, File.join(@dest, "screen.css"))
27
-
28
- create_index(File.join(@dest, "index.html"))
29
-
30
- each_file_pair_sorted do |filename, fileinfo|
31
- create_file(File.join(@dest, mangle_filename(filename)), fileinfo)
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
- private
34
+ private
36
35
 
37
- class SummaryFileInfo # :nodoc:
38
-
39
- def initialize(obj)
40
- @o = obj
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
- def code_coverage_for_report
56
- code_coverage * 100
57
- end
41
+ def num_lines
42
+ @o.num_lines
43
+ end
58
44
 
59
- def total_coverage
60
- @o.total_coverage
61
- end
45
+ def num_code_lines
46
+ @o.num_code_lines
47
+ end
62
48
 
63
- def total_coverage_for_report
64
- total_coverage * 100
65
- end
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 create_index(destname)
74
- files = [SummaryFileInfo.new(self)] + each_file_pair_sorted.map{|k,v| v}
75
- doc = Rcov::Formatters::HtmlErbTemplate.new('index.html.erb', :title => 'C0 Coverage Information - RCov',
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
- File.open(destname, "w") { |f| f.puts doc.render }
61
+ def total_coverage_for_report
62
+ total_coverage * 100
83
63
  end
84
64
 
85
-
86
- def create_file(destfile, fileinfo)
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
- DEFAULT_OPTS = {:destdir => "profiling"}
101
- def initialize(opts = {})
102
- options = DEFAULT_OPTS.clone.update(opts)
103
- super(options)
104
- @max_cache = {}
105
- @median_cache = {}
106
- end
101
+ def default_title
102
+ "Bogo-profile information"
103
+ end
107
104
 
108
- def default_title
109
- "Bogo-profile information"
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
- def default_color
113
- if @color
114
- "rgb(179,205,255)"
115
- else
116
- "rgb(255, 255, 255)"
117
- end
118
- end
113
+ def output_color_table?
114
+ false
115
+ end
119
116
 
120
- def output_color_table?
121
- false
122
- end
123
-
124
- def span_class(sourceinfo, marked, count)
125
- full_scale_range = @fsr # dB
126
- nz_count = sourceinfo.counts.select{|x| x && x != 0}
127
- nz_count << 1 # avoid div by 0
128
- max = @max_cache[sourceinfo] ||= nz_count.max
129
- #avg = @median_cache[sourceinfo] ||= 1.0 *
130
- # nz_count.inject{|a,b| a+b} / nz_count.size
131
- median = @median_cache[sourceinfo] ||= 1.0 * nz_count.sort[nz_count.size/2]
132
- max ||= 2
133
- max = 2 if max == 1
134
- if marked == true
135
- count = 1 if !count || count == 0
136
- idx = 50 + 1.0 * (500/full_scale_range) * Math.log(count/median) / Math.log(10)
137
- idx = idx.to_i
138
- idx = 0 if idx < 0
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
- DEFAULT_OPTS = { :destdir => "coverage" }
150
- def initialize(opts = {})
151
- options = DEFAULT_OPTS.clone.update(opts)
152
- super(options)
153
- @dest = options[:destdir]
154
- @do_callsites = true
155
- @do_cross_references = true
156
-
157
- @mangle_filename = Hash.new{|h,base|
158
- h[base] = Pathname.new(base).cleanpath.to_s.gsub(%r{^\w:[/\\]}, "").gsub(/\./, "_").gsub(/[\\\/]/, "-") + ".rb"
159
- }
160
- end
161
-
162
- def execute
163
- return if @files.empty?
164
- FileUtils.mkdir_p @dest
165
- each_file_pair_sorted do |filename, fileinfo|
166
- create_file(File.join(@dest, mangle_filename(filename)), fileinfo)
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
- private
162
+ private
171
163
 
172
- def format_lines(file)
173
- result = ""
174
- format_line = "%#{file.num_lines.to_s.size}d"
175
- file.num_lines.times do |i|
176
- line = file.lines[i].chomp
177
- marked = file.coverage[i]
178
- count = file.counts[i]
179
- result << create_cross_refs(file.name, i+1, line, marked) + "\n"
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
- def create_cross_refs(filename, lineno, linetext, marked)
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
- if ref.file
189
- ref.file.sub!(%r!^./!, '')
190
- where = "at #{mangle_filename(ref.file)}:#{ref.line}"
191
- else
192
- where = "(C extension/core)"
193
- end
194
- "#{ref.klass}##{ref.mid} " + where + ""
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
- ref.file.sub!(%r!^./!, '')
198
- "#{mangle_filename(ref.file||'C code')}:#{ref.line} " +
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
- end
194
+ end
204
195
 
205
- def create_cross_reference_block(linetext, ref_blocks, marked)
206
- codelen = 75
207
- if ref_blocks.empty?
196
+ def create_cross_reference_block(linetext, ref_blocks, marked)
197
+ codelen = 75
198
+ if ref_blocks.empty?
208
199
  if marked
209
- return "%-#{codelen}s #o" % linetext
200
+ return "%-#{codelen}s #o" % linetext
210
201
  else
211
- return linetext
202
+ return linetext
212
203
  end
213
- end
214
- ret = ""
215
- @cross_ref_idx ||= 0
216
- @known_files ||= sorted_file_pairs.map{|fname, finfo| normalize_filename(fname)}
217
- ret << "%-#{codelen}s # " % linetext
218
- ref_blocks.each do |refs, toplabel, label_proc|
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
- ret << toplabel << " "
211
+ ret << toplabel << " "
221
212
  end
222
213
  refs.each do |dst|
223
- dstfile = normalize_filename(dst.file) if dst.file
224
- dstline = dst.line
225
- label = label_proc.call(dst)
226
- if dst.file && @known_files.include?(dstfile)
227
- ret << "[[" << label << "]], "
228
- else
229
- ret << label << ", "
230
- end
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
- def footer(fileinfo)
246
- s = "# Total lines : %d\n" % fileinfo.num_lines
247
- s << "# Lines of code : %d\n" % fileinfo.num_code_lines
248
- s << "# Total coverage : %3.1f%%\n" % [ fileinfo.total_coverage*100 ]
249
- s << "# Code coverage : %3.1f%%\n\n" % [ fileinfo.code_coverage*100 ]
250
- # prevents false positives on Emacs
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