jruby-rcov 0.8.2.2-java → 0.8.2.3-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,199 +0,0 @@
1
- require 'rcov/xx'
2
- require "erb"
3
-
4
- class Hash
5
- def to_binding(object = Object.new)
6
- object.instance_eval("def binding_for(#{keys.join(",")}) binding end")
7
- object.binding_for(*values)
8
- end
9
- end
10
-
11
- class Document
12
- def initialize(template)
13
- @template = ERB.new(template)
14
- end
15
-
16
- def interpolate(replacements = {})
17
- @template.result(replacements.to_binding)
18
- end
19
- end
20
-
21
- module XX
22
- module XMLish
23
- include Markup
24
-
25
- def xmlish_ *a, &b
26
- xx_which(XMLish){ xx_with_doc_in_effect(*a, &b)}
27
- end
28
- end
29
- end
30
-
31
- module Rcov
32
-
33
- class BaseFormatter # :nodoc:
34
- require 'pathname'
35
-
36
- ignore_files = [/\A#{Regexp.escape(Pathname.new(::Config::CONFIG["libdir"]).cleanpath.to_s)}/,
37
- /\btc_[^.]*.rb/, /_test\.rb\z/, /\btest\//, /\bvendor\//, /\A#{Regexp.escape(__FILE__)}\z/]
38
-
39
- DEFAULT_OPTS = {:ignore => ignore_files, :sort => :name, :sort_reverse => false,
40
- :output_threshold => 101, :dont_ignore => [], :callsite_analyzer => nil, :comments_run_by_default => false}
41
-
42
- def initialize(opts = {})
43
- options = DEFAULT_OPTS.clone.update(opts)
44
- @files = {}
45
- @ignore_files = options[:ignore]
46
- @dont_ignore_files = options[:dont_ignore]
47
- @sort_criterium = case options[:sort]
48
- when :loc then lambda{|fname, finfo| finfo.num_code_lines}
49
- when :coverage then lambda{|fname, finfo| finfo.code_coverage}
50
- else lambda{|fname, finfo| fname}
51
- end
52
- @sort_reverse = options[:sort_reverse]
53
- @output_threshold = options[:output_threshold]
54
- @callsite_analyzer = options[:callsite_analyzer]
55
- @comments_run_by_default = options[:comments_run_by_default]
56
- @callsite_index = nil
57
-
58
- @mangle_filename = Hash.new{|h,base|
59
- h[base] = Pathname.new(base).cleanpath.to_s.gsub(%r{^\w:[/\\]}, "").gsub(/\./, "_").gsub(/[\\\/]/, "-") + ".html"
60
- }
61
- end
62
-
63
- def add_file(filename, lines, coverage, counts)
64
- old_filename = filename
65
- filename = normalize_filename(filename)
66
- SCRIPT_LINES__[filename] = SCRIPT_LINES__[old_filename]
67
- if @ignore_files.any?{|x| x === filename} &&
68
- !@dont_ignore_files.any?{|x| x === filename}
69
- return nil
70
- end
71
- if @files[filename]
72
- @files[filename].merge(lines, coverage, counts)
73
- else
74
- @files[filename] = FileStatistics.new(filename, lines, counts,
75
- @comments_run_by_default)
76
- end
77
- end
78
-
79
- def normalize_filename(filename)
80
- File.expand_path(filename).gsub(/^#{Regexp.escape(Dir.getwd)}\//, '')
81
- end
82
-
83
- def mangle_filename(base)
84
- @mangle_filename[base]
85
- end
86
-
87
- def each_file_pair_sorted(&b)
88
- return sorted_file_pairs unless block_given?
89
- sorted_file_pairs.each(&b)
90
- end
91
-
92
- def sorted_file_pairs
93
- pairs = @files.sort_by do |fname, finfo|
94
- @sort_criterium.call(fname, finfo)
95
- end.select{|_, finfo| 100 * finfo.code_coverage < @output_threshold}
96
- @sort_reverse ? pairs.reverse : pairs
97
- end
98
-
99
- def total_coverage
100
- lines = 0
101
- total = 0.0
102
- @files.each do |k,f|
103
- total += f.num_lines * f.total_coverage
104
- lines += f.num_lines
105
- end
106
- return 0 if lines == 0
107
- total / lines
108
- end
109
-
110
- def code_coverage
111
- lines = 0
112
- total = 0.0
113
- @files.each do |k,f|
114
- total += f.num_code_lines * f.code_coverage
115
- lines += f.num_code_lines
116
- end
117
- return 0 if lines == 0
118
- total / lines
119
- end
120
-
121
- def num_code_lines
122
- lines = 0
123
- @files.each{|k, f| lines += f.num_code_lines }
124
- lines
125
- end
126
-
127
- def num_lines
128
- lines = 0
129
- @files.each{|k, f| lines += f.num_lines }
130
- lines
131
- end
132
-
133
- private
134
- def cross_references_for(filename, lineno)
135
- return nil unless @callsite_analyzer
136
- @callsite_index ||= build_callsite_index
137
- @callsite_index[normalize_filename(filename)][lineno]
138
- end
139
-
140
- def reverse_cross_references_for(filename, lineno)
141
- return nil unless @callsite_analyzer
142
- @callsite_reverse_index ||= build_reverse_callsite_index
143
- @callsite_reverse_index[normalize_filename(filename)][lineno]
144
- end
145
-
146
- def build_callsite_index
147
- index = Hash.new{|h,k| h[k] = {}}
148
- @callsite_analyzer.analyzed_classes.each do |classname|
149
- @callsite_analyzer.analyzed_methods(classname).each do |methname|
150
- defsite = @callsite_analyzer.defsite(classname, methname)
151
- index[normalize_filename(defsite.file)][defsite.line] =
152
- @callsite_analyzer.callsites(classname, methname)
153
- end
154
- end
155
- index
156
- end
157
-
158
- def build_reverse_callsite_index
159
- index = Hash.new{|h,k| h[k] = {}}
160
- @callsite_analyzer.analyzed_classes.each do |classname|
161
- @callsite_analyzer.analyzed_methods(classname).each do |methname|
162
- callsites = @callsite_analyzer.callsites(classname, methname)
163
- defsite = @callsite_analyzer.defsite(classname, methname)
164
- callsites.each_pair do |callsite, count|
165
- next unless callsite.file
166
- fname = normalize_filename(callsite.file)
167
- (index[fname][callsite.line] ||= []) << [classname, methname, defsite, count]
168
- end
169
- end
170
- end
171
- index
172
- end
173
-
174
- class XRefHelper < Struct.new(:file, :line, :klass, :mid, :count) # :nodoc:
175
- end
176
-
177
- def _get_defsites(ref_blocks, filename, lineno, linetext, label, &format_call_ref)
178
- if @do_cross_references and
179
- (rev_xref = reverse_cross_references_for(filename, lineno))
180
- refs = rev_xref.map do |classname, methodname, defsite, count|
181
- XRefHelper.new(defsite.file, defsite.line, classname, methodname, count)
182
- end.sort_by{|r| r.count}.reverse
183
- ref_blocks << [refs, label, format_call_ref]
184
- end
185
- end
186
-
187
- def _get_callsites(ref_blocks, filename, lineno, linetext, label, &format_called_ref)
188
- if @do_callsites and
189
- (refs = cross_references_for(filename, lineno))
190
- refs = refs.sort_by{|k,count| count}.map do |ref, count|
191
- XRefHelper.new(ref.file, ref.line, ref.calling_class, ref.calling_method, count)
192
- end.reverse
193
- ref_blocks << [refs, label, format_called_ref]
194
- end
195
- end
196
-
197
- end
198
-
199
- end
@@ -1,55 +0,0 @@
1
- module Rcov
2
-
3
- class FullTextReport < BaseFormatter # :nodoc:
4
- DEFAULT_OPTS = {:textmode => :coverage}
5
-
6
- def initialize(opts = {})
7
- options = DEFAULT_OPTS.clone.update(opts)
8
- @textmode = options[:textmode]
9
- @color = options[:color]
10
- super(options)
11
- end
12
-
13
- def execute
14
- each_file_pair_sorted do |filename, fileinfo|
15
- puts "=" * 80
16
- puts filename
17
- puts "=" * 80
18
- lines = SCRIPT_LINES__[filename]
19
-
20
- unless lines
21
- # try to get the source code from the global code coverage
22
- # analyzer
23
- re = /#{Regexp.escape(filename)}\z/
24
- if $rcov_code_coverage_analyzer and
25
- (data = $rcov_code_coverage_analyzer.data_matching(re))
26
- lines = data[0]
27
- end
28
- end
29
-
30
- (lines || []).each_with_index do |line, i|
31
-
32
- case @textmode
33
- when :counts
34
- puts "%-70s| %6d" % [line.chomp[0,70], fileinfo.counts[i]]
35
- when :gcc
36
- puts "%s:%d:%s" % [filename, i+1, line.chomp] unless fileinfo.coverage[i]
37
- when :coverage
38
- if @color
39
- prefix = fileinfo.coverage[i] ? "\e[32;40m" : "\e[31;40m"
40
- puts "#{prefix}%s\e[37;40m" % line.chomp
41
- else
42
- prefix = fileinfo.coverage[i] ? " " : "!! "
43
- puts "#{prefix}#{line}"
44
- end
45
- end
46
-
47
- end
48
-
49
- end
50
-
51
- end
52
-
53
- end
54
-
55
- end