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 +4 -4
- data/lib/single_cov/version.rb +1 -1
- data/lib/single_cov.rb +24 -21
- 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: 8d35277b97cbcabd001c11de169153d1eda320dfcfbd7ad516406ee811e623eb
|
4
|
+
data.tar.gz: c5d9fb7c34b7cb1a67a772a8ce870dbfc40cc6b1ae9ee859a951bbc3cbf93120
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64b8de808afd738fae4817c0701c12905882a4122ac50b53cc3e13694f78a831bcbaa433a7e45115682ef3ea2beefd7b59d2442872ad2ce11a82999007e3c6c7
|
7
|
+
data.tar.gz: 7637465f16cadc6a8beec088abd9fff899a3d9052617dd9c89d786ee24e565cb6fa8a8508a69407d63c013088aa11a3b765ac152198fc395460a490536525295
|
data/lib/single_cov/version.rb
CHANGED
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
|
-
|
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! { |
|
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
|
-
|
177
|
-
sum = Hash.new(0)
|
174
|
+
sum = {}
|
178
175
|
coverage.each_value do |branch|
|
179
|
-
branch.
|
180
|
-
|
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
|
-
|
185
|
-
|
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.
|
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-
|
11
|
+
date: 2023-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: michael@grosser.it
|