single_cov 1.9.1 → 1.11.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: 033c6118fe2eb88114dab333f21c65b789ae0841b52ecfc5d7e96ce086f1c36d
4
- data.tar.gz: f6dbb0e79ccd6764efa21f943d1e10e31b84ba7a1bff80f4af7d92dcf3b7ea42
3
+ metadata.gz: 3ffed2c03e29890449010148c9492563266983dd70d0f32e7a600692fa6b6a57
4
+ data.tar.gz: a9395fb02ed4dd4f5490cf4faf8a7c8ef3bd8b084081958c3a86fabb3cbbedcf
5
5
  SHA512:
6
- metadata.gz: 939772cc7264d4ab62255b608b9ef6d493c75c6ed0e96f7e1c1d5f97e967a79bc93624c6449a5cffb5973e527a5ce9dae204e01b336e8ecb22dbea9779fd19d1
7
- data.tar.gz: 8d101d81129a40851a00b9f7157d1e1424c0845f3f0185c64fe890b08c3f453dc11dbcd756275768d286a6817e1483205cabf18683428ecbdb884cd4877118d7
6
+ metadata.gz: dddfdd5778b9e3c34b92db87d4288970a6a0bd27154d0c40572bf5fa581f92806214827974b55c2612b19f1298bd1d5827072006fb1d131bf5feb36ccca33513
7
+ data.tar.gz: 6b82b17a84a018334c140027bab24ef3ac9c08cb0d52973f87d580006d19b0c7cfd3a80b8331b7d487e38af34c8e51f817066170ddee360378587b0b8af03981
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SingleCov
3
- VERSION = "1.9.1"
3
+ VERSION = "1.11.0"
4
4
  end
data/lib/single_cov.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module SingleCov
3
3
  COVERAGES = []
4
- MAX_OUTPUT = 40
4
+ MAX_OUTPUT = Integer(ENV["SINGLE_COV_MAX_OUTPUT"] || "40")
5
5
  RAILS_APP_FOLDERS = ["models", "serializers", "helpers", "controllers", "mailers", "views", "jobs", "channels"]
6
6
  UNCOVERED_COMMENT_MARKER = /#.*uncovered/
7
7
  PREFIXES_TO_IGNORE = [] # things to not prefix with lib/ etc
@@ -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
@@ -50,7 +50,9 @@ module SingleCov
50
50
 
51
51
  return true if errors.empty?
52
52
 
53
- errors[MAX_OUTPUT..-1] = "... coverage output truncated" if errors.size >= MAX_OUTPUT
53
+ if errors.size >= MAX_OUTPUT
54
+ errors[MAX_OUTPUT..-1] = "... coverage output truncated (use SINGLE_COV_MAX_OUTPUT=999 to expand)"
55
+ end
54
56
  @error_logger.puts errors
55
57
 
56
58
  errors.all? { |l| warning?(l) }
@@ -146,18 +148,13 @@ module SingleCov
146
148
  def uncovered(coverage)
147
149
  return coverage unless coverage.is_a?(Hash) # just lines
148
150
 
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
-
151
+ uncovered_lines = indexes(coverage.fetch(:lines), 0).map! { |i| i + 1 }
156
152
  uncovered_branches = uncovered_branches(coverage[:branches] || {})
157
- uncovered_branches.reject! { |k| uncovered_lines.include?(k[0]) } # remove duplicates
153
+ uncovered_branches.reject! { |br| uncovered_lines.include?(br[0]) } # ignore branch when whole line is uncovered
158
154
 
155
+ # combine lines and branches while keeping them sorted
159
156
  all = uncovered_lines.concat uncovered_branches
160
- all.sort_by! { |line_start, char_start, _, _| [line_start, char_start || 0] } # branches are unsorted
157
+ all.sort_by! { |line_start, char_start, _, _, _| [line_start, char_start || 0] } # branches are unsorted
161
158
  all
162
159
  end
163
160
 
@@ -174,19 +171,21 @@ module SingleCov
174
171
  (!defined?(@main_process_pid) || @main_process_pid == Process.pid)
175
172
  end
176
173
 
174
+ # {[branch_id] => {[branch_part] => coverage}} --> uncovered location
177
175
  def uncovered_branches(coverage)
178
- # {[branch_id] => {[branch_part] => coverage}} --> {branch_part -> sum-of-coverage}
179
- sum = Hash.new(0)
176
+ sum = {}
180
177
  coverage.each_value do |branch|
181
- branch.each do |k, v|
182
- sum[k.slice(2, 4)] += v
178
+ branch.filter_map do |part, c|
179
+ location = [part[2], part[3] + 1, part[4], part[5] + 1] # locations can be duplicated
180
+ type = part[0]
181
+ info = (sum[location] ||= [0, nil])
182
+ info[0] += c
183
+ info[1] = type if type == :else # only else is important to track since it often is not in the code
183
184
  end
184
185
  end
185
186
 
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
187
+ # keep location and type of missing coverage
188
+ sum.filter_map { |k, v| k + [v[1]] if v[0] == 0 }
190
189
  end
191
190
 
192
191
  def default_tests
@@ -197,6 +196,10 @@ module SingleCov
197
196
  Dir["#{root}/#{pattern}"].map! { |f| f.sub("#{root}/", '') }
198
197
  end
199
198
 
199
+ def indexes(list, find)
200
+ list.each_with_index.filter_map { |v, i| i if v == find }
201
+ end
202
+
200
203
  # do not ask for coverage when SimpleCov already does or it conflicts
201
204
  def coverage_results
202
205
  if defined?(SimpleCov) && (result = SimpleCov.instance_variable_get(:@result))
@@ -327,13 +330,13 @@ module SingleCov
327
330
  [
328
331
  "#{file} new uncovered lines introduced #{details}",
329
332
  red("Lines missing coverage:"),
330
- *uncovered.map do |line_start, char_start, line_end, char_end|
333
+ *uncovered.map do |line_start, char_start, line_end, char_end, type|
331
334
  if char_start # branch coverage
332
335
  if line_start == line_end
333
336
  "#{file}:#{line_start}:#{char_start}-#{char_end}"
334
337
  else # possibly unreachable since branches always seem to be on the same line
335
338
  "#{file}:#{line_start}:#{char_start}-#{line_end}:#{char_end}"
336
- end
339
+ end + (type ? " # #{type}" : "")
337
340
  else
338
341
  "#{file}:#{line_start}"
339
342
  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.11.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-06-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: michael@grosser.it