simplecov 0.13.0 → 0.17.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +99 -3
- data/CONTRIBUTING.md +12 -9
- data/ISSUE_TEMPLATE.md +23 -0
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/README.md +90 -43
- data/doc/alternate-formatters.md +21 -1
- data/doc/editor-integration.md +6 -1
- data/lib/simplecov.rb +131 -13
- data/lib/simplecov/command_guesser.rb +2 -0
- data/lib/simplecov/configuration.rb +34 -25
- data/lib/simplecov/defaults.rb +12 -82
- data/lib/simplecov/exit_codes.rb +2 -0
- data/lib/simplecov/file_list.rb +7 -5
- data/lib/simplecov/filter.rb +41 -4
- data/lib/simplecov/formatter.rb +2 -0
- data/lib/simplecov/formatter/multi_formatter.rb +2 -0
- data/lib/simplecov/formatter/simple_formatter.rb +3 -1
- data/lib/simplecov/jruby_fix.rb +2 -0
- data/lib/simplecov/last_run.rb +5 -1
- data/lib/simplecov/lines_classifier.rb +48 -0
- data/lib/simplecov/load_global_config.rb +8 -0
- data/lib/simplecov/no_defaults.rb +2 -0
- data/lib/simplecov/profiles.rb +2 -0
- data/lib/simplecov/profiles/bundler_filter.rb +5 -0
- data/lib/simplecov/profiles/hidden_filter.rb +5 -0
- data/lib/simplecov/profiles/rails.rb +18 -0
- data/lib/simplecov/profiles/root_filter.rb +10 -0
- data/lib/simplecov/profiles/test_frameworks.rb +8 -0
- data/lib/simplecov/railtie.rb +2 -0
- data/lib/simplecov/railties/tasks.rake +2 -0
- data/lib/simplecov/raw_coverage.rb +41 -0
- data/lib/simplecov/result.rb +2 -1
- data/lib/simplecov/result_merger.rb +56 -21
- data/lib/simplecov/source_file.rb +43 -34
- data/lib/simplecov/version.rb +3 -23
- metadata +131 -99
- data/.gitignore +0 -31
- data/.rspec +0 -3
- data/.rubocop.yml +0 -84
- data/.travis.yml +0 -32
- data/.yardopts +0 -1
- data/Gemfile +0 -38
- data/Rakefile +0 -41
- data/cucumber.yml +0 -13
- data/features/config_autoload.feature +0 -46
- data/features/config_command_name.feature +0 -45
- data/features/config_coverage_dir.feature +0 -33
- data/features/config_deactivate_merging.feature +0 -42
- data/features/config_formatters.feature +0 -77
- data/features/config_merge_timeout.feature +0 -39
- data/features/config_nocov_token.feature +0 -79
- data/features/config_profiles.feature +0 -44
- data/features/config_project_name.feature +0 -27
- data/features/config_styles.feature +0 -121
- data/features/config_tracked_files.feature +0 -29
- data/features/cucumber_basic.feature +0 -29
- data/features/maximum_coverage_drop.feature +0 -36
- data/features/merging_test_unit_and_rspec.feature +0 -44
- data/features/minimum_coverage.feature +0 -59
- data/features/refuse_coverage_drop.feature +0 -35
- data/features/rspec_basic.feature +0 -32
- data/features/rspec_fails_on_initialization.feature +0 -14
- data/features/rspec_groups_and_filters_basic.feature +0 -29
- data/features/rspec_groups_and_filters_complex.feature +0 -37
- data/features/rspec_groups_using_filter_class.feature +0 -41
- data/features/rspec_without_simplecov.feature +0 -20
- data/features/skipping_code_blocks_manually.feature +0 -70
- data/features/step_definitions/html_steps.rb +0 -44
- data/features/step_definitions/simplecov_steps.rb +0 -68
- data/features/step_definitions/transformers.rb +0 -13
- data/features/step_definitions/web_steps.rb +0 -64
- data/features/support/env.rb +0 -50
- data/features/test_unit_basic.feature +0 -34
- data/features/test_unit_groups_and_filters_basic.feature +0 -29
- data/features/test_unit_groups_and_filters_complex.feature +0 -35
- data/features/test_unit_groups_using_filter_class.feature +0 -40
- data/features/test_unit_without_simplecov.feature +0 -20
- data/features/unicode_compatiblity.feature +0 -67
- data/lib/simplecov/merge_helpers.rb +0 -37
- data/simplecov.gemspec +0 -27
- data/spec/1_8_fallbacks_spec.rb +0 -31
- data/spec/command_guesser_spec.rb +0 -48
- data/spec/deleted_source_spec.rb +0 -12
- data/spec/faked_project/Gemfile +0 -6
- data/spec/faked_project/Rakefile +0 -8
- data/spec/faked_project/cucumber.yml +0 -13
- data/spec/faked_project/features/step_definitions/my_steps.rb +0 -22
- data/spec/faked_project/features/support/env.rb +0 -12
- data/spec/faked_project/features/test_stuff.feature +0 -6
- data/spec/faked_project/lib/faked_project.rb +0 -11
- data/spec/faked_project/lib/faked_project/framework_specific.rb +0 -18
- data/spec/faked_project/lib/faked_project/meta_magic.rb +0 -24
- data/spec/faked_project/lib/faked_project/some_class.rb +0 -28
- data/spec/faked_project/lib/faked_project/untested_class.rb +0 -11
- data/spec/faked_project/spec/faked_spec.rb +0 -11
- data/spec/faked_project/spec/forking_spec.rb +0 -8
- data/spec/faked_project/spec/meta_magic_spec.rb +0 -15
- data/spec/faked_project/spec/some_class_spec.rb +0 -13
- data/spec/faked_project/spec/spec_helper.rb +0 -11
- data/spec/faked_project/test/faked_test.rb +0 -11
- data/spec/faked_project/test/meta_magic_test.rb +0 -13
- data/spec/faked_project/test/some_class_test.rb +0 -15
- data/spec/faked_project/test/test_helper.rb +0 -12
- data/spec/file_list_spec.rb +0 -50
- data/spec/filters_spec.rb +0 -98
- data/spec/fixtures/app/controllers/sample_controller.rb +0 -10
- data/spec/fixtures/app/models/user.rb +0 -10
- data/spec/fixtures/deleted_source_sample.rb +0 -15
- data/spec/fixtures/frameworks/rspec_bad.rb +0 -9
- data/spec/fixtures/frameworks/rspec_good.rb +0 -9
- data/spec/fixtures/frameworks/testunit_bad.rb +0 -9
- data/spec/fixtures/frameworks/testunit_good.rb +0 -9
- data/spec/fixtures/iso-8859.rb +0 -3
- data/spec/fixtures/resultset1.rb +0 -4
- data/spec/fixtures/resultset2.rb +0 -4
- data/spec/fixtures/sample.rb +0 -16
- data/spec/fixtures/utf-8.rb +0 -3
- data/spec/helper.rb +0 -24
- data/spec/merge_helpers_spec.rb +0 -126
- data/spec/multi_formatter_spec.rb +0 -20
- data/spec/result_spec.rb +0 -209
- data/spec/return_codes_spec.rb +0 -34
- data/spec/source_file_line_spec.rb +0 -155
- data/spec/source_file_spec.rb +0 -77
data/doc/alternate-formatters.md
CHANGED
@@ -10,6 +10,11 @@ If you have built or found one that is missing here, please send a Pull Request
|
|
10
10
|
|
11
11
|
A formatter that generates a coverage badge for use in your project's readme using ImageMagick.
|
12
12
|
|
13
|
+
#### [simplecov-small-badge](https://github.com/marcgrimme/simplecov-small-badge)
|
14
|
+
*by Marc Grimme*
|
15
|
+
|
16
|
+
A formatter that generates a small coverage badge for use in your project's readme using the SVG.
|
17
|
+
|
13
18
|
#### [simplecov-cobertura](https://github.com/dashingrocket/simplecov-cobertura)
|
14
19
|
*by Jesse Bowes*
|
15
20
|
|
@@ -20,11 +25,21 @@ A formatter that generates Cobertura XML.
|
|
20
25
|
|
21
26
|
CSV formatter for SimpleCov
|
22
27
|
|
28
|
+
#### [simplecov-erb](https://github.com/kpaulisse/simplecov-erb)
|
29
|
+
*by [Kevin Paulisse](https://github.com/kpaulisse)*
|
30
|
+
|
31
|
+
Flexible formatter that generates the output from an ERB template.
|
32
|
+
|
23
33
|
#### [simplecov-json](https://github.com/vicentllongo/simplecov-json)
|
24
34
|
*by Vicent Llongo*
|
25
35
|
|
26
36
|
JSON formatter for SimpleCov
|
27
37
|
|
38
|
+
#### [simplecov-lcov](https://github.com/fortissimo1997/simplecov-lcov)
|
39
|
+
*by fortissimo1997*
|
40
|
+
|
41
|
+
lcov formatter for SimpleCov
|
42
|
+
|
28
43
|
#### [simplecov-rcov](https://github.com/fguillen/simplecov-rcov)
|
29
44
|
*by Fernando Guillen*
|
30
45
|
|
@@ -33,4 +48,9 @@ JSON formatter for SimpleCov
|
|
33
48
|
#### [simplecov-single_file_reporter](https://github.com/grosser/simplecov-single_file_reporter)
|
34
49
|
*by [Michael Grosser](http://grosser.it)*
|
35
50
|
|
36
|
-
A formatter that prints the coverage of the file under test when you run a single test file.
|
51
|
+
A formatter that prints the coverage of the file under test when you run a single test file.
|
52
|
+
|
53
|
+
#### [simplecov-t_wada](https://github.com/ysksn/simplecov-t_wada)
|
54
|
+
*by [Yosuke Kabuto](https://github.com/ysksn)*
|
55
|
+
|
56
|
+
t_wada AA formatter for SimpleCov
|
data/doc/editor-integration.md
CHANGED
@@ -7,7 +7,12 @@ Some editors have a graphical integration for the simplecov gem.
|
|
7
7
|
|
8
8
|
Adds an overview of your current test coverage to Atom.
|
9
9
|
|
10
|
+
#### [Sublime Editor: SimpleCov](https://packagecontrol.io/packages/SimpleCov)
|
11
|
+
*by sentience*
|
12
|
+
|
13
|
+
Adds in editor live coverage highlighting, status bar coverage information, and summary coverage information.
|
14
|
+
|
10
15
|
#### [cadre](https://github.com/nyarly/cadre)
|
11
16
|
*by Judson Lester*
|
12
17
|
|
13
|
-
Includes a formatter for Simplecov that emits a Vim script to mark up code files with coverage information.
|
18
|
+
Includes a formatter for Simplecov that emits a Vim script to mark up code files with coverage information.
|
data/lib/simplecov.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "English"
|
4
|
+
|
1
5
|
#
|
2
6
|
# Code coverage for ruby 1.9. Please check out README for a full introduction.
|
3
7
|
#
|
@@ -20,6 +24,7 @@ module SimpleCov
|
|
20
24
|
class << self
|
21
25
|
attr_accessor :running
|
22
26
|
attr_accessor :pid
|
27
|
+
attr_reader :exit_exception
|
23
28
|
|
24
29
|
#
|
25
30
|
# Sets up SimpleCov to run against your project.
|
@@ -55,15 +60,15 @@ module SimpleCov
|
|
55
60
|
|
56
61
|
#
|
57
62
|
# Finds files that were to be tracked but were not loaded and initializes
|
58
|
-
#
|
63
|
+
# the line-by-line coverage to zero (if relevant) or nil (comments / whitespace etc).
|
59
64
|
#
|
60
65
|
def add_not_loaded_files(result)
|
61
|
-
if
|
66
|
+
if tracked_files
|
62
67
|
result = result.dup
|
63
|
-
Dir[
|
68
|
+
Dir[tracked_files].each do |file|
|
64
69
|
absolute = File.expand_path(file)
|
65
70
|
|
66
|
-
result[absolute] ||=
|
71
|
+
result[absolute] ||= LinesClassifier.new.classify(File.foreach(absolute))
|
67
72
|
end
|
68
73
|
end
|
69
74
|
|
@@ -75,23 +80,22 @@ module SimpleCov
|
|
75
80
|
# from cache using SimpleCov::ResultMerger if use_merging is activated (default)
|
76
81
|
#
|
77
82
|
def result
|
78
|
-
|
79
|
-
@result = nil unless defined?(@result)
|
83
|
+
return @result if result?
|
80
84
|
|
81
85
|
# Collect our coverage result
|
82
|
-
if running
|
86
|
+
if running
|
83
87
|
@result = SimpleCov::Result.new add_not_loaded_files(Coverage.result)
|
84
88
|
end
|
85
89
|
|
86
90
|
# If we're using merging of results, store the current result
|
87
|
-
# first, then merge the results and return those
|
91
|
+
# first (if there is one), then merge the results and return those
|
88
92
|
if use_merging
|
93
|
+
wait_for_other_processes
|
89
94
|
SimpleCov::ResultMerger.store_result(@result) if result?
|
90
|
-
|
91
|
-
SimpleCov::ResultMerger.merged_result
|
92
|
-
else
|
93
|
-
@result
|
95
|
+
@result = SimpleCov::ResultMerger.merged_result
|
94
96
|
end
|
97
|
+
|
98
|
+
@result
|
95
99
|
ensure
|
96
100
|
self.running = false
|
97
101
|
end
|
@@ -158,6 +162,119 @@ module SimpleCov
|
|
158
162
|
false
|
159
163
|
end
|
160
164
|
end
|
165
|
+
|
166
|
+
#
|
167
|
+
# Clear out the previously cached .result. Primarily useful in testing
|
168
|
+
#
|
169
|
+
def clear_result
|
170
|
+
@result = nil
|
171
|
+
end
|
172
|
+
|
173
|
+
#
|
174
|
+
# Capture the current exception if it exists
|
175
|
+
# This will get called inside the at_exit block
|
176
|
+
#
|
177
|
+
def set_exit_exception
|
178
|
+
@exit_exception = $ERROR_INFO
|
179
|
+
end
|
180
|
+
|
181
|
+
#
|
182
|
+
# Returns the exit status from the exit exception
|
183
|
+
#
|
184
|
+
def exit_status_from_exception
|
185
|
+
return SimpleCov::ExitCodes::SUCCESS unless exit_exception
|
186
|
+
|
187
|
+
if exit_exception.is_a?(SystemExit)
|
188
|
+
exit_exception.status
|
189
|
+
else
|
190
|
+
SimpleCov::ExitCodes::EXCEPTION
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
# @api private
|
195
|
+
#
|
196
|
+
# Called from at_exit block
|
197
|
+
#
|
198
|
+
def run_exit_tasks!
|
199
|
+
exit_status = SimpleCov.exit_status_from_exception
|
200
|
+
|
201
|
+
SimpleCov.at_exit.call
|
202
|
+
|
203
|
+
# Don't modify the exit status unless the result has already been
|
204
|
+
# computed
|
205
|
+
exit_status = SimpleCov.process_result(SimpleCov.result, exit_status) if SimpleCov.result?
|
206
|
+
|
207
|
+
# Force exit with stored status (see github issue #5)
|
208
|
+
# unless it's nil or 0 (see github issue #281)
|
209
|
+
if exit_status && exit_status > 0
|
210
|
+
$stderr.printf("SimpleCov failed with exit %d", exit_status)
|
211
|
+
Kernel.exit exit_status
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
# @api private
|
216
|
+
#
|
217
|
+
# Usage:
|
218
|
+
# exit_status = SimpleCov.process_result(SimpleCov.result, exit_status)
|
219
|
+
#
|
220
|
+
def process_result(result, exit_status)
|
221
|
+
return exit_status if exit_status != SimpleCov::ExitCodes::SUCCESS # Existing errors
|
222
|
+
|
223
|
+
covered_percent = result.covered_percent.round(2)
|
224
|
+
result_exit_status = result_exit_status(result, covered_percent)
|
225
|
+
if result_exit_status == SimpleCov::ExitCodes::SUCCESS # No result errors
|
226
|
+
write_last_run(covered_percent)
|
227
|
+
end
|
228
|
+
final_result_process? ? result_exit_status : SimpleCov::ExitCodes::SUCCESS
|
229
|
+
end
|
230
|
+
|
231
|
+
# @api private
|
232
|
+
#
|
233
|
+
# rubocop:disable Metrics/MethodLength
|
234
|
+
def result_exit_status(result, covered_percent)
|
235
|
+
covered_percentages = result.covered_percentages.map { |percentage| percentage.round(2) }
|
236
|
+
if covered_percent < SimpleCov.minimum_coverage
|
237
|
+
$stderr.printf("Coverage (%.2f%%) is below the expected minimum coverage (%.2f%%).\n", covered_percent, SimpleCov.minimum_coverage)
|
238
|
+
SimpleCov::ExitCodes::MINIMUM_COVERAGE
|
239
|
+
elsif covered_percentages.any? { |p| p < SimpleCov.minimum_coverage_by_file }
|
240
|
+
$stderr.printf("File (%s) is only (%.2f%%) covered. This is below the expected minimum coverage per file of (%.2f%%).\n", result.least_covered_file, covered_percentages.min, SimpleCov.minimum_coverage_by_file)
|
241
|
+
SimpleCov::ExitCodes::MINIMUM_COVERAGE
|
242
|
+
elsif (last_run = SimpleCov::LastRun.read)
|
243
|
+
coverage_diff = last_run["result"]["covered_percent"] - covered_percent
|
244
|
+
if coverage_diff > SimpleCov.maximum_coverage_drop
|
245
|
+
$stderr.printf("Coverage has dropped by %.2f%% since the last time (maximum allowed: %.2f%%).\n", coverage_diff, SimpleCov.maximum_coverage_drop)
|
246
|
+
SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
|
247
|
+
else
|
248
|
+
SimpleCov::ExitCodes::SUCCESS
|
249
|
+
end
|
250
|
+
else
|
251
|
+
SimpleCov::ExitCodes::SUCCESS
|
252
|
+
end
|
253
|
+
end
|
254
|
+
# rubocop:enable Metrics/MethodLength
|
255
|
+
|
256
|
+
#
|
257
|
+
# @api private
|
258
|
+
#
|
259
|
+
def final_result_process?
|
260
|
+
# checking for ENV["TEST_ENV_NUMBER"] to determine if the tess are being run in parallel
|
261
|
+
!defined?(ParallelTests) || !ENV["TEST_ENV_NUMBER"] || ParallelTests.number_of_running_processes <= 1
|
262
|
+
end
|
263
|
+
|
264
|
+
#
|
265
|
+
# @api private
|
266
|
+
#
|
267
|
+
def wait_for_other_processes
|
268
|
+
return unless defined?(ParallelTests) && final_result_process?
|
269
|
+
ParallelTests.wait_for_other_processes_to_finish
|
270
|
+
end
|
271
|
+
|
272
|
+
#
|
273
|
+
# @api private
|
274
|
+
#
|
275
|
+
def write_last_run(covered_percent)
|
276
|
+
SimpleCov::LastRun.write(:result => {:covered_percent => covered_percent})
|
277
|
+
end
|
161
278
|
end
|
162
279
|
end
|
163
280
|
|
@@ -172,7 +289,8 @@ require "simplecov/result"
|
|
172
289
|
require "simplecov/filter"
|
173
290
|
require "simplecov/formatter"
|
174
291
|
require "simplecov/last_run"
|
175
|
-
require "simplecov/
|
292
|
+
require "simplecov/lines_classifier"
|
293
|
+
require "simplecov/raw_coverage"
|
176
294
|
require "simplecov/result_merger"
|
177
295
|
require "simplecov/command_guesser"
|
178
296
|
require "simplecov/version"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "fileutils"
|
2
4
|
require "docile"
|
3
5
|
require "simplecov/formatter/multi_formatter"
|
@@ -50,9 +52,16 @@ module SimpleCov
|
|
50
52
|
# or not they were explicitly required. Without this, un-required files
|
51
53
|
# will not be present in the final report.
|
52
54
|
#
|
53
|
-
def track_files(glob
|
54
|
-
|
55
|
-
|
55
|
+
def track_files(glob)
|
56
|
+
@tracked_files = glob
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# Returns the glob that will be used to include files that were not
|
61
|
+
# explicitly required.
|
62
|
+
#
|
63
|
+
def tracked_files
|
64
|
+
@tracked_files if defined?(@tracked_files)
|
56
65
|
end
|
57
66
|
|
58
67
|
#
|
@@ -143,9 +152,9 @@ module SimpleCov
|
|
143
152
|
# Allows you to configure simplecov in a block instead of prepending SimpleCov to all config methods
|
144
153
|
# you're calling.
|
145
154
|
#
|
146
|
-
#
|
147
|
-
#
|
148
|
-
#
|
155
|
+
# SimpleCov.configure do
|
156
|
+
# add_filter 'foobar'
|
157
|
+
# end
|
149
158
|
#
|
150
159
|
# This is equivalent to SimpleCov.add_filter 'foobar' and thus makes it easier to set a bunch of configure
|
151
160
|
# options at once.
|
@@ -161,10 +170,11 @@ module SimpleCov
|
|
161
170
|
# By default, it will call SimpleCov.result.format!
|
162
171
|
#
|
163
172
|
# Configure with:
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
173
|
+
#
|
174
|
+
# SimpleCov.at_exit do
|
175
|
+
# puts "Coverage done"
|
176
|
+
# SimpleCov.result.format!
|
177
|
+
# end
|
168
178
|
#
|
169
179
|
def at_exit(&block)
|
170
180
|
return proc {} unless running || block_given?
|
@@ -249,15 +259,18 @@ module SimpleCov
|
|
249
259
|
|
250
260
|
#
|
251
261
|
# Add a filter to the processing chain.
|
252
|
-
# There are
|
262
|
+
# There are four ways to define a filter:
|
253
263
|
#
|
254
264
|
# * as a String that will then be matched against all source files' file paths,
|
255
|
-
#
|
265
|
+
# SimpleCov.add_filter 'app/models' # will reject all your models
|
256
266
|
# * as a block which will be passed the source file in question and should either
|
257
267
|
# return a true or false value, depending on whether the file should be removed
|
258
|
-
#
|
259
|
-
#
|
260
|
-
#
|
268
|
+
# SimpleCov.add_filter do |src_file|
|
269
|
+
# File.basename(src_file.filename) == 'environment.rb'
|
270
|
+
# end # Will exclude environment.rb files from the results
|
271
|
+
# * as an array of strings that are matched against all sorce files' file
|
272
|
+
# paths and then ignored (basically string filter multiple times)
|
273
|
+
# SimpleCov.add_filter ['app/models', 'app/helpers'] # ignores both dirs
|
261
274
|
# * as an instance of a subclass of SimpleCov::Filter. See the documentation there
|
262
275
|
# on how to define your own filter classes
|
263
276
|
#
|
@@ -277,19 +290,15 @@ module SimpleCov
|
|
277
290
|
private
|
278
291
|
|
279
292
|
#
|
280
|
-
# The
|
293
|
+
# The actual filter processor. Not meant for direct use
|
281
294
|
#
|
282
295
|
def parse_filter(filter_argument = nil, &filter_proc)
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
SimpleCov::
|
287
|
-
elsif filter_proc
|
288
|
-
SimpleCov::BlockFilter.new(filter_proc)
|
289
|
-
elsif filter_argument.is_a?(Array)
|
290
|
-
SimpleCov::ArrayFilter.new(filter_argument)
|
296
|
+
filter = filter_argument || filter_proc
|
297
|
+
|
298
|
+
if filter
|
299
|
+
SimpleCov::Filter.build_filter(filter)
|
291
300
|
else
|
292
|
-
raise ArgumentError, "Please specify either a
|
301
|
+
raise ArgumentError, "Please specify either a filter or a block to filter with"
|
293
302
|
end
|
294
303
|
end
|
295
304
|
end
|
data/lib/simplecov/defaults.rb
CHANGED
@@ -1,47 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Load default formatter gem
|
2
4
|
require "simplecov-html"
|
3
5
|
require "pathname"
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
root_filter ||= /\A#{Regexp.escape(SimpleCov.root)}/io
|
10
|
-
!(src.filename =~ root_filter)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
SimpleCov.profiles.define "test_frameworks" do
|
15
|
-
add_filter "/test/"
|
16
|
-
add_filter "/features/"
|
17
|
-
add_filter "/spec/"
|
18
|
-
add_filter "/autotest/"
|
19
|
-
end
|
20
|
-
|
21
|
-
SimpleCov.profiles.define "bundler_filter" do
|
22
|
-
add_filter "/vendor/bundle/"
|
23
|
-
end
|
24
|
-
|
25
|
-
SimpleCov.profiles.define "rails" do
|
26
|
-
load_profile "test_frameworks"
|
27
|
-
|
28
|
-
add_filter "/config/"
|
29
|
-
add_filter "/db/"
|
30
|
-
|
31
|
-
add_group "Controllers", "app/controllers"
|
32
|
-
add_group "Models", "app/models"
|
33
|
-
add_group "Mailers", "app/mailers"
|
34
|
-
add_group "Helpers", "app/helpers"
|
35
|
-
add_group "Jobs", %w(app/jobs app/workers)
|
36
|
-
add_group "Libraries", "lib"
|
37
|
-
|
38
|
-
track_files "{app,lib}/**/*.rb"
|
39
|
-
end
|
6
|
+
require "simplecov/profiles/root_filter"
|
7
|
+
require "simplecov/profiles/test_frameworks"
|
8
|
+
require "simplecov/profiles/bundler_filter"
|
9
|
+
require "simplecov/profiles/hidden_filter"
|
10
|
+
require "simplecov/profiles/rails"
|
40
11
|
|
41
12
|
# Default configuration
|
42
13
|
SimpleCov.configure do
|
43
14
|
formatter SimpleCov::Formatter::HTMLFormatter
|
44
15
|
load_profile "bundler_filter"
|
16
|
+
load_profile "hidden_filter"
|
45
17
|
# Exclude files outside of SimpleCov.root
|
46
18
|
load_profile "root_filter"
|
47
19
|
end
|
@@ -49,58 +21,16 @@ end
|
|
49
21
|
# Gotta stash this a-s-a-p, see the CommandGuesser class and i.e. #110 for further info
|
50
22
|
SimpleCov::CommandGuesser.original_run_command = "#{$PROGRAM_NAME} #{ARGV.join(' ')}"
|
51
23
|
|
52
|
-
at_exit do
|
24
|
+
at_exit do
|
53
25
|
# If we are in a different process than called start, don't interfere.
|
54
26
|
next if SimpleCov.pid != Process.pid
|
55
27
|
|
56
|
-
|
57
|
-
|
58
|
-
# otherwise set a non-zero status representing termination by
|
59
|
-
# some other exception (see github issue 41)
|
60
|
-
$!.is_a?(SystemExit) ? $!.status : SimpleCov::ExitCodes::EXCEPTION
|
61
|
-
else
|
62
|
-
# Store the exit status of the test run since it goes away
|
63
|
-
# after calling the at_exit proc...
|
64
|
-
SimpleCov::ExitCodes::SUCCESS
|
65
|
-
end
|
66
|
-
|
67
|
-
SimpleCov.at_exit.call
|
68
|
-
|
69
|
-
if SimpleCov.result? # Result has been computed
|
70
|
-
covered_percent = SimpleCov.result.covered_percent.round(2)
|
71
|
-
covered_percentages = SimpleCov.result.covered_percentages.map { |p| p.round(2) }
|
72
|
-
|
73
|
-
if @exit_status == SimpleCov::ExitCodes::SUCCESS # No other errors
|
74
|
-
if covered_percent < SimpleCov.minimum_coverage # rubocop:disable Metrics/BlockNesting
|
75
|
-
$stderr.printf("Coverage (%.2f%%) is below the expected minimum coverage (%.2f%%).\n", covered_percent, SimpleCov.minimum_coverage)
|
76
|
-
@exit_status = SimpleCov::ExitCodes::MINIMUM_COVERAGE
|
77
|
-
elsif covered_percentages.any? { |p| p < SimpleCov.minimum_coverage_by_file } # rubocop:disable Metrics/BlockNesting
|
78
|
-
$stderr.printf("File (%s) is only (%.2f%%) covered. This is below the expected minimum coverage per file of (%.2f%%).\n", SimpleCov.result.least_covered_file, covered_percentages.min, SimpleCov.minimum_coverage_by_file)
|
79
|
-
@exit_status = SimpleCov::ExitCodes::MINIMUM_COVERAGE
|
80
|
-
elsif (last_run = SimpleCov::LastRun.read) # rubocop:disable Metrics/BlockNesting
|
81
|
-
diff = last_run["result"]["covered_percent"] - covered_percent
|
82
|
-
if diff > SimpleCov.maximum_coverage_drop # rubocop:disable Metrics/BlockNesting
|
83
|
-
$stderr.printf("Coverage has dropped by %.2f%% since the last time (maximum allowed: %.2f%%).\n", diff, SimpleCov.maximum_coverage_drop)
|
84
|
-
@exit_status = SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
SimpleCov::LastRun.write(:result => {:covered_percent => covered_percent})
|
90
|
-
end
|
91
|
-
|
92
|
-
# Force exit with stored status (see github issue #5)
|
93
|
-
# unless it's nil or 0 (see github issue #281)
|
94
|
-
Kernel.exit @exit_status if @exit_status && @exit_status > 0
|
28
|
+
SimpleCov.set_exit_exception
|
29
|
+
SimpleCov.run_exit_tasks!
|
95
30
|
end
|
96
31
|
|
97
32
|
# Autoload config from ~/.simplecov if present
|
98
|
-
require "
|
99
|
-
home_dir = File.expand_path("~") || Etc.getpwuid.dir || (ENV["USER"] && File.expand_path("~#{ENV['USER']}"))
|
100
|
-
if home_dir
|
101
|
-
global_config_path = File.join(home_dir, ".simplecov")
|
102
|
-
load global_config_path if File.exist?(global_config_path)
|
103
|
-
end
|
33
|
+
require "simplecov/load_global_config"
|
104
34
|
|
105
35
|
# Autoload config from .simplecov if present
|
106
36
|
# Recurse upwards until we find .simplecov or reach the root directory
|