simplecov 0.18.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +233 -168
- data/CONTRIBUTING.md +3 -3
- data/ISSUE_TEMPLATE.md +1 -1
- data/README.md +77 -20
- data/doc/alternate-formatters.md +7 -2
- data/doc/commercial-services.md +5 -0
- data/lib/minitest/simplecov_plugin.rb +15 -0
- data/lib/simplecov.rb +117 -118
- data/lib/simplecov/combine.rb +2 -2
- data/lib/simplecov/combine/branches_combiner.rb +2 -2
- data/lib/simplecov/configuration.rb +52 -3
- data/lib/simplecov/coverage_statistics.rb +5 -5
- data/lib/simplecov/defaults.rb +8 -12
- data/lib/simplecov/exit_codes.rb +5 -0
- data/lib/simplecov/exit_codes/exit_code_handling.rb +29 -0
- data/lib/simplecov/exit_codes/maximum_coverage_drop_check.rb +50 -0
- data/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb +38 -0
- data/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb +53 -0
- data/lib/simplecov/filter.rb +7 -5
- data/lib/simplecov/formatter.rb +2 -2
- data/lib/simplecov/formatter/multi_formatter.rb +5 -7
- data/lib/simplecov/lines_classifier.rb +1 -1
- data/lib/simplecov/no_defaults.rb +1 -1
- data/lib/simplecov/process.rb +19 -0
- data/lib/simplecov/result.rb +14 -12
- data/lib/simplecov/result_merger.rb +2 -7
- data/lib/simplecov/source_file.rb +53 -4
- data/lib/simplecov/useless_results_remover.rb +5 -3
- data/lib/simplecov/version.rb +1 -1
- metadata +18 -10
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Process
|
4
|
+
class << self
|
5
|
+
def fork_with_simplecov(&block)
|
6
|
+
if defined?(SimpleCov) && SimpleCov.running
|
7
|
+
fork_without_simplecov do
|
8
|
+
SimpleCov.at_fork.call(Process.pid)
|
9
|
+
block.call if block_given?
|
10
|
+
end
|
11
|
+
else
|
12
|
+
fork_without_simplecov(&block)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
alias fork_without_simplecov fork
|
17
|
+
alias fork fork_with_simplecov
|
18
|
+
end
|
19
|
+
end
|
data/lib/simplecov/result.rb
CHANGED
@@ -25,9 +25,11 @@ module SimpleCov
|
|
25
25
|
|
26
26
|
# Initialize a new SimpleCov::Result from given Coverage.result (a Hash of filenames each containing an array of
|
27
27
|
# coverage data)
|
28
|
-
def initialize(original_result)
|
28
|
+
def initialize(original_result, command_name: nil, created_at: nil)
|
29
29
|
result = adapt_result(original_result)
|
30
30
|
@original_result = result.freeze
|
31
|
+
@command_name = command_name
|
32
|
+
@created_at = created_at
|
31
33
|
@files = SimpleCov::FileList.new(result.map do |filename, coverage|
|
32
34
|
SimpleCov::SourceFile.new(filename, JSON.parse(JSON.dump(coverage))) if File.file?(filename)
|
33
35
|
end.compact.sort_by(&:filename))
|
@@ -70,15 +72,15 @@ module SimpleCov
|
|
70
72
|
}
|
71
73
|
end
|
72
74
|
|
75
|
+
def time_since_creation
|
76
|
+
Time.now - created_at
|
77
|
+
end
|
78
|
+
|
73
79
|
# Loads a SimpleCov::Result#to_hash dump
|
74
80
|
def self.from_hash(hash)
|
75
|
-
command_name, data
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
result.command_name = command_name
|
80
|
-
result.created_at = Time.at(data["timestamp"])
|
81
|
-
result
|
81
|
+
hash.map do |command_name, data|
|
82
|
+
new(data.fetch("coverage"), command_name: command_name, created_at: Time.at(data["timestamp"]))
|
83
|
+
end
|
82
84
|
end
|
83
85
|
|
84
86
|
private
|
@@ -86,7 +88,7 @@ module SimpleCov
|
|
86
88
|
# We changed the format of the raw result data in simplecov, as people are likely
|
87
89
|
# to have "old" resultsets lying around (but not too old so that they're still
|
88
90
|
# considered we can adapt them).
|
89
|
-
# See https://github.com/
|
91
|
+
# See https://github.com/simplecov-ruby/simplecov/pull/824#issuecomment-576049747
|
90
92
|
def adapt_result(result)
|
91
93
|
if pre_simplecov_0_18_result?(result)
|
92
94
|
adapt_pre_simplecov_0_18_result(result)
|
@@ -103,9 +105,9 @@ module SimpleCov
|
|
103
105
|
end
|
104
106
|
|
105
107
|
def adapt_pre_simplecov_0_18_result(result)
|
106
|
-
result.
|
107
|
-
|
108
|
-
end
|
108
|
+
result.transform_values do |line_coverage_data|
|
109
|
+
{"lines" => line_coverage_data}
|
110
|
+
end
|
109
111
|
end
|
110
112
|
|
111
113
|
def coverage
|
@@ -53,13 +53,8 @@ module SimpleCov
|
|
53
53
|
# All results that are above the SimpleCov.merge_timeout will be
|
54
54
|
# dropped. Returns an array of SimpleCov::Result items.
|
55
55
|
def results
|
56
|
-
results =
|
57
|
-
|
58
|
-
result = SimpleCov::Result.from_hash(command_name => data)
|
59
|
-
# Only add result if the timeout is above the configured threshold
|
60
|
-
results << result if (Time.now - result.created_at) < SimpleCov.merge_timeout
|
61
|
-
end
|
62
|
-
results
|
56
|
+
results = Result.from_hash(resultset)
|
57
|
+
results.select { |result| result.time_since_creation < SimpleCov.merge_timeout }
|
63
58
|
end
|
64
59
|
|
65
60
|
def merge_and_store(*results)
|
@@ -25,7 +25,7 @@ module SimpleCov
|
|
25
25
|
def src
|
26
26
|
# We intentionally read source code lazily to
|
27
27
|
# suppress reading unused source code.
|
28
|
-
@src ||=
|
28
|
+
@src ||= load_source
|
29
29
|
end
|
30
30
|
alias source src
|
31
31
|
|
@@ -162,15 +162,64 @@ module SimpleCov
|
|
162
162
|
end
|
163
163
|
|
164
164
|
def build_no_cov_chunks
|
165
|
-
no_cov_lines = src.map.with_index(1).select { |
|
165
|
+
no_cov_lines = src.map.with_index(1).select { |line_src, _index| LinesClassifier.no_cov_line?(line_src) }
|
166
166
|
|
167
|
-
|
167
|
+
# if we have an uneven number of nocovs we assume they go to the
|
168
|
+
# end of the file, the source doesn't really matter
|
169
|
+
# Can't deal with this within the each_slice due to differing
|
170
|
+
# behavior in JRuby: jruby/jruby#6048
|
171
|
+
no_cov_lines << ["", src.size] if no_cov_lines.size.odd?
|
168
172
|
|
169
|
-
no_cov_lines.each_slice(2).map do |(
|
173
|
+
no_cov_lines.each_slice(2).map do |(_line_src_start, index_start), (_line_src_end, index_end)|
|
170
174
|
index_start..index_end
|
171
175
|
end
|
172
176
|
end
|
173
177
|
|
178
|
+
def load_source
|
179
|
+
lines = []
|
180
|
+
# The default encoding is UTF-8
|
181
|
+
File.open(filename, "rb:UTF-8") do |file|
|
182
|
+
current_line = file.gets
|
183
|
+
|
184
|
+
if shebang?(current_line)
|
185
|
+
lines << current_line
|
186
|
+
current_line = file.gets
|
187
|
+
end
|
188
|
+
|
189
|
+
read_lines(file, lines, current_line)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
SHEBANG_REGEX = /\A#!/.freeze
|
194
|
+
def shebang?(line)
|
195
|
+
SHEBANG_REGEX.match?(line)
|
196
|
+
end
|
197
|
+
|
198
|
+
def read_lines(file, lines, current_line)
|
199
|
+
return lines unless current_line
|
200
|
+
|
201
|
+
set_encoding_based_on_magic_comment(file, current_line)
|
202
|
+
lines.concat([current_line], ensure_remove_undefs(file.readlines))
|
203
|
+
end
|
204
|
+
|
205
|
+
RUBY_FILE_ENCODING_MAGIC_COMMENT_REGEX = /\A#\s*(?:-\*-)?\s*(?:en)?coding:\s*(\S+)\s*(?:-\*-)?\s*\z/.freeze
|
206
|
+
def set_encoding_based_on_magic_comment(file, line)
|
207
|
+
# Check for encoding magic comment
|
208
|
+
# Encoding magic comment must be placed at first line except for shebang
|
209
|
+
if (match = RUBY_FILE_ENCODING_MAGIC_COMMENT_REGEX.match(line))
|
210
|
+
file.set_encoding(match[1], "UTF-8")
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def ensure_remove_undefs(file_lines)
|
215
|
+
# invalid/undef replace are technically not really necessary but nice to
|
216
|
+
# have and work around a JRuby incompatibility. Also moved here from
|
217
|
+
# simplecov-html to have encoding shenaningans in one place. See #866
|
218
|
+
# also setting these option on `file.set_encoding` doesn't seem to work
|
219
|
+
# properly so it has to be done here.
|
220
|
+
file_lines.each { |line| line.encode!("UTF-8", invalid: :replace, undef: :replace) }
|
221
|
+
end
|
222
|
+
|
174
223
|
def build_lines
|
175
224
|
coverage_exceeding_source_warn if coverage_data["lines"].size > src.size
|
176
225
|
lines = src.map.with_index(1) do |src, i|
|
@@ -5,12 +5,14 @@ module SimpleCov
|
|
5
5
|
# Select the files that related to working scope directory of SimpleCov
|
6
6
|
#
|
7
7
|
module UselessResultsRemover
|
8
|
-
ROOT_REGX = /\A#{Regexp.escape(SimpleCov.root + File::SEPARATOR)}/io.freeze
|
9
|
-
|
10
8
|
def self.call(coverage_result)
|
11
9
|
coverage_result.select do |path, _coverage|
|
12
|
-
path =~
|
10
|
+
path =~ root_regx
|
13
11
|
end
|
14
12
|
end
|
13
|
+
|
14
|
+
def self.root_regx
|
15
|
+
@root_regx ||= /\A#{Regexp.escape(SimpleCov.root + File::SEPARATOR)}/i.freeze
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
data/lib/simplecov/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplecov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christoph Olszowka
|
8
|
+
- Tobias Pfeiffer
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2020-
|
12
|
+
date: 2020-08-16 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: docile
|
@@ -30,18 +31,19 @@ dependencies:
|
|
30
31
|
requirements:
|
31
32
|
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.11
|
34
|
+
version: '0.11'
|
34
35
|
type: :runtime
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
39
|
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.11
|
41
|
+
version: '0.11'
|
41
42
|
description: Code coverage for Ruby with a powerful configuration library and automatic
|
42
43
|
merging of coverage across test suites
|
43
44
|
email:
|
44
45
|
- christoph at olszowka de
|
46
|
+
- pragtob@gmail.com
|
45
47
|
executables: []
|
46
48
|
extensions: []
|
47
49
|
extra_rdoc_files: []
|
@@ -55,6 +57,7 @@ files:
|
|
55
57
|
- doc/alternate-formatters.md
|
56
58
|
- doc/commercial-services.md
|
57
59
|
- doc/editor-integration.md
|
60
|
+
- lib/minitest/simplecov_plugin.rb
|
58
61
|
- lib/simplecov.rb
|
59
62
|
- lib/simplecov/combine.rb
|
60
63
|
- lib/simplecov/combine/branches_combiner.rb
|
@@ -66,6 +69,10 @@ files:
|
|
66
69
|
- lib/simplecov/coverage_statistics.rb
|
67
70
|
- lib/simplecov/defaults.rb
|
68
71
|
- lib/simplecov/exit_codes.rb
|
72
|
+
- lib/simplecov/exit_codes/exit_code_handling.rb
|
73
|
+
- lib/simplecov/exit_codes/maximum_coverage_drop_check.rb
|
74
|
+
- lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb
|
75
|
+
- lib/simplecov/exit_codes/minimum_overall_coverage_check.rb
|
69
76
|
- lib/simplecov/file_list.rb
|
70
77
|
- lib/simplecov/filter.rb
|
71
78
|
- lib/simplecov/formatter.rb
|
@@ -75,6 +82,7 @@ files:
|
|
75
82
|
- lib/simplecov/lines_classifier.rb
|
76
83
|
- lib/simplecov/load_global_config.rb
|
77
84
|
- lib/simplecov/no_defaults.rb
|
85
|
+
- lib/simplecov/process.rb
|
78
86
|
- lib/simplecov/profiles.rb
|
79
87
|
- lib/simplecov/profiles/bundler_filter.rb
|
80
88
|
- lib/simplecov/profiles/hidden_filter.rb
|
@@ -90,15 +98,15 @@ files:
|
|
90
98
|
- lib/simplecov/source_file/line.rb
|
91
99
|
- lib/simplecov/useless_results_remover.rb
|
92
100
|
- lib/simplecov/version.rb
|
93
|
-
homepage: https://github.com/
|
101
|
+
homepage: https://github.com/simplecov-ruby/simplecov
|
94
102
|
licenses:
|
95
103
|
- MIT
|
96
104
|
metadata:
|
97
|
-
bug_tracker_uri: https://github.com/
|
98
|
-
changelog_uri: https://github.com/
|
99
|
-
documentation_uri: https://www.rubydoc.info/gems/simplecov/0.
|
105
|
+
bug_tracker_uri: https://github.com/simplecov-ruby/simplecov/issues
|
106
|
+
changelog_uri: https://github.com/simplecov-ruby/simplecov/blob/main/CHANGELOG.md
|
107
|
+
documentation_uri: https://www.rubydoc.info/gems/simplecov/0.19.0
|
100
108
|
mailing_list_uri: https://groups.google.com/forum/#!forum/simplecov
|
101
|
-
source_code_uri: https://github.com/
|
109
|
+
source_code_uri: https://github.com/simplecov-ruby/simplecov/tree/v0.19.0
|
102
110
|
post_install_message:
|
103
111
|
rdoc_options: []
|
104
112
|
require_paths:
|
@@ -107,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
115
|
requirements:
|
108
116
|
- - ">="
|
109
117
|
- !ruby/object:Gem::Version
|
110
|
-
version: 2.
|
118
|
+
version: 2.5.0
|
111
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
120
|
requirements:
|
113
121
|
- - ">="
|