simplecov 0.22.0 → 1.0.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/LICENSE +1 -1
- data/README.md +1058 -508
- data/doc/alternate-formatters.md +0 -5
- data/doc/commercial-services.md +5 -5
- data/exe/simplecov +11 -0
- data/lib/minitest/simplecov_plugin.rb +13 -5
- data/lib/simplecov/autostart.rb +11 -0
- data/lib/simplecov/cli/clean.rb +47 -0
- data/lib/simplecov/cli/coverage.rb +91 -0
- data/lib/simplecov/cli/diff.rb +151 -0
- data/lib/simplecov/cli/dotfile.rb +100 -0
- data/lib/simplecov/cli/merge.rb +116 -0
- data/lib/simplecov/cli/open.rb +50 -0
- data/lib/simplecov/cli/report.rb +84 -0
- data/lib/simplecov/cli/run.rb +36 -0
- data/lib/simplecov/cli/serve.rb +139 -0
- data/lib/simplecov/cli/uncovered.rb +107 -0
- data/lib/simplecov/cli.rb +150 -0
- data/lib/simplecov/color.rb +74 -0
- data/lib/simplecov/combine/branches_combiner.rb +27 -5
- data/lib/simplecov/combine/files_combiner.rb +7 -1
- data/lib/simplecov/combine/lines_combiner.rb +19 -17
- data/lib/simplecov/combine/methods_combiner.rb +26 -0
- data/lib/simplecov/combine/results_combiner.rb +5 -4
- data/lib/simplecov/command_guesser.rb +46 -32
- data/lib/simplecov/configuration/coverage.rb +171 -0
- data/lib/simplecov/configuration/coverage_criteria.rb +156 -0
- data/lib/simplecov/configuration/filters.rb +197 -0
- data/lib/simplecov/configuration/formatting.rb +119 -0
- data/lib/simplecov/configuration/ignored_entries.rb +63 -0
- data/lib/simplecov/configuration/merging.rb +164 -0
- data/lib/simplecov/configuration/thresholds.rb +174 -0
- data/lib/simplecov/configuration.rb +91 -407
- data/lib/simplecov/coverage_statistics.rb +12 -9
- data/lib/simplecov/coverage_violations.rb +148 -0
- data/lib/simplecov/defaults.rb +27 -20
- data/lib/simplecov/deprecation.rb +45 -0
- data/lib/simplecov/directive.rb +162 -0
- data/lib/simplecov/exit_codes/exit_code_handling.rb +8 -2
- data/lib/simplecov/exit_codes/maximum_coverage_drop_check.rb +19 -57
- data/lib/simplecov/exit_codes/maximum_overall_coverage_check.rb +45 -0
- data/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb +17 -27
- data/lib/simplecov/exit_codes/minimum_coverage_by_group_check.rb +41 -0
- data/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb +38 -21
- data/lib/simplecov/exit_codes.rb +3 -0
- data/lib/simplecov/exit_handling.rb +158 -0
- data/lib/simplecov/file_list.rb +61 -17
- data/lib/simplecov/filter.rb +69 -24
- data/lib/simplecov/formatter/base.rb +101 -0
- data/lib/simplecov/formatter/html_formatter/public/application.css +1 -0
- data/lib/simplecov/formatter/html_formatter/public/application.js +18 -0
- data/lib/simplecov/formatter/html_formatter/public/favicon_green.png +0 -0
- data/lib/simplecov/formatter/html_formatter/public/favicon_red.png +0 -0
- data/lib/simplecov/formatter/html_formatter/public/favicon_yellow.png +0 -0
- data/lib/simplecov/formatter/html_formatter/public/index.html +56 -0
- data/lib/simplecov/formatter/html_formatter.rb +79 -0
- data/lib/simplecov/formatter/json_formatter/errors_formatter.rb +84 -0
- data/lib/simplecov/formatter/json_formatter/result_hash_formatter.rb +128 -0
- data/lib/simplecov/formatter/json_formatter/source_file_formatter.rb +99 -0
- data/lib/simplecov/formatter/json_formatter.rb +87 -0
- data/lib/simplecov/formatter/multi_formatter.rb +4 -5
- data/lib/simplecov/formatter/simple_formatter.rb +9 -11
- data/lib/simplecov/formatter.rb +4 -0
- data/lib/simplecov/last_run.rb +10 -3
- data/lib/simplecov/lines_classifier.rb +25 -13
- data/lib/simplecov/load_global_config.rb +9 -4
- data/lib/simplecov/parallel_adapters/base.rb +61 -0
- data/lib/simplecov/parallel_adapters/generic.rb +44 -0
- data/lib/simplecov/parallel_adapters/parallel_tests.rb +93 -0
- data/lib/simplecov/parallel_adapters.rb +83 -0
- data/lib/simplecov/parallel_coordination.rb +129 -0
- data/lib/simplecov/process.rb +31 -13
- data/lib/simplecov/profiles/bundler_filter.rb +1 -1
- data/lib/simplecov/profiles/hidden_filter.rb +1 -1
- data/lib/simplecov/profiles/rails.rb +24 -10
- data/lib/simplecov/profiles/root_filter.rb +6 -5
- data/lib/simplecov/profiles/strict.rb +32 -0
- data/lib/simplecov/profiles/test_frameworks.rb +1 -4
- data/lib/simplecov/profiles.rb +32 -3
- data/lib/simplecov/result/missing_source_files_reporter.rb +49 -0
- data/lib/simplecov/result/source_file_builder.rb +51 -0
- data/lib/simplecov/result.rb +108 -19
- data/lib/simplecov/result_adapter.rb +70 -8
- data/lib/simplecov/result_merger/legacy_format_adapter.rb +28 -0
- data/lib/simplecov/result_merger/resultset_file.rb +38 -0
- data/lib/simplecov/result_merger/resultset_store.rb +50 -0
- data/lib/simplecov/result_merger.rb +59 -91
- data/lib/simplecov/result_processing.rb +179 -0
- data/lib/simplecov/simulate_coverage.rb +54 -8
- data/lib/simplecov/source_file/branch.rb +1 -3
- data/lib/simplecov/source_file/branch_builder.rb +114 -0
- data/lib/simplecov/source_file/builder_context.rb +28 -0
- data/lib/simplecov/source_file/line.rb +7 -2
- data/lib/simplecov/source_file/line_builder.rb +43 -0
- data/lib/simplecov/source_file/method.rb +52 -0
- data/lib/simplecov/source_file/method_builder.rb +58 -0
- data/lib/simplecov/source_file/ruby_data_parser.rb +88 -0
- data/lib/simplecov/source_file/skip_chunks.rb +75 -0
- data/lib/simplecov/source_file/source_loader.rb +63 -0
- data/lib/simplecov/source_file/statistics.rb +57 -0
- data/lib/simplecov/source_file.rb +66 -232
- data/lib/simplecov/static_coverage_extractor/method_collector.rb +55 -0
- data/lib/simplecov/static_coverage_extractor/visitor.rb +171 -0
- data/lib/simplecov/static_coverage_extractor.rb +110 -0
- data/lib/simplecov/useless_results_remover.rb +16 -7
- data/lib/simplecov/version.rb +1 -1
- data/lib/simplecov-html.rb +4 -0
- data/lib/simplecov.rb +156 -371
- data/lib/simplecov_json_formatter.rb +4 -0
- data/schemas/coverage-v1.0.schema.json +306 -0
- data/schemas/coverage.schema.json +306 -0
- metadata +90 -57
- data/CHANGELOG.md +0 -191
- data/lib/simplecov/default_formatter.rb +0 -20
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "fileutils"
|
|
4
|
-
require "docile"
|
|
5
|
-
require_relative "formatter/multi_formatter"
|
|
6
4
|
|
|
7
5
|
module SimpleCov
|
|
8
6
|
#
|
|
@@ -11,8 +9,6 @@ module SimpleCov
|
|
|
11
9
|
# SimpleCov documentation for further info.
|
|
12
10
|
#
|
|
13
11
|
module Configuration
|
|
14
|
-
attr_writer :filters, :groups, :formatter, :print_error_status
|
|
15
|
-
|
|
16
12
|
#
|
|
17
13
|
# The root for the project. This defaults to the
|
|
18
14
|
# current working directory.
|
|
@@ -22,7 +18,7 @@ module SimpleCov
|
|
|
22
18
|
def root(root = nil)
|
|
23
19
|
return @root if defined?(@root) && root.nil?
|
|
24
20
|
|
|
25
|
-
@coverage_path = nil # invalidate cache
|
|
21
|
+
@coverage_path = nil unless @coverage_path_explicit # invalidate cache
|
|
26
22
|
@root = File.expand_path(root || Dir.getwd)
|
|
27
23
|
end
|
|
28
24
|
|
|
@@ -34,467 +30,155 @@ module SimpleCov
|
|
|
34
30
|
def coverage_dir(dir = nil)
|
|
35
31
|
return @coverage_dir if defined?(@coverage_dir) && dir.nil?
|
|
36
32
|
|
|
37
|
-
@coverage_path = nil # invalidate cache
|
|
38
|
-
@
|
|
33
|
+
@coverage_path = nil unless @coverage_path_explicit # invalidate cache
|
|
34
|
+
@coverage_dir_explicit = true unless dir.nil?
|
|
35
|
+
@coverage_dir = dir || "coverage"
|
|
39
36
|
end
|
|
40
37
|
|
|
41
38
|
#
|
|
42
|
-
# Returns the full path to the output directory
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
def coverage_path
|
|
47
|
-
@coverage_path ||= begin
|
|
48
|
-
coverage_path = File.expand_path(coverage_dir, root)
|
|
49
|
-
FileUtils.mkdir_p coverage_path
|
|
50
|
-
coverage_path
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
39
|
+
# Returns the full path to the output directory. By default
|
|
40
|
+
# constructed from `SimpleCov.root` + `SimpleCov.coverage_dir`, but
|
|
41
|
+
# callers can override with an arbitrary absolute path — handy for
|
|
42
|
+
# out-of-tree build directories. See #716.
|
|
54
43
|
#
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
#
|
|
44
|
+
# Reading is pure: the directory is only created when a path is
|
|
45
|
+
# explicitly assigned (the user has signaled they intend to write
|
|
46
|
+
# there). The codepaths that actually write into the directory
|
|
47
|
+
# (formatters, `LastRun`, `ResultsetStore`) ensure existence
|
|
48
|
+
# themselves, so read-only CLI subcommands that interpolate the
|
|
49
|
+
# path into status text don't materialize a stray `coverage/`
|
|
50
|
+
# directory.
|
|
58
51
|
#
|
|
59
|
-
def
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
def coverage_path(path = nil)
|
|
53
|
+
if path
|
|
54
|
+
@coverage_path = File.expand_path(path)
|
|
55
|
+
@coverage_path_explicit = true
|
|
56
|
+
FileUtils.mkdir_p @coverage_path
|
|
57
|
+
end
|
|
62
58
|
|
|
63
|
-
|
|
64
|
-
# Returns the glob that will be used to include files that were not
|
|
65
|
-
# explicitly required.
|
|
66
|
-
#
|
|
67
|
-
def tracked_files
|
|
68
|
-
@tracked_files if defined?(@tracked_files)
|
|
59
|
+
@coverage_path ||= File.expand_path(coverage_dir, root)
|
|
69
60
|
end
|
|
70
61
|
|
|
71
62
|
#
|
|
72
|
-
#
|
|
73
|
-
#
|
|
74
|
-
|
|
75
|
-
@filters ||= []
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
# The name of the command (a.k.a. Test Suite) currently running. Used for result
|
|
79
|
-
# merging and caching. It first tries to make a guess based upon the command line
|
|
80
|
-
# arguments the current test suite is running on and should automatically detect
|
|
81
|
-
# unit tests, functional tests, integration tests, rpsec and cucumber and label
|
|
82
|
-
# them properly. If it fails to recognize the current command, the command name
|
|
83
|
-
# is set to the shell command that the current suite is running on.
|
|
63
|
+
# The name of the command (a.k.a. Test Suite) currently running.
|
|
64
|
+
# Used for result merging and caching. Auto-detected; set explicitly
|
|
65
|
+
# with SimpleCov.command_name("test:units").
|
|
84
66
|
#
|
|
85
|
-
# You can specify it manually with SimpleCov.command_name("test:units") - please
|
|
86
|
-
# also check out the corresponding section in README.rdoc
|
|
87
67
|
def command_name(name = nil)
|
|
88
68
|
@name = name unless name.nil?
|
|
89
69
|
@name ||= SimpleCov::CommandGuesser.guess
|
|
90
70
|
@name
|
|
91
71
|
end
|
|
92
72
|
|
|
93
|
-
#
|
|
94
|
-
# Gets or sets the configured formatter.
|
|
95
|
-
#
|
|
96
|
-
# Configure with: SimpleCov.formatter(SimpleCov::Formatter::SimpleFormatter)
|
|
97
|
-
#
|
|
98
|
-
def formatter(formatter = nil)
|
|
99
|
-
return @formatter if defined?(@formatter) && formatter.nil?
|
|
100
|
-
|
|
101
|
-
@formatter = formatter
|
|
102
|
-
raise "No formatter configured. Please specify a formatter using SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter" unless @formatter
|
|
103
|
-
|
|
104
|
-
@formatter
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
#
|
|
108
|
-
# Sets the configured formatters.
|
|
109
|
-
#
|
|
110
|
-
def formatters=(formatters)
|
|
111
|
-
@formatter = SimpleCov::Formatter::MultiFormatter.new(formatters)
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
#
|
|
115
|
-
# Gets the configured formatters.
|
|
116
|
-
#
|
|
117
|
-
def formatters
|
|
118
|
-
if @formatter.is_a?(SimpleCov::Formatter::MultiFormatter)
|
|
119
|
-
@formatter.formatters
|
|
120
|
-
else
|
|
121
|
-
Array(formatter)
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
#
|
|
126
|
-
# Whether we should print non-success status codes. This can be
|
|
127
|
-
# configured with the #print_error_status= method.
|
|
128
|
-
#
|
|
129
|
-
def print_error_status
|
|
130
|
-
defined?(@print_error_status) ? @print_error_status : true
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
#
|
|
134
|
-
# Certain code blocks (i.e. Ruby-implementation specific code) can be excluded from
|
|
135
|
-
# the coverage metrics by wrapping it inside # :nocov: comment blocks. The nocov token
|
|
136
|
-
# can be configured to be any other string using this.
|
|
137
|
-
#
|
|
138
|
-
# Configure with SimpleCov.nocov_token('skip') or it's alias SimpleCov.skip_token('skip')
|
|
139
|
-
#
|
|
140
|
-
def nocov_token(nocov_token = nil)
|
|
141
|
-
return @nocov_token if defined?(@nocov_token) && nocov_token.nil?
|
|
142
|
-
|
|
143
|
-
@nocov_token = (nocov_token || "nocov")
|
|
144
|
-
end
|
|
145
|
-
alias skip_token nocov_token
|
|
146
|
-
|
|
147
|
-
#
|
|
148
|
-
# Returns the configured groups. Add groups using SimpleCov.add_group
|
|
149
|
-
#
|
|
150
|
-
def groups
|
|
151
|
-
@groups ||= {}
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
#
|
|
155
73
|
# Returns the hash of available profiles
|
|
156
|
-
#
|
|
157
74
|
def profiles
|
|
158
75
|
@profiles ||= SimpleCov::Profiles.new
|
|
159
76
|
end
|
|
160
77
|
|
|
161
|
-
def adapters
|
|
162
|
-
warn "#{Kernel.caller.first}: [DEPRECATION] #adapters is deprecated. Use #profiles instead."
|
|
163
|
-
profiles
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
#
|
|
167
|
-
# Allows you to configure simplecov in a block instead of prepending SimpleCov to all config methods
|
|
168
|
-
# you're calling.
|
|
169
|
-
#
|
|
170
|
-
# SimpleCov.configure do
|
|
171
|
-
# add_filter 'foobar'
|
|
172
|
-
# end
|
|
173
78
|
#
|
|
174
|
-
#
|
|
175
|
-
#
|
|
79
|
+
# Allows you to configure simplecov in a block instead of
|
|
80
|
+
# prepending SimpleCov to each config method.
|
|
176
81
|
#
|
|
177
82
|
def configure(&block)
|
|
178
|
-
|
|
83
|
+
block_context = block.binding.receiver
|
|
84
|
+
|
|
85
|
+
# If the block was defined in our own context, instance_exec is sufficient
|
|
86
|
+
return instance_exec(&block) if equal?(block_context)
|
|
87
|
+
|
|
88
|
+
# Copy the caller's instance variables in so that references like @filter
|
|
89
|
+
# inside the block resolve to the caller's values, not ours.
|
|
90
|
+
saved = swap_ivars_from(block_context)
|
|
91
|
+
instance_exec(&block)
|
|
92
|
+
ensure
|
|
93
|
+
restore_ivars(block_context, saved) if defined?(saved) && saved
|
|
179
94
|
end
|
|
180
95
|
|
|
181
96
|
#
|
|
182
97
|
# Gets or sets the behavior to process coverage results.
|
|
183
|
-
#
|
|
184
|
-
#
|
|
185
|
-
#
|
|
186
|
-
# Configure with:
|
|
187
|
-
#
|
|
188
|
-
# SimpleCov.at_exit do
|
|
189
|
-
# puts "Coverage done"
|
|
190
|
-
# SimpleCov.result.format!
|
|
191
|
-
# end
|
|
98
|
+
# By default, it stores/merges the current result and formats only
|
|
99
|
+
# from the final reporting process.
|
|
192
100
|
#
|
|
193
101
|
def at_exit(&block)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
@at_exit ||= proc { SimpleCov.result.format! }
|
|
198
|
-
end
|
|
102
|
+
@at_exit = block if block
|
|
103
|
+
return @at_exit if @at_exit
|
|
104
|
+
return proc {} unless active_session?
|
|
199
105
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
@enable_for_subprocesses = value || false
|
|
106
|
+
@at_exit = proc do
|
|
107
|
+
result = SimpleCov.result
|
|
108
|
+
result.format! if result && SimpleCov.merge_finalization_owner? && SimpleCov.final_result_process?
|
|
109
|
+
end
|
|
206
110
|
end
|
|
207
111
|
|
|
208
|
-
#
|
|
209
|
-
|
|
210
|
-
|
|
112
|
+
# Whether SimpleCov has anything to do at exit: the Coverage module
|
|
113
|
+
# is actively tracking, or a `@result` has already been assembled
|
|
114
|
+
# (e.g. by `SimpleCov.collate`, which never starts Coverage).
|
|
115
|
+
def active_session?
|
|
116
|
+
SimpleCov.result? || (defined?(Coverage) && Coverage.running?)
|
|
211
117
|
end
|
|
212
118
|
|
|
213
119
|
#
|
|
214
120
|
# Gets or sets the behavior to start a new forked Process.
|
|
215
|
-
#
|
|
216
|
-
#
|
|
217
|
-
#
|
|
218
|
-
# Configure with:
|
|
219
|
-
#
|
|
220
|
-
# SimpleCov.at_fork do |pid|
|
|
221
|
-
# SimpleCov.start do
|
|
222
|
-
# # This needs a unique name so it won't be ovewritten
|
|
223
|
-
# SimpleCov.command_name "#{SimpleCov.command_name} (subprocess: #{pid})"
|
|
224
|
-
# # be quiet, the parent process will be in charge of using the regular formatter and checking coverage totals
|
|
225
|
-
# SimpleCov.print_error_status = false
|
|
226
|
-
# SimpleCov.formatter SimpleCov::Formatter::SimpleFormatter
|
|
227
|
-
# SimpleCov.minimum_coverage 0
|
|
228
|
-
# # start
|
|
229
|
-
# SimpleCov.start
|
|
230
|
-
# end
|
|
231
|
-
# end
|
|
121
|
+
# Defaults to adding " (subprocess: #{serial})" to command_name and
|
|
122
|
+
# starting SimpleCov in quiet mode.
|
|
232
123
|
#
|
|
233
124
|
def at_fork(&block)
|
|
234
|
-
@at_fork = block if
|
|
235
|
-
@at_fork ||= lambda { |
|
|
236
|
-
#
|
|
237
|
-
|
|
238
|
-
#
|
|
239
|
-
|
|
125
|
+
@at_fork = block if block
|
|
126
|
+
@at_fork ||= lambda { |_pid|
|
|
127
|
+
# Needs a name that's unique per worker within a run yet identical
|
|
128
|
+
# across runs. Build it from SimpleCov's stable fork serial rather
|
|
129
|
+
# than the OS pid: with the pid, every run produced uniquely-named
|
|
130
|
+
# results that never overwrote the previous run's, so they piled up
|
|
131
|
+
# in .resultset.json until merge_timeout and the merged report's
|
|
132
|
+
# file set drifted from run to run. See issue #1171.
|
|
133
|
+
SimpleCov.command_name "#{SimpleCov.command_name} (subprocess: #{SimpleCov.subprocess_serial})"
|
|
134
|
+
# be quiet, the parent process will use the regular formatter
|
|
135
|
+
SimpleCov.print_errors false
|
|
240
136
|
SimpleCov.formatter SimpleCov::Formatter::SimpleFormatter
|
|
241
137
|
SimpleCov.minimum_coverage 0
|
|
242
|
-
# start
|
|
243
138
|
SimpleCov.start
|
|
244
139
|
}
|
|
245
140
|
end
|
|
246
141
|
|
|
247
142
|
#
|
|
248
|
-
# Returns the project name
|
|
249
|
-
#
|
|
143
|
+
# Returns the project name — defaults to the last dirname in
|
|
144
|
+
# SimpleCov.root, capitalized with underscores → spaces.
|
|
250
145
|
#
|
|
251
146
|
def project_name(new_name = nil)
|
|
252
147
|
return @project_name if defined?(@project_name) && @project_name && new_name.nil?
|
|
253
148
|
|
|
254
149
|
@project_name = new_name if new_name.is_a?(String)
|
|
255
|
-
@project_name ||= File.basename(root
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
#
|
|
259
|
-
# Defines whether to use result merging so all your test suites (test:units, test:functionals, cucumber, ...)
|
|
260
|
-
# are joined and combined into a single coverage report
|
|
261
|
-
#
|
|
262
|
-
def use_merging(use = nil)
|
|
263
|
-
@use_merging = use unless use.nil?
|
|
264
|
-
@use_merging = true unless defined?(@use_merging) && @use_merging == false
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
#
|
|
268
|
-
# Defines the maximum age (in seconds) of a resultset to still be included in merged results.
|
|
269
|
-
# i.e. If you run cucumber features, then later rake test, if the stored cucumber resultset is
|
|
270
|
-
# more seconds ago than specified here, it won't be taken into account when merging (and is also
|
|
271
|
-
# purged from the resultset cache)
|
|
272
|
-
#
|
|
273
|
-
# Of course, this only applies when merging is active (e.g. SimpleCov.use_merging is not false!)
|
|
274
|
-
#
|
|
275
|
-
# Default is 600 seconds (10 minutes)
|
|
276
|
-
#
|
|
277
|
-
# Configure with SimpleCov.merge_timeout(3600) # 1hr
|
|
278
|
-
#
|
|
279
|
-
def merge_timeout(seconds = nil)
|
|
280
|
-
@merge_timeout = seconds if seconds.is_a?(Integer)
|
|
281
|
-
@merge_timeout ||= 600
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
#
|
|
285
|
-
# Defines the minimum overall coverage required for the testsuite to pass.
|
|
286
|
-
# SimpleCov will return non-zero if the current coverage is below this threshold.
|
|
287
|
-
#
|
|
288
|
-
# Default is 0% (disabled)
|
|
289
|
-
#
|
|
290
|
-
def minimum_coverage(coverage = nil)
|
|
291
|
-
return @minimum_coverage ||= {} unless coverage
|
|
292
|
-
|
|
293
|
-
coverage = {primary_coverage => coverage} if coverage.is_a?(Numeric)
|
|
294
|
-
|
|
295
|
-
raise_on_invalid_coverage(coverage, "minimum_coverage")
|
|
296
|
-
|
|
297
|
-
@minimum_coverage = coverage
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
def raise_on_invalid_coverage(coverage, coverage_setting)
|
|
301
|
-
coverage.each_key { |criterion| raise_if_criterion_disabled(criterion) }
|
|
302
|
-
coverage.each_value do |percent|
|
|
303
|
-
minimum_possible_coverage_exceeded(coverage_setting) if percent && percent > 100
|
|
304
|
-
end
|
|
305
|
-
end
|
|
306
|
-
|
|
307
|
-
#
|
|
308
|
-
# Defines the maximum coverage drop at once allowed for the testsuite to pass.
|
|
309
|
-
# SimpleCov will return non-zero if the coverage decreases by more than this threshold.
|
|
310
|
-
#
|
|
311
|
-
# Default is 100% (disabled)
|
|
312
|
-
#
|
|
313
|
-
def maximum_coverage_drop(coverage_drop = nil)
|
|
314
|
-
return @maximum_coverage_drop ||= {} unless coverage_drop
|
|
315
|
-
|
|
316
|
-
coverage_drop = {primary_coverage => coverage_drop} if coverage_drop.is_a?(Numeric)
|
|
317
|
-
|
|
318
|
-
raise_on_invalid_coverage(coverage_drop, "maximum_coverage_drop")
|
|
319
|
-
|
|
320
|
-
@maximum_coverage_drop = coverage_drop
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
#
|
|
324
|
-
# Defines the minimum coverage per file required for the testsuite to pass.
|
|
325
|
-
# SimpleCov will return non-zero if the current coverage of the least covered file
|
|
326
|
-
# is below this threshold.
|
|
327
|
-
#
|
|
328
|
-
# Default is 0% (disabled)
|
|
329
|
-
#
|
|
330
|
-
def minimum_coverage_by_file(coverage = nil)
|
|
331
|
-
return @minimum_coverage_by_file ||= {} unless coverage
|
|
332
|
-
|
|
333
|
-
coverage = {primary_coverage => coverage} if coverage.is_a?(Numeric)
|
|
334
|
-
|
|
335
|
-
raise_on_invalid_coverage(coverage, "minimum_coverage_by_file")
|
|
336
|
-
|
|
337
|
-
@minimum_coverage_by_file = coverage
|
|
338
|
-
end
|
|
339
|
-
|
|
340
|
-
#
|
|
341
|
-
# Refuses any coverage drop. That is, coverage is only allowed to increase.
|
|
342
|
-
# SimpleCov will return non-zero if the coverage decreases.
|
|
343
|
-
#
|
|
344
|
-
def refuse_coverage_drop(*criteria)
|
|
345
|
-
criteria = coverage_criteria if criteria.empty?
|
|
346
|
-
|
|
347
|
-
maximum_coverage_drop(criteria.map { |c| [c, 0] }.to_h)
|
|
348
|
-
end
|
|
349
|
-
|
|
350
|
-
#
|
|
351
|
-
# Add a filter to the processing chain.
|
|
352
|
-
# There are four ways to define a filter:
|
|
353
|
-
#
|
|
354
|
-
# * as a String that will then be matched against all source files' file paths,
|
|
355
|
-
# SimpleCov.add_filter 'app/models' # will reject all your models
|
|
356
|
-
# * as a block which will be passed the source file in question and should either
|
|
357
|
-
# return a true or false value, depending on whether the file should be removed
|
|
358
|
-
# SimpleCov.add_filter do |src_file|
|
|
359
|
-
# File.basename(src_file.filename) == 'environment.rb'
|
|
360
|
-
# end # Will exclude environment.rb files from the results
|
|
361
|
-
# * as an array of strings that are matched against all sorce files' file
|
|
362
|
-
# paths and then ignored (basically string filter multiple times)
|
|
363
|
-
# SimpleCov.add_filter ['app/models', 'app/helpers'] # ignores both dirs
|
|
364
|
-
# * as an instance of a subclass of SimpleCov::Filter. See the documentation there
|
|
365
|
-
# on how to define your own filter classes
|
|
366
|
-
#
|
|
367
|
-
def add_filter(filter_argument = nil, &filter_proc)
|
|
368
|
-
filters << parse_filter(filter_argument, &filter_proc)
|
|
369
|
-
end
|
|
370
|
-
|
|
371
|
-
#
|
|
372
|
-
# Define a group for files. Works similar to add_filter, only that the first
|
|
373
|
-
# argument is the desired group name and files PASSING the filter end up in the group
|
|
374
|
-
# (while filters exclude when the filter is applicable).
|
|
375
|
-
#
|
|
376
|
-
def add_group(group_name, filter_argument = nil, &filter_proc)
|
|
377
|
-
groups[group_name] = parse_filter(filter_argument, &filter_proc)
|
|
378
|
-
end
|
|
379
|
-
|
|
380
|
-
SUPPORTED_COVERAGE_CRITERIA = %i[line branch].freeze
|
|
381
|
-
DEFAULT_COVERAGE_CRITERION = :line
|
|
382
|
-
#
|
|
383
|
-
# Define which coverage criterion should be evaluated.
|
|
384
|
-
#
|
|
385
|
-
# Possible coverage criteria:
|
|
386
|
-
# * :line - coverage based on lines aka has this line been executed?
|
|
387
|
-
# * :branch - coverage based on branches aka has this branch (think conditions) been executed?
|
|
388
|
-
#
|
|
389
|
-
# If not set the default is `:line`
|
|
390
|
-
#
|
|
391
|
-
# @param [Symbol] criterion
|
|
392
|
-
#
|
|
393
|
-
def coverage_criterion(criterion = nil)
|
|
394
|
-
return @coverage_criterion ||= primary_coverage unless criterion
|
|
395
|
-
|
|
396
|
-
raise_if_criterion_unsupported(criterion)
|
|
397
|
-
|
|
398
|
-
@coverage_criterion = criterion
|
|
399
|
-
end
|
|
400
|
-
|
|
401
|
-
def enable_coverage(criterion)
|
|
402
|
-
raise_if_criterion_unsupported(criterion)
|
|
403
|
-
|
|
404
|
-
coverage_criteria << criterion
|
|
405
|
-
end
|
|
406
|
-
|
|
407
|
-
def primary_coverage(criterion = nil)
|
|
408
|
-
if criterion.nil?
|
|
409
|
-
@primary_coverage ||= DEFAULT_COVERAGE_CRITERION
|
|
410
|
-
else
|
|
411
|
-
raise_if_criterion_disabled(criterion)
|
|
412
|
-
@primary_coverage = criterion
|
|
413
|
-
end
|
|
414
|
-
end
|
|
415
|
-
|
|
416
|
-
def coverage_criteria
|
|
417
|
-
@coverage_criteria ||= Set[primary_coverage]
|
|
418
|
-
end
|
|
419
|
-
|
|
420
|
-
def coverage_criterion_enabled?(criterion)
|
|
421
|
-
coverage_criteria.member?(criterion)
|
|
422
|
-
end
|
|
423
|
-
|
|
424
|
-
def clear_coverage_criteria
|
|
425
|
-
@coverage_criteria = nil
|
|
426
|
-
end
|
|
427
|
-
|
|
428
|
-
def branch_coverage?
|
|
429
|
-
branch_coverage_supported? && coverage_criterion_enabled?(:branch)
|
|
430
|
-
end
|
|
431
|
-
|
|
432
|
-
def coverage_start_arguments_supported?
|
|
433
|
-
# safe to cache as within one process this value should never
|
|
434
|
-
# change
|
|
435
|
-
return @coverage_start_arguments_supported if defined?(@coverage_start_arguments_supported)
|
|
436
|
-
|
|
437
|
-
@coverage_start_arguments_supported = begin
|
|
438
|
-
require "coverage"
|
|
439
|
-
!Coverage.method(:start).arity.zero?
|
|
440
|
-
end
|
|
441
|
-
end
|
|
442
|
-
|
|
443
|
-
def branch_coverage_supported?
|
|
444
|
-
coverage_start_arguments_supported? && RUBY_ENGINE != "jruby"
|
|
445
|
-
end
|
|
446
|
-
|
|
447
|
-
def coverage_for_eval_supported?
|
|
448
|
-
require "coverage"
|
|
449
|
-
defined?(Coverage.supported?) && Coverage.supported?(:eval)
|
|
450
|
-
end
|
|
451
|
-
|
|
452
|
-
def coverage_for_eval_enabled?
|
|
453
|
-
@coverage_for_eval_enabled ||= false
|
|
454
|
-
end
|
|
455
|
-
|
|
456
|
-
def enable_coverage_for_eval
|
|
457
|
-
if coverage_for_eval_supported?
|
|
458
|
-
@coverage_for_eval_enabled = true
|
|
459
|
-
else
|
|
460
|
-
warn "Coverage for eval is not available; Use Ruby 3.2.0 or later"
|
|
461
|
-
end
|
|
150
|
+
@project_name ||= File.basename(root).capitalize.tr("_", " ")
|
|
462
151
|
end
|
|
463
152
|
|
|
464
153
|
private
|
|
465
154
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
155
|
+
# Copy instance variables from block_context into self, saving any
|
|
156
|
+
# of ours that would be clobbered. Returns the saved values for
|
|
157
|
+
# later restoration.
|
|
158
|
+
def swap_ivars_from(block_context)
|
|
159
|
+
saved = {}
|
|
160
|
+
our_ivars = instance_variables
|
|
161
|
+
block_context.instance_variables.each do |ivar|
|
|
162
|
+
saved[ivar] = instance_variable_get(ivar) if our_ivars.include?(ivar)
|
|
163
|
+
instance_variable_set(ivar, block_context.instance_variable_get(ivar))
|
|
471
164
|
end
|
|
472
|
-
|
|
165
|
+
saved
|
|
473
166
|
end
|
|
474
167
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
end
|
|
480
|
-
# rubocop:enable Style/IfUnlessModifier
|
|
481
|
-
end
|
|
482
|
-
|
|
483
|
-
def minimum_possible_coverage_exceeded(coverage_option)
|
|
484
|
-
warn "The coverage you set for #{coverage_option} is greater than 100%"
|
|
485
|
-
end
|
|
486
|
-
|
|
487
|
-
#
|
|
488
|
-
# The actual filter processor. Not meant for direct use
|
|
489
|
-
#
|
|
490
|
-
def parse_filter(filter_argument = nil, &filter_proc)
|
|
491
|
-
filter = filter_argument || filter_proc
|
|
492
|
-
|
|
493
|
-
if filter
|
|
494
|
-
SimpleCov::Filter.build_filter(filter)
|
|
495
|
-
else
|
|
496
|
-
raise ArgumentError, "Please specify either a filter or a block to filter with"
|
|
168
|
+
# Copy instance variables back to block_context and restore our saved values.
|
|
169
|
+
def restore_ivars(block_context, saved)
|
|
170
|
+
block_context.instance_variables.each do |ivar|
|
|
171
|
+
block_context.instance_variable_set(ivar, instance_variable_get(ivar))
|
|
497
172
|
end
|
|
173
|
+
saved.each { |ivar, value| instance_variable_set(ivar, value) }
|
|
498
174
|
end
|
|
499
175
|
end
|
|
500
176
|
end
|
|
177
|
+
|
|
178
|
+
require_relative "configuration/coverage"
|
|
179
|
+
require_relative "configuration/coverage_criteria"
|
|
180
|
+
require_relative "configuration/filters"
|
|
181
|
+
require_relative "configuration/formatting"
|
|
182
|
+
require_relative "configuration/ignored_entries"
|
|
183
|
+
require_relative "configuration/merging"
|
|
184
|
+
require_relative "configuration/thresholds"
|
|
@@ -8,34 +8,37 @@ module SimpleCov
|
|
|
8
8
|
# * total - how many things to cover there are (total relevant loc/branches)
|
|
9
9
|
# * covered - how many of the coverables are hit
|
|
10
10
|
# * missed - how many of the coverables are missed
|
|
11
|
+
# * omitted - how many lines cannot be covered (blank lines/comments); only meaningful for line coverage
|
|
11
12
|
# * percent - percentage as covered/missed
|
|
12
13
|
# * strength - average hits per/coverable (will not exist for one shot lines format)
|
|
13
14
|
class CoverageStatistics
|
|
14
|
-
attr_reader :total, :covered, :missed, :strength, :percent
|
|
15
|
+
attr_reader :total, :covered, :missed, :omitted, :strength, :percent
|
|
15
16
|
|
|
16
17
|
def self.from(coverage_statistics)
|
|
17
|
-
sum_covered, sum_missed, sum_total_strength =
|
|
18
|
-
coverage_statistics.reduce([0, 0, 0.0]) do |(covered, missed, total_strength),
|
|
18
|
+
sum_covered, sum_missed, sum_omitted, sum_total_strength =
|
|
19
|
+
coverage_statistics.reduce([0, 0, 0, 0.0]) do |(covered, missed, omitted, total_strength), stats|
|
|
19
20
|
[
|
|
20
|
-
covered +
|
|
21
|
-
missed +
|
|
21
|
+
covered + stats.covered,
|
|
22
|
+
missed + stats.missed,
|
|
23
|
+
omitted + stats.omitted,
|
|
22
24
|
# gotta remultiply with loc because files have different strength and loc
|
|
23
25
|
# giving them a different "weight" in total
|
|
24
|
-
total_strength + (
|
|
26
|
+
total_strength + (stats.strength * stats.total)
|
|
25
27
|
]
|
|
26
28
|
end
|
|
27
29
|
|
|
28
|
-
new(covered: sum_covered, missed: sum_missed, total_strength: sum_total_strength)
|
|
30
|
+
new(covered: sum_covered, missed: sum_missed, omitted: sum_omitted, total_strength: sum_total_strength)
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
# Requires only covered, missed and strength to be initialized.
|
|
32
34
|
#
|
|
33
35
|
# Other values are computed by this class.
|
|
34
|
-
def initialize(covered:, missed:, total_strength: 0.0)
|
|
36
|
+
def initialize(covered:, missed:, omitted: 0, total_strength: 0.0, percent: nil)
|
|
35
37
|
@covered = covered
|
|
36
38
|
@missed = missed
|
|
39
|
+
@omitted = omitted
|
|
37
40
|
@total = covered + missed
|
|
38
|
-
@percent = compute_percent(covered, missed, total)
|
|
41
|
+
@percent = percent || compute_percent(covered, missed, total)
|
|
39
42
|
@strength = compute_strength(total_strength, total)
|
|
40
43
|
end
|
|
41
44
|
|