simplecov 0.8.0.pre2 → 0.18.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +368 -27
- data/CODE_OF_CONDUCT.md +76 -0
- data/CONTRIBUTING.md +38 -7
- data/ISSUE_TEMPLATE.md +23 -0
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/README.md +449 -230
- data/doc/alternate-formatters.md +61 -0
- data/doc/commercial-services.md +20 -0
- data/doc/editor-integration.md +18 -0
- data/lib/simplecov.rb +294 -59
- data/lib/simplecov/combine.rb +30 -0
- data/lib/simplecov/combine/branches_combiner.rb +32 -0
- data/lib/simplecov/combine/files_combiner.rb +25 -0
- data/lib/simplecov/combine/lines_combiner.rb +43 -0
- data/lib/simplecov/combine/results_combiner.rb +60 -0
- data/lib/simplecov/command_guesser.rb +46 -40
- data/lib/simplecov/configuration.rb +346 -221
- data/lib/simplecov/defaults.rb +35 -75
- data/lib/simplecov/exit_codes.rb +9 -4
- data/lib/simplecov/file_list.rb +80 -36
- data/lib/simplecov/filter.rb +51 -3
- data/lib/simplecov/formatter.rb +4 -2
- data/lib/simplecov/formatter/multi_formatter.rb +28 -19
- data/lib/simplecov/formatter/simple_formatter.rb +21 -15
- data/lib/simplecov/last_run.rb +21 -13
- data/lib/simplecov/lines_classifier.rb +48 -0
- data/lib/simplecov/load_global_config.rb +8 -0
- data/lib/simplecov/no_defaults.rb +4 -2
- data/lib/simplecov/profiles.rb +29 -23
- 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/result.rb +39 -68
- data/lib/simplecov/result_adapter.rb +30 -0
- data/lib/simplecov/result_merger.rb +110 -60
- data/lib/simplecov/simulate_coverage.rb +29 -0
- data/lib/simplecov/source_file.rb +261 -135
- data/lib/simplecov/source_file/branch.rb +106 -0
- data/lib/simplecov/source_file/line.rb +72 -0
- data/lib/simplecov/useless_results_remover.rb +16 -0
- data/lib/simplecov/version.rb +4 -2
- metadata +48 -197
- data/.gitignore +0 -32
- data/.travis.yml +0 -28
- data/.yardopts +0 -1
- data/Appraisals +0 -8
- data/Gemfile +0 -16
- data/Rakefile +0 -32
- 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 -52
- 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/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 -31
- 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 -35
- data/features/rspec_groups_using_filter_class.feature +0 -40
- 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 -45
- data/features/step_definitions/simplecov_steps.rb +0 -66
- data/features/step_definitions/transformers.rb +0 -13
- data/features/step_definitions/web_steps.rb +0 -64
- data/features/support/env.rb +0 -44
- 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/gemfiles/multi_json_legacy.gemfile +0 -12
- data/gemfiles/multi_json_new.gemfile +0 -12
- data/lib/simplecov/jruby16_fix.rb +0 -43
- data/lib/simplecov/json.rb +0 -27
- data/lib/simplecov/merge_helpers.rb +0 -39
- data/lib/simplecov/railtie.rb +0 -7
- data/lib/simplecov/railties/tasks.rake +0 -11
- data/simplecov.gemspec +0 -30
- data/test/faked_project/Gemfile +0 -6
- data/test/faked_project/Rakefile +0 -8
- data/test/faked_project/cucumber.yml +0 -13
- data/test/faked_project/features/step_definitions/my_steps.rb +0 -23
- data/test/faked_project/features/support/env.rb +0 -12
- data/test/faked_project/features/test_stuff.feature +0 -6
- data/test/faked_project/lib/faked_project.rb +0 -11
- data/test/faked_project/lib/faked_project/framework_specific.rb +0 -18
- data/test/faked_project/lib/faked_project/meta_magic.rb +0 -24
- data/test/faked_project/lib/faked_project/some_class.rb +0 -29
- data/test/faked_project/spec/faked_spec.rb +0 -11
- data/test/faked_project/spec/meta_magic_spec.rb +0 -10
- data/test/faked_project/spec/some_class_spec.rb +0 -10
- data/test/faked_project/spec/spec_helper.rb +0 -15
- data/test/faked_project/test/faked_test.rb +0 -11
- data/test/faked_project/test/meta_magic_test.rb +0 -13
- data/test/faked_project/test/some_class_test.rb +0 -15
- data/test/faked_project/test/test_helper.rb +0 -16
- data/test/fixtures/app/controllers/sample_controller.rb +0 -10
- data/test/fixtures/app/models/user.rb +0 -10
- data/test/fixtures/deleted_source_sample.rb +0 -15
- data/test/fixtures/frameworks/rspec_bad.rb +0 -9
- data/test/fixtures/frameworks/rspec_good.rb +0 -9
- data/test/fixtures/frameworks/testunit_bad.rb +0 -9
- data/test/fixtures/frameworks/testunit_good.rb +0 -9
- data/test/fixtures/iso-8859.rb +0 -3
- data/test/fixtures/resultset1.rb +0 -4
- data/test/fixtures/resultset2.rb +0 -5
- data/test/fixtures/sample.rb +0 -16
- data/test/fixtures/utf-8.rb +0 -3
- data/test/helper.rb +0 -34
- data/test/shoulda_macros.rb +0 -19
- data/test/test_1_8_fallbacks.rb +0 -31
- data/test/test_command_guesser.rb +0 -19
- data/test/test_deleted_source.rb +0 -14
- data/test/test_file_list.rb +0 -22
- data/test/test_filters.rb +0 -78
- data/test/test_merge_helpers.rb +0 -105
- data/test/test_result.rb +0 -160
- data/test/test_return_codes.rb +0 -37
- data/test/test_source_file.rb +0 -106
- data/test/test_source_file_line.rb +0 -106
@@ -0,0 +1,61 @@
|
|
1
|
+
## Alternate coverage report formatters
|
2
|
+
|
3
|
+
The community around simplecov provides a whole bunch of alternate formatters beyond the official
|
4
|
+
[simplecov-html](https://github.com/colszowka/simplecov-html) gem.
|
5
|
+
|
6
|
+
If you have built or found one that is missing here, please send a Pull Request for this document!
|
7
|
+
|
8
|
+
#### [simplecov-badge](https://github.com/matthew342/simplecov-badge)
|
9
|
+
*by Matt Hale*
|
10
|
+
|
11
|
+
A formatter that generates a coverage badge for use in your project's readme using ImageMagick.
|
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
|
+
|
18
|
+
#### [simplecov-cobertura](https://github.com/dashingrocket/simplecov-cobertura)
|
19
|
+
*by Jesse Bowes*
|
20
|
+
|
21
|
+
A formatter that generates Cobertura XML.
|
22
|
+
|
23
|
+
#### [simplecov-csv](https://github.com/fguillen/simplecov-csv)
|
24
|
+
*by Fernando Guillen*
|
25
|
+
|
26
|
+
CSV formatter for SimpleCov
|
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
|
+
|
33
|
+
#### [simplecov-json](https://github.com/vicentllongo/simplecov-json)
|
34
|
+
*by Vicent Llongo*
|
35
|
+
|
36
|
+
JSON formatter for SimpleCov
|
37
|
+
|
38
|
+
#### [simplecov-lcov](https://github.com/fortissimo1997/simplecov-lcov)
|
39
|
+
*by fortissimo1997*
|
40
|
+
|
41
|
+
lcov formatter for SimpleCov
|
42
|
+
|
43
|
+
#### [simplecov-rcov](https://github.com/fguillen/simplecov-rcov)
|
44
|
+
*by Fernando Guillen*
|
45
|
+
|
46
|
+
"The target of this formatter is to cheat on Hudson so I can use the Ruby metrics plugin with SimpleCov."
|
47
|
+
|
48
|
+
#### [simplecov-single_file_reporter](https://github.com/grosser/simplecov-single_file_reporter)
|
49
|
+
*by [Michael Grosser](http://grosser.it)*
|
50
|
+
|
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
|
57
|
+
|
58
|
+
#### [simplecov-material(https://github.com/chiefpansancolt/simplecov-material)
|
59
|
+
*by [Chiefpansancolt](https://github.com/chiefpansancolt)*
|
60
|
+
|
61
|
+
A Material Designed HTML formatter with clean and easy search of files with a tabular left Navigation.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
## Commercial Services with SimpleCov integration
|
2
|
+
|
3
|
+
There is a bunch of services that offer integration with your existing CI pipeline and SimpleCov coverage
|
4
|
+
reports. Please note these are not associated with the SimpleCov project itself, so please report problems with
|
5
|
+
these integrations with their respective owners.
|
6
|
+
|
7
|
+
#### [codeclimate](https://github.com/codeclimate/ruby-test-reporter)
|
8
|
+
*by [Code Climate](https://codeclimate.com/)*
|
9
|
+
|
10
|
+
Upload coverage reports to [codeclimate.com](https://codeclimate.com/), a hosted software quality analysis and that also includes coverage reporting.
|
11
|
+
|
12
|
+
#### [codecov](https://github.com/codecov/codecov-ruby)
|
13
|
+
*by [Codecov](https://codecov.io/)*
|
14
|
+
|
15
|
+
Upload coverage reports to [codecov.io](https://codecov.io/), a hosted coverage reporting solution.
|
16
|
+
|
17
|
+
#### [coveralls](https://github.com/lemurheavy/coveralls-ruby)
|
18
|
+
*by [Coveralls](https://coveralls.io/)*
|
19
|
+
|
20
|
+
Upload coverage reports to [coveralls.io](https://coveralls.io/), a hosted coverage reporting solution.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
## Editor integration
|
2
|
+
|
3
|
+
Some editors have a graphical integration for the simplecov gem.
|
4
|
+
|
5
|
+
#### [Atom Editor: coverage](https://atom.io/packages/coverage)
|
6
|
+
*by Philip Giuliani*
|
7
|
+
|
8
|
+
Adds an overview of your current test coverage to Atom.
|
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
|
+
|
15
|
+
#### [cadre](https://github.com/nyarly/cadre)
|
16
|
+
*by Judson Lester*
|
17
|
+
|
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,11 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "English"
|
4
|
+
|
5
|
+
# Coverage may be inaccurate under JRUBY.
|
6
|
+
if defined?(JRUBY_VERSION) && defined?(JRuby)
|
7
|
+
|
8
|
+
# @see https://github.com/jruby/jruby/issues/1196
|
9
|
+
# @see https://github.com/metricfu/metric_fu/pull/226
|
10
|
+
# @see https://github.com/colszowka/simplecov/issues/420
|
11
|
+
# @see https://github.com/colszowka/simplecov/issues/86
|
12
|
+
# @see https://jira.codehaus.org/browse/JRUBY-6106
|
13
|
+
|
14
|
+
unless org.jruby.RubyInstanceConfig.FULL_TRACE_ENABLED
|
15
|
+
warn 'Coverage may be inaccurate; set the "--debug" command line option,' \
|
16
|
+
' or do JRUBY_OPTS="--debug"' \
|
17
|
+
' or set the "debug.fullTrace=true" option in your .jrubyrc'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
1
21
|
#
|
2
|
-
# Code coverage for ruby
|
22
|
+
# Code coverage for ruby. Please check out README for a full introduction.
|
3
23
|
#
|
4
|
-
require 'lockfile'
|
5
|
-
|
6
24
|
module SimpleCov
|
7
25
|
class << self
|
8
26
|
attr_accessor :running
|
27
|
+
attr_accessor :pid
|
28
|
+
attr_reader :exit_exception
|
9
29
|
|
10
30
|
#
|
11
31
|
# Sets up SimpleCov to run against your project.
|
@@ -24,18 +44,15 @@ module SimpleCov
|
|
24
44
|
#
|
25
45
|
# Please check out the RDoc for SimpleCov::Configuration to find about available config options
|
26
46
|
#
|
27
|
-
def start(profile=nil, &block)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
warn "Starting with SimpleCov 1.0.0, even no-op compatibility with Ruby <= 1.8 will be entirely dropped."
|
37
|
-
false
|
38
|
-
end
|
47
|
+
def start(profile = nil, &block)
|
48
|
+
require "coverage"
|
49
|
+
load_profile(profile) if profile
|
50
|
+
configure(&block) if block_given?
|
51
|
+
@result = nil
|
52
|
+
self.running = true
|
53
|
+
self.pid = Process.pid
|
54
|
+
|
55
|
+
start_coverage_measurment
|
39
56
|
end
|
40
57
|
|
41
58
|
#
|
@@ -43,19 +60,21 @@ module SimpleCov
|
|
43
60
|
# from cache using SimpleCov::ResultMerger if use_merging is activated (default)
|
44
61
|
#
|
45
62
|
def result
|
46
|
-
@result
|
63
|
+
return @result if result?
|
64
|
+
|
65
|
+
# Collect our coverage result
|
66
|
+
|
67
|
+
process_coverage_result if running
|
68
|
+
|
47
69
|
# If we're using merging of results, store the current result
|
48
|
-
# first, then merge the results and return those
|
70
|
+
# first (if there is one), then merge the results and return those
|
49
71
|
if use_merging
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
SimpleCov::ResultMerger.store_result(@result) if @result
|
54
|
-
return SimpleCov::ResultMerger.merged_result
|
55
|
-
end
|
56
|
-
else
|
57
|
-
return @result if defined? @result
|
72
|
+
wait_for_other_processes
|
73
|
+
SimpleCov::ResultMerger.store_result(@result) if result?
|
74
|
+
@result = SimpleCov::ResultMerger.merged_result
|
58
75
|
end
|
76
|
+
|
77
|
+
@result
|
59
78
|
ensure
|
60
79
|
self.running = false
|
61
80
|
end
|
@@ -65,7 +84,7 @@ module SimpleCov
|
|
65
84
|
# Otherwise, returns the result
|
66
85
|
#
|
67
86
|
def result?
|
68
|
-
defined?
|
87
|
+
defined?(@result) && @result
|
69
88
|
end
|
70
89
|
|
71
90
|
#
|
@@ -74,7 +93,7 @@ module SimpleCov
|
|
74
93
|
def filtered(files)
|
75
94
|
result = files.clone
|
76
95
|
filters.each do |filter|
|
77
|
-
result = result.reject {|source_file| filter.matches?(source_file) }
|
96
|
+
result = result.reject { |source_file| filter.matches?(source_file) }
|
78
97
|
end
|
79
98
|
SimpleCov::FileList.new result
|
80
99
|
end
|
@@ -86,10 +105,10 @@ module SimpleCov
|
|
86
105
|
grouped = {}
|
87
106
|
grouped_files = []
|
88
107
|
groups.each do |name, filter|
|
89
|
-
grouped[name] = SimpleCov::FileList.new(files.select {|source_file| filter.matches?(source_file)})
|
108
|
+
grouped[name] = SimpleCov::FileList.new(files.select { |source_file| filter.matches?(source_file) })
|
90
109
|
grouped_files += grouped[name]
|
91
110
|
end
|
92
|
-
if groups.
|
111
|
+
if !groups.empty? && !(other_files = files.reject { |source_file| grouped_files.include?(source_file) }).empty?
|
93
112
|
grouped["Ungrouped"] = SimpleCov::FileList.new(other_files)
|
94
113
|
end
|
95
114
|
grouped
|
@@ -103,47 +122,263 @@ module SimpleCov
|
|
103
122
|
end
|
104
123
|
|
105
124
|
def load_adapter(name)
|
106
|
-
warn "
|
125
|
+
warn "#{Kernel.caller.first}: [DEPRECATION] #load_adapter is deprecated. Use #load_profile instead."
|
107
126
|
load_profile(name)
|
108
127
|
end
|
109
128
|
|
110
129
|
#
|
111
|
-
#
|
112
|
-
# provides coverage support
|
130
|
+
# Clear out the previously cached .result. Primarily useful in testing
|
113
131
|
#
|
114
|
-
def
|
115
|
-
|
132
|
+
def clear_result
|
133
|
+
@result = nil
|
134
|
+
end
|
135
|
+
|
136
|
+
#
|
137
|
+
# Capture the current exception if it exists
|
138
|
+
# This will get called inside the at_exit block
|
139
|
+
#
|
140
|
+
def set_exit_exception
|
141
|
+
@exit_exception = $ERROR_INFO
|
142
|
+
end
|
116
143
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
144
|
+
#
|
145
|
+
# Returns the exit status from the exit exception
|
146
|
+
#
|
147
|
+
def exit_status_from_exception
|
148
|
+
return SimpleCov::ExitCodes::SUCCESS unless exit_exception
|
149
|
+
|
150
|
+
if exit_exception.is_a?(SystemExit)
|
151
|
+
exit_exception.status
|
152
|
+
else
|
153
|
+
SimpleCov::ExitCodes::EXCEPTION
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# @api private
|
158
|
+
#
|
159
|
+
# Called from at_exit block
|
160
|
+
#
|
161
|
+
def run_exit_tasks!
|
162
|
+
exit_status = SimpleCov.exit_status_from_exception
|
163
|
+
|
164
|
+
SimpleCov.at_exit.call
|
165
|
+
|
166
|
+
# Don't modify the exit status unless the result has already been
|
167
|
+
# computed
|
168
|
+
exit_status = SimpleCov.process_result(SimpleCov.result, exit_status) if SimpleCov.result?
|
169
|
+
|
170
|
+
# Force exit with stored status (see github issue #5)
|
171
|
+
# unless it's nil or 0 (see github issue #281)
|
172
|
+
if exit_status&.positive?
|
173
|
+
$stderr.printf("SimpleCov failed with exit %<exit_status>d\n", :exit_status => exit_status) if print_error_status
|
174
|
+
Kernel.exit exit_status
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
# @api private
|
179
|
+
#
|
180
|
+
# Usage:
|
181
|
+
# exit_status = SimpleCov.process_result(SimpleCov.result, exit_status)
|
182
|
+
#
|
183
|
+
def process_result(result, exit_status)
|
184
|
+
return exit_status if exit_status != SimpleCov::ExitCodes::SUCCESS # Existing errors
|
185
|
+
|
186
|
+
covered_percent = result.covered_percent.floor(2)
|
187
|
+
result_exit_status = result_exit_status(result, covered_percent)
|
188
|
+
write_last_run(covered_percent) if result_exit_status == SimpleCov::ExitCodes::SUCCESS # No result errors
|
189
|
+
final_result_process? ? result_exit_status : SimpleCov::ExitCodes::SUCCESS
|
190
|
+
end
|
191
|
+
|
192
|
+
# @api private
|
193
|
+
#
|
194
|
+
# rubocop:disable Metrics/MethodLength
|
195
|
+
def result_exit_status(result, covered_percent)
|
196
|
+
covered_percentages = result.covered_percentages.map { |percentage| percentage.floor(2) }
|
197
|
+
if covered_percent < SimpleCov.minimum_coverage
|
198
|
+
$stderr.printf(
|
199
|
+
"Coverage (%<covered>.2f%%) is below the expected minimum coverage (%<minimum_coverage>.2f%%).\n",
|
200
|
+
:covered => covered_percent,
|
201
|
+
:minimum_coverage => SimpleCov.minimum_coverage
|
202
|
+
)
|
203
|
+
SimpleCov::ExitCodes::MINIMUM_COVERAGE
|
204
|
+
elsif covered_percentages.any? { |p| p < SimpleCov.minimum_coverage_by_file }
|
205
|
+
$stderr.printf(
|
206
|
+
"File (%<file>s) is only (%<least_covered_percentage>.2f%%) covered. This is below the expected minimum coverage per file of (%<min_coverage>.2f%%).\n",
|
207
|
+
:file => result.least_covered_file,
|
208
|
+
:least_covered_percentage => covered_percentages.min,
|
209
|
+
:min_coverage => SimpleCov.minimum_coverage_by_file
|
210
|
+
)
|
211
|
+
SimpleCov::ExitCodes::MINIMUM_COVERAGE
|
212
|
+
elsif (last_run = SimpleCov::LastRun.read)
|
213
|
+
coverage_diff = last_run["result"]["covered_percent"] - covered_percent
|
214
|
+
if coverage_diff > SimpleCov.maximum_coverage_drop
|
215
|
+
$stderr.printf(
|
216
|
+
"Coverage has dropped by %<drop_percent>.2f%% since the last time (maximum allowed: %<max_drop>.2f%%).\n",
|
217
|
+
:drop_percent => coverage_diff,
|
218
|
+
:max_drop => SimpleCov.maximum_coverage_drop
|
219
|
+
)
|
220
|
+
SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
|
221
|
+
else
|
222
|
+
SimpleCov::ExitCodes::SUCCESS
|
223
|
+
end
|
224
|
+
else
|
225
|
+
SimpleCov::ExitCodes::SUCCESS
|
123
226
|
end
|
124
227
|
end
|
228
|
+
# rubocop:enable Metrics/MethodLength
|
229
|
+
|
230
|
+
#
|
231
|
+
# @api private
|
232
|
+
#
|
233
|
+
def final_result_process?
|
234
|
+
# checking for ENV["TEST_ENV_NUMBER"] to determine if the tess are being run in parallel
|
235
|
+
!defined?(ParallelTests) || !ENV["TEST_ENV_NUMBER"] || ParallelTests.number_of_running_processes <= 1
|
236
|
+
end
|
237
|
+
|
238
|
+
#
|
239
|
+
# @api private
|
240
|
+
#
|
241
|
+
def wait_for_other_processes
|
242
|
+
return unless defined?(ParallelTests) && final_result_process?
|
243
|
+
|
244
|
+
ParallelTests.wait_for_other_processes_to_finish
|
245
|
+
end
|
246
|
+
|
247
|
+
#
|
248
|
+
# @api private
|
249
|
+
#
|
250
|
+
def write_last_run(covered_percent)
|
251
|
+
SimpleCov::LastRun.write(:result => {:covered_percent => covered_percent})
|
252
|
+
end
|
253
|
+
|
254
|
+
private
|
255
|
+
|
256
|
+
#
|
257
|
+
# Trigger Coverage.start depends on given config coverage_criterion
|
258
|
+
#
|
259
|
+
# With Positive branch it supports all coverage measurement types
|
260
|
+
# With Negative branch it supports only line coverage measurement type
|
261
|
+
#
|
262
|
+
def start_coverage_measurment
|
263
|
+
# This blog post gives a good run down of the coverage criterias introduced
|
264
|
+
# in Ruby 2.5: https://blog.bigbinary.com/2018/04/11/ruby-2-5-supports-measuring-branch-and-method-coverages.html
|
265
|
+
# There is also a nice writeup of the different coverage criteria made in this
|
266
|
+
# comment https://github.com/colszowka/simplecov/pull/692#discussion_r281836176 :
|
267
|
+
# Ruby < 2.5:
|
268
|
+
# https://github.com/ruby/ruby/blob/v1_9_3_374/ext/coverage/coverage.c
|
269
|
+
# traditional mode (Array)
|
270
|
+
#
|
271
|
+
# Ruby 2.5:
|
272
|
+
# https://bugs.ruby-lang.org/issues/13901
|
273
|
+
# https://github.com/ruby/ruby/blob/v2_5_3/ext/coverage/coverage.c
|
274
|
+
# default: traditional/compatible mode (Array)
|
275
|
+
# :lines - like traditional mode but using Hash
|
276
|
+
# :branches
|
277
|
+
# :methods
|
278
|
+
# :all - same as lines + branches + methods
|
279
|
+
#
|
280
|
+
# Ruby >= 2.6:
|
281
|
+
# https://bugs.ruby-lang.org/issues/15022
|
282
|
+
# https://github.com/ruby/ruby/blob/v2_6_3/ext/coverage/coverage.c
|
283
|
+
# default: traditional/compatible mode (Array)
|
284
|
+
# :lines - like traditional mode but using Hash
|
285
|
+
# :branches
|
286
|
+
# :methods
|
287
|
+
# :oneshot_lines - can not be combined with lines
|
288
|
+
# :all - same as lines + branches + methods
|
289
|
+
#
|
290
|
+
if branch_coverage?
|
291
|
+
Coverage.start(:all)
|
292
|
+
else
|
293
|
+
Coverage.start
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
#
|
298
|
+
# Finds files that were to be tracked but were not loaded and initializes
|
299
|
+
# the line-by-line coverage to zero (if relevant) or nil (comments / whitespace etc).
|
300
|
+
#
|
301
|
+
def add_not_loaded_files(result)
|
302
|
+
if tracked_files
|
303
|
+
result = result.dup
|
304
|
+
Dir[tracked_files].each do |file|
|
305
|
+
absolute_path = File.expand_path(file)
|
306
|
+
result[absolute_path] ||= SimulateCoverage.call(absolute_path)
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
result
|
311
|
+
end
|
312
|
+
|
313
|
+
#
|
314
|
+
# Call steps that handle process coverage result
|
315
|
+
#
|
316
|
+
# @return [Hash]
|
317
|
+
#
|
318
|
+
def process_coverage_result
|
319
|
+
adapt_coverage_result
|
320
|
+
remove_useless_results
|
321
|
+
result_with_not_loaded_files
|
322
|
+
end
|
323
|
+
|
324
|
+
#
|
325
|
+
# Unite the result so it wouldn't matter what coverage type was called
|
326
|
+
#
|
327
|
+
# @return [Hash]
|
328
|
+
#
|
329
|
+
def adapt_coverage_result
|
330
|
+
@result = SimpleCov::ResultAdapter.call(Coverage.result)
|
331
|
+
end
|
332
|
+
|
333
|
+
#
|
334
|
+
# Filter coverage result
|
335
|
+
# The result before filter also has result of coverage for files
|
336
|
+
# are not related to the project like loaded gems coverage.
|
337
|
+
#
|
338
|
+
# @return [Hash]
|
339
|
+
#
|
340
|
+
def remove_useless_results
|
341
|
+
@result = SimpleCov::UselessResultsRemover.call(@result)
|
342
|
+
end
|
343
|
+
|
344
|
+
#
|
345
|
+
# Initialize result with files that are not included by coverage
|
346
|
+
# and added inside the config block
|
347
|
+
#
|
348
|
+
# @return [Hash]
|
349
|
+
#
|
350
|
+
def result_with_not_loaded_files
|
351
|
+
@result = SimpleCov::Result.new(add_not_loaded_files(@result))
|
352
|
+
end
|
125
353
|
end
|
126
354
|
end
|
127
355
|
|
128
356
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__)))
|
129
|
-
require
|
130
|
-
|
131
|
-
|
132
|
-
require
|
133
|
-
require
|
134
|
-
require
|
135
|
-
require
|
136
|
-
require
|
137
|
-
require
|
138
|
-
require
|
139
|
-
require
|
140
|
-
require
|
141
|
-
require
|
142
|
-
require
|
143
|
-
require
|
357
|
+
require "set"
|
358
|
+
require "simplecov/configuration"
|
359
|
+
SimpleCov.extend SimpleCov::Configuration
|
360
|
+
require "simplecov/exit_codes"
|
361
|
+
require "simplecov/profiles"
|
362
|
+
require "simplecov/source_file/line"
|
363
|
+
require "simplecov/source_file/branch"
|
364
|
+
require "simplecov/source_file"
|
365
|
+
require "simplecov/file_list"
|
366
|
+
require "simplecov/result"
|
367
|
+
require "simplecov/filter"
|
368
|
+
require "simplecov/formatter"
|
369
|
+
require "simplecov/last_run"
|
370
|
+
require "simplecov/lines_classifier"
|
371
|
+
require "simplecov/result_merger"
|
372
|
+
require "simplecov/command_guesser"
|
373
|
+
require "simplecov/version"
|
374
|
+
require "simplecov/result_adapter"
|
375
|
+
require "simplecov/combine"
|
376
|
+
require "simplecov/combine/branches_combiner"
|
377
|
+
require "simplecov/combine/files_combiner"
|
378
|
+
require "simplecov/combine/lines_combiner"
|
379
|
+
require "simplecov/combine/results_combiner"
|
380
|
+
require "simplecov/useless_results_remover"
|
381
|
+
require "simplecov/simulate_coverage"
|
144
382
|
|
145
383
|
# Load default config
|
146
|
-
require
|
147
|
-
|
148
|
-
# Load Rails integration (only for Rails 3, see #113)
|
149
|
-
require 'simplecov/railtie' if defined? Rails::Railtie
|
384
|
+
require "simplecov/defaults" unless ENV["SIMPLECOV_NO_DEFAULTS"]
|