covered 0.20.1 → 0.20.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a1eaf5277a7fb0e714337382c57b984cac7f85ca1dcf554bad14aa854fa83c5
4
- data.tar.gz: 0ffef4a5eca5b677089d094aff7d6ad566a7fa5a6790ca64199a5411a0c08c16
3
+ metadata.gz: 78b0c761d5570d863e9a5d83188e37f136838b566e984ac949f8e9875c6fbc8a
4
+ data.tar.gz: 0434dcd73729213ebb510009c435557fa13d411a4b4de7564960b12482a8811e
5
5
  SHA512:
6
- metadata.gz: 505bac20e09538f38461bf9aecc016ada76557d1f60d1f0cdb4b4279d5505b556f23bdf10d2944f76e410f14cf32a8925e790c6e7ee5756f465169d78184b3f1
7
- data.tar.gz: ae1294f4a3833a2394b5a7239c9a044f9bb2208d2e0b96db774cd508413eb092f46b2ab5891418803add487e0e6ee3dd033948c9161201a028f71b42dfe8d910
6
+ metadata.gz: f2f0b4eae95375d6e3f08df7d5a064660c0453e7c64775841ea193bf57cbde51ed07145b9f2558dec6a67887b278adc00833e87f96f08621359c08599c24941e
7
+ data.tar.gz: 4daa48fa88d3a028343bc055743ad60eb702c964e2a98f972478c3b0823a4766db135d118bb0b19e48653a907bbf86d08a0077b1bfa41c1844cc34a7b13ca0b2
checksums.yaml.gz.sig CHANGED
Binary file
@@ -21,15 +21,26 @@ module Covered
21
21
  ::Coverage.result(stop: false, clear: true)
22
22
  end
23
23
 
24
+ EVAL_PATHS = {
25
+ "(eval)" => true,
26
+ "(irb)" => true,
27
+ "eval" => true
28
+ }
29
+
24
30
  def finish
25
31
  results = ::Coverage.result
26
32
 
27
33
  results.each do |path, result|
28
- lines = result[:lines]
34
+ next if EVAL_PATHS.include?(path)
35
+
29
36
  path = self.expand_path(path)
30
37
 
31
- lines.each_with_index do |count, lineno|
32
- @output.mark(path, lineno+1, count) if count
38
+ # Skip files which don't exist. This can happen if `eval` is used with an invalid/incorrect path.
39
+ if File.exist?(path)
40
+ @output.mark(path, 1, result[:lines])
41
+ else
42
+ # warn "Skipping coverage for #{path.inspect} because it doesn't exist!"
43
+ # Ignore.
33
44
  end
34
45
  end
35
46
 
data/lib/covered/files.rb CHANGED
@@ -34,10 +34,13 @@ module Covered
34
34
  end
35
35
 
36
36
  def mark(lineno, value = 1)
37
- if @counts[lineno]
38
- @counts[lineno] += value
39
- else
40
- @counts[lineno] = value
37
+ Array(value).each_with_index do |value, index|
38
+ offset = lineno + index
39
+ if @counts[offset]
40
+ @counts[offset] += value
41
+ else
42
+ @counts[offset] = value
43
+ end
41
44
  end
42
45
  end
43
46
 
@@ -29,6 +29,7 @@ module Covered
29
29
  terminal[:ignored_code] ||= terminal.style(nil, nil, :faint)
30
30
 
31
31
  terminal[:annotations] ||= terminal.style(:blue)
32
+ terminal[:error] ||= terminal.style(:red)
32
33
  end
33
34
  end
34
35
 
@@ -82,36 +83,49 @@ module Covered
82
83
  end
83
84
  end
84
85
 
86
+ def print_coverage(terminal, coverage)
87
+ line_offset = 1
88
+ counts = coverage.counts
89
+
90
+ coverage.read do |file|
91
+ print_line_header(terminal)
92
+
93
+ file.each_line do |line|
94
+ count = counts[line_offset]
95
+
96
+ print_annotations(terminal, coverage, line, line_offset)
97
+
98
+ print_line(terminal, line, line_offset, count)
99
+
100
+ line_offset += 1
101
+ end
102
+ end
103
+ end
104
+
105
+ def print_error(terminal, error)
106
+ terminal.puts "Error: #{error.message}", style: :error
107
+ terminal.puts error.backtrace
108
+ end
109
+
85
110
  # A coverage array gives, for each line, the number of line execution by the interpreter. A nil value means coverage is finishd for this line (lines like else and end).
