single_cov 1.9.0 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23e33169bc7e852c3671bd513b45a1060b1b472d51f2962e37bc2f436bf65a9e
4
- data.tar.gz: 0715bf92881ae7b66088db7b4661b4e9b30d86ed1437d2d8a373e33e3741b727
3
+ metadata.gz: 8d35277b97cbcabd001c11de169153d1eda320dfcfbd7ad516406ee811e623eb
4
+ data.tar.gz: c5d9fb7c34b7cb1a67a772a8ce870dbfc40cc6b1ae9ee859a951bbc3cbf93120
5
5
  SHA512:
6
- metadata.gz: 4554330293058a81f84444ba526183f73cdfe46a0432ca620004f2633519d160a83b94138e46f5089e8e72d1a71e3dc17a2b1afb0e1693b2c218bc22a27cd3d7
7
- data.tar.gz: 00adfea4b2aa109ea76b9b956a448cf5958d8005cdaecfe95f699f50e8594f59faa03ea9bd409b8f197253fbe5fe881a1a1870e19fe2afabde096c77959bc74e
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.0"
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
@@ -87,8 +87,10 @@ module SingleCov
87
87
  if missing_complete.any?
88
88
  errors << <<~MSG
89
89
  The following file(s) were previously marked as having 100% SingleCov test coverage (had no `coverage:` option) but are no longer marked as such.
90
- Please increase test coverage in these files to maintain 100% coverage and remove `coverage:` usage.
91
90
  #{missing_complete.join("\n")}
91
+ Please increase test coverage in these files to maintain 100% coverage and remove `coverage:` usage.
92
+
93
+ If this test fails during a file removal, make it pass by removing all references to the removed file's path from the code base.
92
94
  MSG
93
95
  end
94
96
 
@@ -144,18 +146,13 @@ module SingleCov
144
146
  def uncovered(coverage)
145
147
  return coverage unless coverage.is_a?(Hash) # just lines
146
148
 
147
- # [nil, 1, 0, 1, 0] -> [3, 5]
148
- uncovered_lines = coverage.fetch(:lines)
149
- .each_with_index
150
- .select { |c, _| c == 0 }
151
- .map { |_, i| i + 1 }
152
- .compact
153
-
149
+ uncovered_lines = indexes(coverage.fetch(:lines), 0).map! { |i| i + 1 }
154
150
  uncovered_branches = uncovered_branches(coverage[:branches] || {})
155
- 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
156
152
 
153
+ # combine lines and branches while keeping them sorted
157
154
  all = uncovered_lines.concat uncovered_branches
158
- 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
159
156
  all
160
157
  end
161
158
 
@@ -172,19 +169,21 @@ module SingleCov
172
169
  (!defined?(@main_process_pid) || @main_process_pid == Process.pid)
173
170
  end
174
171
 
172
+ # {[branch_id] => {[branch_part] => coverage}} --> uncovered location
175
173
  def uncovered_branches(coverage)
176
- # {[branch_id] => {[branch_part] => coverage}} --> {branch_part -> sum-of-coverage}
177
- sum = Hash.new(0)
174
+ sum = {}
178
175
  coverage.each_value do |branch|
179
- branch.each do |k, v|
180
- 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
181
182
  end
182
183
  end
183
184
 
184
- sum.select! { |_, v| v == 0 } # keep missing coverage
185
- found = sum.map { |k, _| [k[0], k[1] + 1, k[2], k[3] + 1] }
186
- found.uniq!
187
- found
185
+ # keep location and type of missing coverage
186
+ sum.filter_map { |k, v| k + [v[1]] if v[0] == 0 }
188
187
  end
189
188
 
190
189
  def default_tests
@@ -195,6 +194,10 @@ module SingleCov
195
194
  Dir["#{root}/#{pattern}"].map! { |f| f.sub("#{root}/", '') }
196
195
  end
197
196
 
197
+ def indexes(list, find)
198
+ list.each_with_index.filter_map { |v, i| i if v == find }
199
+ end
200
+
198
201
  # do not ask for coverage when SimpleCov already does or it conflicts
199
202
  def coverage_results
200
203
  if defined?(SimpleCov) && (result = SimpleCov.instance_variable_get(:@result))
@@ -325,13 +328,13 @@ module SingleCov
325
328
  [
326
329
  "#{file} new uncovered lines introduced #{details}",
327
330
  red("Lines missing coverage:"),
328
- *uncovered.map do |line_start, char_start, line_end, char_end|
331
+ *uncovered.map do |line_start, char_start, line_end, char_end, type|
329
332
  if char_start # branch coverage
330
333
  if line_start == line_end
331
334
  "#{file}:#{line_start}:#{char_start}-#{char_end}"
332
335
  else # possibly unreachable since branches always seem to be on the same line
333
336
  "#{file}:#{line_start}:#{char_start}-#{line_end}:#{char_end}"
334
- end
337
+ end + (type ? " # #{type}" : "")
335
338
  else
336
339
  "#{file}:#{line_start}"
337
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.0
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-02-17 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