single_cov 1.9.1 → 1.11.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 +4 -4
- data/lib/single_cov/version.rb +1 -1
- data/lib/single_cov.rb +25 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ffed2c03e29890449010148c9492563266983dd70d0f32e7a600692fa6b6a57
|
4
|
+
data.tar.gz: a9395fb02ed4dd4f5490cf4faf8a7c8ef3bd8b084081958c3a86fabb3cbbedcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dddfdd5778b9e3c34b92db87d4288970a6a0bd27154d0c40572bf5fa581f92806214827974b55c2612b19f1298bd1d5827072006fb1d131bf5feb36ccca33513
|
7
|
+
data.tar.gz: 6b82b17a84a018334c140027bab24ef3ac9c08cb0d52973f87d580006d19b0c7cfd3a80b8331b7d487e38af34c8e51f817066170ddee360378587b0b8af03981
|
data/lib/single_cov/version.rb
CHANGED
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
|
-
|
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
|
-
|
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! { |
|
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
|
-
|
179
|
-
sum = Hash.new(0)
|
176
|
+
sum = {}
|
180
177
|
coverage.each_value do |branch|
|
181
|
-
branch.
|
182
|
-
|
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
|
-
|
187
|
-
|
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.
|
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
|
11
|
+
date: 2023-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: michael@grosser.it
|