86
- def call(wrapper, output = $stdout)
111
+ def call(wrapper, output = $stdout, **options)
87
112
  terminal = self.terminal(output)
88
113
 
89
114
  statistics = self.each(wrapper) do |coverage|
90
- line_offset = 1
91
-
92
115
  path = wrapper.relative_path(coverage.path)
93
116
  terminal.puts ""
94
117
  terminal.puts path, style: :path
95
118
 
96
- counts = coverage.counts
97
-
98
- coverage.read do |file|
99
- print_line_header(terminal)
100
-
101
- file.each_line do |line|
102
- count = counts[line_offset]
103
-
104
- print_annotations(terminal, coverage, line, line_offset)
105
-
106
- print_line(terminal, line, line_offset, count)
107
-
108
- line_offset += 1
109
- end
119
+ begin
120
+ print_coverage(terminal, coverage, **options)
121
+ rescue => error
122
+ print_error(terminal, error)
110
123
  end
111
124
 
112
125
  coverage.print(output)
113
126
  end
114
127
 
128
+ terminal.puts
115
129
  statistics.print(output)
116
130
  end
117
131
  end
@@ -150,49 +164,35 @@ module Covered
150
164
  end
151
165
 
152
166
  class PartialSummary < Summary
153
- def call(wrapper, output = $stdout, before: 4, after: 4)
154
- terminal = self.terminal(output)
167
+ def print_coverage(terminal, coverage, before: 4, after: 4)
168
+ return if coverage.zero?
155
169
 
156
- statistics = self.each(wrapper) do |coverage|
157
- line_offset = 1
158
-
159
- path = wrapper.relative_path(coverage.path)
160
- terminal.puts ""
161
- terminal.puts path, style: :path
162
-
163
- counts = coverage.counts
164
- last_line = nil
170
+ line_offset = 1
171
+ counts = coverage.counts
172
+ last_line = nil
173
+
174
+ coverage.read do |file|
175
+ print_line_header(terminal)
165
176
 
166
- unless coverage.zero?
167
- print_line_header(terminal)
177
+ file.each_line do |line|
178
+ range = Range.new([line_offset - before, 0].max, line_offset+after)
168
179
 
169
- coverage.read do |file|
170
- file.each_line do |line|
171
- range = Range.new([line_offset - before, 0].max, line_offset+after)
172
-
173
- if counts[range]&.include?(0)
174
- count = counts[line_offset]
175
-
176
- if last_line and last_line != line_offset-1
177
- terminal.puts ":".rjust(16)
178
- end
179
-
180
- print_annotations(terminal, coverage, line, line_offset)
181
- print_line(terminal, line, line_offset, count)
182
-
183
- last_line = line_offset
184
- end
185
-
186
- line_offset += 1
180
+ if counts[range]&.include?(0)
181
+ count = counts[line_offset]
182
+
183
+ if last_line and last_line != line_offset-1
184
+ terminal.puts ":".rjust(16)
187
185
  end
186
+
187
+ print_annotations(terminal, coverage, line, line_offset)
188
+ print_line(terminal, line, line_offset, count)
189
+
190
+ last_line = line_offset
188
191
  end
192
+
193
+ line_offset += 1
189
194
  end
190
-
191
- coverage.print(output)
192
195
  end
193
-
194
- terminal.puts
195
- statistics.print(output)
196
196
  end
197
197
  end
198
198
 
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2018-2022, by Samuel Williams.
5
5
 
6
6
  module Covered
7
- VERSION = "0.20.1"
7
+ VERSION = "0.20.2"
8
8
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: covered
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.1
4
+ version: 0.20.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -43,7 +43,7 @@ cert_chain:
43
43
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
44
44
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
45
45
  -----END CERTIFICATE-----
46
- date: 2023-02-10 00:00:00.000000000 Z
46
+ date: 2023-03-24 00:00:00.000000000 Z
47
47
  dependencies:
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: console
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  - !ruby/object:Gem::Version
177
177
  version: '0'
178
178
  requirements: []
179
- rubygems_version: 3.4.1
179
+ rubygems_version: 3.4.6
180
180
  signing_key:
181
181
  specification_version: 4
182
182
  summary: A modern approach to code coverage.
metadata.gz.sig CHANGED
Binary file