single_cov 1.9.1 → 1.10.0

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: 033c6118fe2eb88114dab333f21c65b789ae0841b52ecfc5d7e96ce086f1c36d
4
- data.tar.gz: f6dbb0e79ccd6764efa21f943d1e10e31b84ba7a1bff80f4af7d92dcf3b7ea42
3
+ metadata.gz: 8d35277b97cbcabd001c11de169153d1eda320dfcfbd7ad516406ee811e623eb
4
+ data.tar.gz: c5d9fb7c34b7cb1a67a772a8ce870dbfc40cc6b1ae9ee859a951bbc3cbf93120
5
5
  SHA512:
6
- metadata.gz: 939772cc7264d4ab62255b608b9ef6d493c75c6ed0e96f7e1c1d5f97e967a79bc93624c6449a5cffb5973e527a5ce9dae204e01b336e8ecb22dbea9779fd19d1
7
- data.tar.gz: 8d101d81129a40851a00b9f7157d1e1424c0845f3f0185c64fe890b08c3f453dc11dbcd756275768d286a6817e1483205cabf18683428ecbdb884cd4877118d7
6
+ metadata.gz: 64b8de808afd738fae4817c0701c12905882a4122ac50b53cc3e13694f78a831bcbaa433a7e45115682ef3ea2beefd7b59d2442872ad2ce11a82999007e3c6c7
7
+ data.tar.gz: 7637465f16cadc6a8beec088abd9fff899a3d9052617dd9c89d786ee24e565cb6fa8a8508a69407d63c013088aa11a3b765ac152198fc395460a490536525295
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SingleCov
3
- VERSION = "1.9.1"
3
+ VERSION = "1.10.0"
4
4
  end
data/lib/single_cov.rb CHANGED
@@ -40,7 +40,7 @@ module SingleCov
40
40
  # ignore lines that are marked as uncovered via comments
41
41
  # TODO: warn when using uncovered but the section is indeed covered
42
42
  content = File.readlines("#{root}/#{file}")
43
- uncovered.reject! do |line_start, _, _, _|
43
+ uncovered.reject! do |line_start, _, _, _, _|
44
44
  content[line_start - 1].match?(UNCOVERED_COMMENT_MARKER)
45
45
  end
46
46
  next if uncovered.size == expected_uncovered
@@ -146,18 +146,13 @@ module SingleCov
146
146
  def uncovered(coverage)
147
147
  return coverage unless coverage.is_a?(Hash) # just lines
148
148
 
149
- # [nil, 1, 0, 1, 0] -> [3, 5]
150
- uncovered_lines = coverage.fetch(:lines)
151
- .each_with_index
152
- .select { |c, _| c == 0 }
153
- .map { |_, i| i + 1 }
154
- .compact
155
-
149
+ uncovered_lines = indexes(coverage.fetch(:lines), 0).map! { |i| i + 1 }
156
150
  uncovered_branches = uncovered_branches(coverage[:branches] || {})
157
- uncovered_branches.reject! { |k| uncovered_lines.include?(k[0]) } # remove duplicates
151
+ uncovered_branches.reject! { |br| uncovered_lines.include?(br[0]) } # ignore branch when whole line is uncovered
158
152
 
153
+ # combine lines and branches while keeping them sorted
159
154
  all = uncovered_lines.concat uncovered_branches
160
- all.sort_by! { |line_start, char_start, _, _| [line_start, char_start || 0] } # branches are unsorted
155
+ all.sort_by! { |line_start, char_start, _, _, _| [line_start, char_start || 0] } # branches are unsorted
161
156
  all
162
157
  end
163
158
 
@@ -174,19 +169,21 @@ module SingleCov
174
169
  (!defined?(@main_process_pid) || @main_process_pid == Process.pid)
175
170
  end
176
171
 
172
+ # {[branch_id] => {[branch_part] => coverage}} --> uncovered location
177
173
  def uncovered_branches(coverage)
178
- # {[branch_id] => {[branch_part] => coverage}} --> {branch_part -> sum-of-coverage}
179
- sum = Hash.new(0)
174
+ sum = {}
180
175
  coverage.each_value do |branch|
181
- branch.each do |k, v|
182
- sum[k.slice(2, 4)] += v
176
+ branch.filter_map do |part, c|
177
+ location = [part[2], part[3] + 1, part[4], part[5] + 1] # locations can be duplicated
178
+ type = part[0]
179
+ info = (sum[location] ||= [0, nil])
180
+ info[0] += c
181
+ info[1] = type if type == :else # only else is important to track since it often is not in the code
183
182
  end
184
183
  end
185
184
 
186
- sum.select! { |_, v| v == 0 } # keep missing coverage
187
- found = sum.map { |k, _| [k[0], k[1] + 1, k[2], k[3] + 1] }
188
- found.uniq!
189
- found
185
+ # keep location and type of missing coverage
186
+ sum.filter_map { |k, v| k + [v[1]] if v[0] == 0 }
190
187
  end
191
188
 
192
189
  def default_tests
@@ -197,6 +194,10 @@ module SingleCov
197
194
  Dir["#{root}/#{pattern}"].map! { |f| f.sub("#{root}/", '') }
198
195
  end
199
196
 
197
+ def indexes(list, find)
198
+ list.each_with_index.filter_map { |v, i| i if v == find }
199
+ end
200
+
200
201
  # do not ask for coverage when SimpleCov already does or it conflicts
201
202
  def coverage_results
202
203
  if defined?(SimpleCov) && (result = SimpleCov.instance_variable_get(:@result))
@@ -327,13 +328,13 @@ module SingleCov
327
328
  [
328
329
  "#{file} new uncovered lines introduced #{details}",
329
330
  red("Lines missing coverage:"),
330
- *uncovered.map do |line_start, char_start, line_end, char_end|
331
+ *uncovered.map do |line_start, char_start, line_end, char_end, type|
331
332
  if char_start # branch coverage
332
333
  if line_start == line_end
333
334
  "#{file}:#{line_start}:#{char_start}-#{char_end}"
334
335
  else # possibly unreachable since branches always seem to be on the same line
335
336
  "#{file}:#{line_start}:#{char_start}-#{line_end}:#{char_end}"
336
- end
337
+ end + (type ? " # #{type}" : "")
337
338
  else
338
339
  "#{file}:#{line_start}"
339
340
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: single_cov
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-15 00:00:00.000000000 Z
11
+ date: 2023-05-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: michael@grosser.it