nano-fast-box 0.0.1
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 +7 -0
- data/nano-fast-box.gemspec +12 -0
- data/simplecov-0.22.0/CHANGELOG.md +191 -0
- data/simplecov-0.22.0/LICENSE +20 -0
- data/simplecov-0.22.0/README.md +974 -0
- data/simplecov-0.22.0/doc/alternate-formatters.md +71 -0
- data/simplecov-0.22.0/doc/commercial-services.md +25 -0
- data/simplecov-0.22.0/doc/editor-integration.md +18 -0
- data/simplecov-0.22.0/lib/minitest/simplecov_plugin.rb +15 -0
- data/simplecov-0.22.0/lib/simplecov/combine/branches_combiner.rb +32 -0
- data/simplecov-0.22.0/lib/simplecov/combine/files_combiner.rb +24 -0
- data/simplecov-0.22.0/lib/simplecov/combine/lines_combiner.rb +43 -0
- data/simplecov-0.22.0/lib/simplecov/combine/results_combiner.rb +60 -0
- data/simplecov-0.22.0/lib/simplecov/combine.rb +30 -0
- data/simplecov-0.22.0/lib/simplecov/command_guesser.rb +64 -0
- data/simplecov-0.22.0/lib/simplecov/configuration.rb +500 -0
- data/simplecov-0.22.0/lib/simplecov/coverage_statistics.rb +56 -0
- data/simplecov-0.22.0/lib/simplecov/default_formatter.rb +20 -0
- data/simplecov-0.22.0/lib/simplecov/defaults.rb +53 -0
- data/simplecov-0.22.0/lib/simplecov/exit_codes/exit_code_handling.rb +29 -0
- data/simplecov-0.22.0/lib/simplecov/exit_codes/maximum_coverage_drop_check.rb +83 -0
- data/simplecov-0.22.0/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb +54 -0
- data/simplecov-0.22.0/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb +53 -0
- data/simplecov-0.22.0/lib/simplecov/exit_codes.rb +15 -0
- data/simplecov-0.22.0/lib/simplecov/file_list.rb +120 -0
- data/simplecov-0.22.0/lib/simplecov/filter.rb +94 -0
- data/simplecov-0.22.0/lib/simplecov/formatter/multi_formatter.rb +32 -0
- data/simplecov-0.22.0/lib/simplecov/formatter/simple_formatter.rb +25 -0
- data/simplecov-0.22.0/lib/simplecov/formatter.rb +10 -0
- data/simplecov-0.22.0/lib/simplecov/last_run.rb +28 -0
- data/simplecov-0.22.0/lib/simplecov/lines_classifier.rb +48 -0
- data/simplecov-0.22.0/lib/simplecov/load_global_config.rb +8 -0
- data/simplecov-0.22.0/lib/simplecov/no_defaults.rb +4 -0
- data/simplecov-0.22.0/lib/simplecov/process.rb +19 -0
- data/simplecov-0.22.0/lib/simplecov/profiles/bundler_filter.rb +5 -0
- data/simplecov-0.22.0/lib/simplecov/profiles/hidden_filter.rb +5 -0
- data/simplecov-0.22.0/lib/simplecov/profiles/rails.rb +18 -0
- data/simplecov-0.22.0/lib/simplecov/profiles/root_filter.rb +10 -0
- data/simplecov-0.22.0/lib/simplecov/profiles/test_frameworks.rb +8 -0
- data/simplecov-0.22.0/lib/simplecov/profiles.rb +35 -0
- data/simplecov-0.22.0/lib/simplecov/result.rb +94 -0
- data/simplecov-0.22.0/lib/simplecov/result_adapter.rb +30 -0
- data/simplecov-0.22.0/lib/simplecov/result_merger.rb +194 -0
- data/simplecov-0.22.0/lib/simplecov/simulate_coverage.rb +29 -0
- data/simplecov-0.22.0/lib/simplecov/source_file/branch.rb +84 -0
- data/simplecov-0.22.0/lib/simplecov/source_file/line.rb +72 -0
- data/simplecov-0.22.0/lib/simplecov/source_file.rb +355 -0
- data/simplecov-0.22.0/lib/simplecov/useless_results_remover.rb +18 -0
- data/simplecov-0.22.0/lib/simplecov/version.rb +5 -0
- data/simplecov-0.22.0/lib/simplecov.rb +470 -0
- metadata +90 -0
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "docile"
|
|
5
|
+
require_relative "formatter/multi_formatter"
|
|
6
|
+
|
|
7
|
+
module SimpleCov
|
|
8
|
+
#
|
|
9
|
+
# Bundles the configuration options used for SimpleCov. All methods
|
|
10
|
+
# defined here are usable from SimpleCov directly. Please check out
|
|
11
|
+
# SimpleCov documentation for further info.
|
|
12
|
+
#
|
|
13
|
+
module Configuration
|
|
14
|
+
attr_writer :filters, :groups, :formatter, :print_error_status
|
|
15
|
+
|
|
16
|
+
#
|
|
17
|
+
# The root for the project. This defaults to the
|
|
18
|
+
# current working directory.
|
|
19
|
+
#
|
|
20
|
+
# Configure with SimpleCov.root('/my/project/path')
|
|
21
|
+
#
|
|
22
|
+
def root(root = nil)
|
|
23
|
+
return @root if defined?(@root) && root.nil?
|
|
24
|
+
|
|
25
|
+
@coverage_path = nil # invalidate cache
|
|
26
|
+
@root = File.expand_path(root || Dir.getwd)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
#
|
|
30
|
+
# The name of the output and cache directory. Defaults to 'coverage'
|
|
31
|
+
#
|
|
32
|
+
# Configure with SimpleCov.coverage_dir('cov')
|
|
33
|
+
#
|
|
34
|
+
def coverage_dir(dir = nil)
|
|
35
|
+
return @coverage_dir if defined?(@coverage_dir) && dir.nil?
|
|
36
|
+
|
|
37
|
+
@coverage_path = nil # invalidate cache
|
|
38
|
+
@coverage_dir = (dir || "coverage")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
#
|
|
42
|
+
# Returns the full path to the output directory using SimpleCov.root
|
|
43
|
+
# and SimpleCov.coverage_dir, so you can adjust this by configuring those
|
|
44
|
+
# values. Will create the directory if it's missing
|
|
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
|
+
|
|
54
|
+
#
|
|
55
|
+
# Coverage results will always include files matched by this glob, whether
|
|
56
|
+
# or not they were explicitly required. Without this, un-required files
|
|
57
|
+
# will not be present in the final report.
|
|
58
|
+
#
|
|
59
|
+
def track_files(glob)
|
|
60
|
+
@tracked_files = glob
|
|
61
|
+
end
|
|
62
|
+
|
|
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)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
#
|
|
72
|
+
# Returns the list of configured filters. Add filters using SimpleCov.add_filter.
|
|
73
|
+
#
|
|
74
|
+
def filters
|
|
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.
|
|
84
|
+
#
|
|
85
|
+
# You can specify it manually with SimpleCov.command_name("test:units") - please
|
|
86
|
+
# also check out the corresponding section in README.rdoc
|
|
87
|
+
def command_name(name = nil)
|
|
88
|
+
@name = name unless name.nil?
|
|
89
|
+
@name ||= SimpleCov::CommandGuesser.guess
|
|
90
|
+
@name
|
|
91
|
+
end
|
|
92
|
+
|
|
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
|
+
# Returns the hash of available profiles
|
|
156
|
+
#
|
|
157
|
+
def profiles
|
|
158
|
+
@profiles ||= SimpleCov::Profiles.new
|
|
159
|
+
end
|
|
160
|
+
|
|
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
|
+
#
|
|
174
|
+
# This is equivalent to SimpleCov.add_filter 'foobar' and thus makes it easier to set a bunch of configure
|
|
175
|
+
# options at once.
|
|
176
|
+
#
|
|
177
|
+
def configure(&block)
|
|
178
|
+
Docile.dsl_eval(self, &block)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
#
|
|
182
|
+
# Gets or sets the behavior to process coverage results.
|
|
183
|
+
#
|
|
184
|
+
# By default, it will call SimpleCov.result.format!
|
|
185
|
+
#
|
|
186
|
+
# Configure with:
|
|
187
|
+
#
|
|
188
|
+
# SimpleCov.at_exit do
|
|
189
|
+
# puts "Coverage done"
|
|
190
|
+
# SimpleCov.result.format!
|
|
191
|
+
# end
|
|
192
|
+
#
|
|
193
|
+
def at_exit(&block)
|
|
194
|
+
return Proc.new unless running || block_given?
|
|
195
|
+
|
|
196
|
+
@at_exit = block if block_given?
|
|
197
|
+
@at_exit ||= proc { SimpleCov.result.format! }
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# gets or sets the enabled_for_subprocess configuration
|
|
201
|
+
# when true, this will inject SimpleCov code into Process.fork
|
|
202
|
+
def enable_for_subprocesses(value = nil)
|
|
203
|
+
return @enable_for_subprocesses if defined?(@enable_for_subprocesses) && value.nil?
|
|
204
|
+
|
|
205
|
+
@enable_for_subprocesses = value || false
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
# gets the enabled_for_subprocess configuration
|
|
209
|
+
def enabled_for_subprocesses?
|
|
210
|
+
enable_for_subprocesses
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
#
|
|
214
|
+
# Gets or sets the behavior to start a new forked Process.
|
|
215
|
+
#
|
|
216
|
+
# By default, it will add " (Process #{pid})" to the command_name, and start SimpleCov in quiet mode
|
|
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
|
|
232
|
+
#
|
|
233
|
+
def at_fork(&block)
|
|
234
|
+
@at_fork = block if block_given?
|
|
235
|
+
@at_fork ||= lambda { |pid|
|
|
236
|
+
# This needs a unique name so it won't be ovewritten
|
|
237
|
+
SimpleCov.command_name "#{SimpleCov.command_name} (subprocess: #{pid})"
|
|
238
|
+
# be quiet, the parent process will be in charge of using the regular formatter and checking coverage totals
|
|
239
|
+
SimpleCov.print_error_status = false
|
|
240
|
+
SimpleCov.formatter SimpleCov::Formatter::SimpleFormatter
|
|
241
|
+
SimpleCov.minimum_coverage 0
|
|
242
|
+
# start
|
|
243
|
+
SimpleCov.start
|
|
244
|
+
}
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
#
|
|
248
|
+
# Returns the project name - currently assuming the last dirname in
|
|
249
|
+
# the SimpleCov.root is this.
|
|
250
|
+
#
|
|
251
|
+
def project_name(new_name = nil)
|
|
252
|
+
return @project_name if defined?(@project_name) && @project_name && new_name.nil?
|
|
253
|
+
|
|
254
|
+
@project_name = new_name if new_name.is_a?(String)
|
|
255
|
+
@project_name ||= File.basename(root.split("/").last).capitalize.tr("_", " ")
|
|
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
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
private
|
|
465
|
+
|
|
466
|
+
def raise_if_criterion_disabled(criterion)
|
|
467
|
+
raise_if_criterion_unsupported(criterion)
|
|
468
|
+
# rubocop:disable Style/IfUnlessModifier
|
|
469
|
+
unless coverage_criterion_enabled?(criterion)
|
|
470
|
+
raise "Coverage criterion #{criterion}, is disabled! Please enable it first through enable_coverage #{criterion} (if supported)"
|
|
471
|
+
end
|
|
472
|
+
# rubocop:enable Style/IfUnlessModifier
|
|
473
|
+
end
|
|
474
|
+
|
|
475
|
+
def raise_if_criterion_unsupported(criterion)
|
|
476
|
+
# rubocop:disable Style/IfUnlessModifier
|
|
477
|
+
unless SUPPORTED_COVERAGE_CRITERIA.member?(criterion)
|
|
478
|
+
raise "Unsupported coverage criterion #{criterion}, supported values are #{SUPPORTED_COVERAGE_CRITERIA}"
|
|
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"
|
|
497
|
+
end
|
|
498
|
+
end
|
|
499
|
+
end
|
|
500
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SimpleCov
|
|
4
|
+
# Holds the individual data of a coverage result.
|
|
5
|
+
#
|
|
6
|
+
# This is uniform across coverage criteria as they all have:
|
|
7
|
+
#
|
|
8
|
+
# * total - how many things to cover there are (total relevant loc/branches)
|
|
9
|
+
# * covered - how many of the coverables are hit
|
|
10
|
+
# * missed - how many of the coverables are missed
|
|
11
|
+
# * percent - percentage as covered/missed
|
|
12
|
+
# * strength - average hits per/coverable (will not exist for one shot lines format)
|
|
13
|
+
class CoverageStatistics
|
|
14
|
+
attr_reader :total, :covered, :missed, :strength, :percent
|
|
15
|
+
|
|
16
|
+
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), file_coverage_statistics|
|
|
19
|
+
[
|
|
20
|
+
covered + file_coverage_statistics.covered,
|
|
21
|
+
missed + file_coverage_statistics.missed,
|
|
22
|
+
# gotta remultiply with loc because files have different strength and loc
|
|
23
|
+
# giving them a different "weight" in total
|
|
24
|
+
total_strength + (file_coverage_statistics.strength * file_coverage_statistics.total)
|
|
25
|
+
]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
new(covered: sum_covered, missed: sum_missed, total_strength: sum_total_strength)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Requires only covered, missed and strength to be initialized.
|
|
32
|
+
#
|
|
33
|
+
# Other values are computed by this class.
|
|
34
|
+
def initialize(covered:, missed:, total_strength: 0.0)
|
|
35
|
+
@covered = covered
|
|
36
|
+
@missed = missed
|
|
37
|
+
@total = covered + missed
|
|
38
|
+
@percent = compute_percent(covered, missed, total)
|
|
39
|
+
@strength = compute_strength(total_strength, total)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def compute_percent(covered, missed, total)
|
|
45
|
+
return 100.0 if missed.zero?
|
|
46
|
+
|
|
47
|
+
covered * 100.0 / total
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def compute_strength(total_strength, total)
|
|
51
|
+
return 0.0 if total.zero?
|
|
52
|
+
|
|
53
|
+
total_strength.to_f / total
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "simplecov-html"
|
|
4
|
+
module SimpleCov
|
|
5
|
+
module Formatter
|
|
6
|
+
class << self
|
|
7
|
+
def from_env(env)
|
|
8
|
+
formatters = [SimpleCov::Formatter::HTMLFormatter]
|
|
9
|
+
|
|
10
|
+
# When running under a CI that uses CodeClimate, JSON output is expected
|
|
11
|
+
if env.fetch("CC_TEST_REPORTER_ID", nil)
|
|
12
|
+
require "simplecov_json_formatter"
|
|
13
|
+
formatters.push(SimpleCov::Formatter::JSONFormatter)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
formatters
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Load default formatter gem
|
|
4
|
+
require "pathname"
|
|
5
|
+
require_relative "default_formatter"
|
|
6
|
+
require_relative "profiles/root_filter"
|
|
7
|
+
require_relative "profiles/test_frameworks"
|
|
8
|
+
require_relative "profiles/bundler_filter"
|
|
9
|
+
require_relative "profiles/hidden_filter"
|
|
10
|
+
require_relative "profiles/rails"
|
|
11
|
+
|
|
12
|
+
# Default configuration
|
|
13
|
+
SimpleCov.configure do
|
|
14
|
+
formatter SimpleCov::Formatter::MultiFormatter.new(
|
|
15
|
+
SimpleCov::Formatter.from_env(ENV)
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
load_profile "bundler_filter"
|
|
19
|
+
load_profile "hidden_filter"
|
|
20
|
+
# Exclude files outside of SimpleCov.root
|
|
21
|
+
load_profile "root_filter"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Gotta stash this a-s-a-p, see the CommandGuesser class and i.e. #110 for further info
|
|
25
|
+
SimpleCov::CommandGuesser.original_run_command = "#{$PROGRAM_NAME} #{ARGV.join(' ')}"
|
|
26
|
+
|
|
27
|
+
at_exit do
|
|
28
|
+
next if SimpleCov.external_at_exit?
|
|
29
|
+
|
|
30
|
+
SimpleCov.at_exit_behavior
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Autoload config from ~/.simplecov if present
|
|
34
|
+
require_relative "load_global_config"
|
|
35
|
+
|
|
36
|
+
# Autoload config from .simplecov if present
|
|
37
|
+
# Recurse upwards until we find .simplecov or reach the root directory
|
|
38
|
+
|
|
39
|
+
config_path = Pathname.new(SimpleCov.root)
|
|
40
|
+
loop do
|
|
41
|
+
filename = config_path.join(".simplecov")
|
|
42
|
+
if filename.exist?
|
|
43
|
+
begin
|
|
44
|
+
load filename
|
|
45
|
+
rescue LoadError, StandardError
|
|
46
|
+
warn "Warning: Error occurred while trying to load #{filename}. " \
|
|
47
|
+
"Error message: #{$!.message}"
|
|
48
|
+
end
|
|
49
|
+
break
|
|
50
|
+
end
|
|
51
|
+
config_path, = config_path.split
|
|
52
|
+
break if config_path.root?
|
|
53
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SimpleCov
|
|
4
|
+
module ExitCodes
|
|
5
|
+
module ExitCodeHandling
|
|
6
|
+
module_function
|
|
7
|
+
|
|
8
|
+
def call(result, coverage_limits:)
|
|
9
|
+
checks = coverage_checks(result, coverage_limits)
|
|
10
|
+
|
|
11
|
+
failing_check = checks.find(&:failing?)
|
|
12
|
+
if failing_check
|
|
13
|
+
failing_check.report
|
|
14
|
+
failing_check.exit_code
|
|
15
|
+
else
|
|
16
|
+
SimpleCov::ExitCodes::SUCCESS
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def coverage_checks(result, coverage_limits)
|
|
21
|
+
[
|
|
22
|
+
MinimumOverallCoverageCheck.new(result, coverage_limits.minimum_coverage),
|
|
23
|
+
MinimumCoverageByFileCheck.new(result, coverage_limits.minimum_coverage_by_file),
|
|
24
|
+
MaximumCoverageDropCheck.new(result, coverage_limits.maximum_coverage_drop)
|
|
25
|
+
]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|