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
- module Rcov
2
-
3
- class TextCoverageDiff < BaseFormatter # :nodoc:
4
- FORMAT_VERSION = [0, 1, 0]
5
- DEFAULT_OPTS = { :textmode => :coverage_diff, :coverage_diff_mode => :record,
6
- :coverage_diff_file => "coverage.info", :diff_cmd => "diff", :comments_run_by_default => true }
7
- HUNK_HEADER = /@@ -\d+,\d+ \+(\d+),(\d+) @@/
8
-
9
- def SERIALIZER
10
- # mfp> this was going to be YAML but I caught it failing at basic
11
- # round-tripping, turning "\n" into "" and corrupting the data, so
12
- # it must be Marshal for now
13
- Marshal
14
- end
15
-
16
- def initialize(opts = {})
17
- options = DEFAULT_OPTS.clone.update(opts)
18
- @textmode = options[:textmode]
19
- @color = options[:color]
20
- @mode = options[:coverage_diff_mode]
21
- @state_file = options[:coverage_diff_file]
22
- @diff_cmd = options[:diff_cmd]
23
- @gcc_output = options[:gcc_output]
24
- super(options)
25
- end
26
-
27
- def execute
28
- case @mode
29
- when :record
30
- record_state
31
- when :compare
32
- compare_state
33
- else
34
- raise "Unknown TextCoverageDiff mode: #{mode.inspect}."
35
- end
36
- end
37
-
38
- def record_state
39
- state = {}
40
- each_file_pair_sorted do |filename, fileinfo|
41
- state[filename] = {:lines => SCRIPT_LINES__[filename], :coverage => fileinfo.coverage.to_a,:counts => fileinfo.counts}
42
- end
43
- File.open(@state_file, "w") do |f|
44
- self.SERIALIZER.dump([FORMAT_VERSION, state], f)
45
- end
46
- rescue
47
- $stderr.puts <<-EOF
48
- Couldn't save coverage data to #{@state_file}.
49
- EOF
50
- end # '
51
-
52
- require 'tempfile'
53
- def compare_state
54
- return unless verify_diff_available
55
- begin
56
- format, prev_state = File.open(@state_file){|f| self.SERIALIZER.load(f) }
57
- rescue
58
- $stderr.puts <<-EOF
59
- Couldn't load coverage data from #{@state_file}.
60
- EOF
61
- return # '
62
- end
63
- if !(Array === format) or
64
- FORMAT_VERSION[0] != format[0] || FORMAT_VERSION[1] < format[1]
65
- $stderr.puts <<-EOF
66
- Couldn't load coverage data from #{@state_file}.
67
- The file is saved in the format #{format.inspect[0..20]}.
68
- This rcov executable understands #{FORMAT_VERSION.inspect}.
69
- EOF
70
- return # '
71
- end
72
- each_file_pair_sorted do |filename, fileinfo|
73
- old_data = Tempfile.new("#{mangle_filename(filename)}-old")
74
- new_data = Tempfile.new("#{mangle_filename(filename)}-new")
75
- if prev_state.has_key? filename
76
- old_code, old_cov = prev_state[filename].values_at(:lines, :coverage)
77
- old_code.each_with_index do |line, i|
78
- prefix = old_cov[i] ? " " : "!! "
79
- old_data.write "#{prefix}#{line}"
80
- end
81
- else
82
- old_data.write ""
83
- end
84
- old_data.close
85
- SCRIPT_LINES__[filename].each_with_index do |line, i|
86
- prefix = fileinfo.coverage[i] ? " " : "!! "
87
- new_data.write "#{prefix}#{line}"
88
- end
89
- new_data.close
90
-
91
- diff = `#{@diff_cmd} -u "#{old_data.path}" "#{new_data.path}"`
92
- new_uncovered_hunks = process_unified_diff(filename, diff)
93
- old_data.close!
94
- new_data.close!
95
- display_hunks(filename, new_uncovered_hunks)
96
- end
97
- end
98
-
99
- def display_hunks(filename, hunks)
100
- return if hunks.empty?
101
- puts
102
- puts "=" * 80
103
- puts "!!!!! Uncovered code introduced in #{filename}"
104
-
105
- hunks.each do |offset, lines|
106
- if @gcc_output
107
- lines.each_with_index do |line,i|
108
- lineno = offset + i
109
- flag = (/^!! / !~ line) ? "-" : ":"
110
- prefix = "#{filename}#{flag}#{lineno}#{flag}"
111
- puts "#{prefix}#{line[3..-1]}"
112
- end
113
- elsif @color
114
- puts "### #{filename}:#{offset}"
115
- lines.each do |line|
116
- prefix = (/^!! / !~ line) ? "\e[32;40m" : "\e[31;40m"
117
- puts "#{prefix}#{line[3..-1].chomp}\e[37;40m"
118
- end
119
- else
120
- puts "### #{filename}:#{offset}"
121
- puts lines
122
- end
123
- end
124
- end
125
-
126
- def verify_diff_available
127
- old_stderr = STDERR.dup
128
- old_stdout = STDOUT.dup
129
- # TODO: should use /dev/null or NUL(?), but I don't want to add the
130
- # win32 check right now
131
- new_stderr = Tempfile.new("rcov_check_diff")
132
- STDERR.reopen new_stderr.path
133
- STDOUT.reopen new_stderr.path
134
-
135
- retval = system "#{@diff_cmd} --version"
136
- unless retval
137
- old_stderr.puts <<EOF
138
-
139
- The '#{@diff_cmd}' executable seems not to be available.
140
- You can specify which diff executable should be used with --diff-cmd.
141
- If your system doesn't have one, you might want to use Diff::LCS's:
142
- gem install diff-lcs
143
- and use --diff-cmd=ldiff.
144
- EOF
145
- return false
146
- end
147
- true
148
- ensure
149
- STDOUT.reopen old_stdout
150
- STDERR.reopen old_stderr
151
- new_stderr.close!
152
- end
153
-
154
-
155
- def process_unified_diff(filename, diff)
156
- current_hunk = []
157
- current_hunk_start = 0
158
- keep_current_hunk = false
159
- state = :init
160
- interesting_hunks = []
161
- diff.each_with_index do |line, i|
162
- #puts "#{state} %5d #{line}" % i
163
- case state
164
- when :init
165
- if md = HUNK_HEADER.match(line)
166
- current_hunk = []
167
- current_hunk_start = md[1].to_i
168
- state = :body
169
- end
170
- when :body
171
- case line
172
- when HUNK_HEADER
173
- new_start = $1.to_i
174
- if keep_current_hunk
175
- interesting_hunks << [current_hunk_start, current_hunk]
176
- end
177
- current_hunk_start = new_start
178
- current_hunk = []
179
- keep_current_hunk = false
180
- when /^-/
181
- # ignore
182
- when /^\+!! /
183
- keep_current_hunk = true
184
- current_hunk << line[1..-1]
185
- else
186
- current_hunk << line[1..-1]
187
- end
188
- end
189
- end
190
- if keep_current_hunk
191
- interesting_hunks << [current_hunk_start, current_hunk]
192
- end
193
-
194
- interesting_hunks
195
- end
196
-
197
- end
198
-
199
- end
@@ -1,36 +0,0 @@
1
- module Rcov
2
-
3
- class TextReport < TextSummary # :nodoc:
4
-
5
- def execute
6
- print_lines
7
- print_header
8
- print_lines
9
-
10
- each_file_pair_sorted do |fname, finfo|
11
- name = fname.size < 52 ? fname : "..." + fname[-48..-1]
12
- print_info(name, finfo.num_lines, finfo.num_code_lines,
13
- finfo.code_coverage)
14
- end
15
-
16
- print_lines
17
- print_info("Total", num_lines, num_code_lines, code_coverage)
18
- print_lines
19
- puts summary
20
- end
21
-
22
- def print_info(name, lines, loc, coverage)
23
- puts "|%-51s | %5d | %5d | %5.1f%% |" % [name, lines, loc, 100 * coverage]
24
- end
25
-
26
- def print_lines
27
- puts "+----------------------------------------------------+-------+-------+--------+"
28
- end
29
-
30
- def print_header
31
- puts "| File | Lines | LOC | COV |"
32
- end
33
-
34
- end
35
-
36
- end
@@ -1,15 +0,0 @@
1
- module Rcov
2
-
3
- class TextSummary < BaseFormatter # :nodoc:
4
-
5
- def execute
6
- puts summary
7
- end
8
-
9
- def summary
10
- "%.1f%% %d file(s) %d Lines %d LOC" % [code_coverage * 100, @files.size, num_lines, num_code_lines]
11
- end
12
-
13
- end
14
-
15
- end
@@ -1,14 +0,0 @@
1
- require 'rcov/formatters/base_formatter'
2
- require 'rcov/formatters/text_summary'
3
- require 'rcov/formatters/text_report'
4
- require 'rcov/formatters/text_coverage_diff'
5
- require 'rcov/formatters/full_text_report'
6
- require 'rcov/formatters/html_coverage'
7
-
8
- module Rcov
9
-
10
- module Formatters
11
-
12
- end
13
-
14
- end