simplecov 0.6.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +163 -80
  3. data/LICENSE +1 -1
  4. data/README.md +776 -277
  5. data/doc/alternate-formatters.md +71 -0
  6. data/doc/commercial-services.md +25 -0
  7. data/doc/editor-integration.md +18 -0
  8. data/lib/minitest/simplecov_plugin.rb +15 -0
  9. data/lib/simplecov/combine/branches_combiner.rb +32 -0
  10. data/lib/simplecov/combine/files_combiner.rb +24 -0
  11. data/lib/simplecov/combine/lines_combiner.rb +43 -0
  12. data/lib/simplecov/combine/results_combiner.rb +60 -0
  13. data/lib/simplecov/combine.rb +30 -0
  14. data/lib/simplecov/command_guesser.rb +53 -38
  15. data/lib/simplecov/configuration.rb +478 -193
  16. data/lib/simplecov/coverage_statistics.rb +56 -0
  17. data/lib/simplecov/default_formatter.rb +20 -0
  18. data/lib/simplecov/defaults.rb +40 -44
  19. data/lib/simplecov/exit_codes/exit_code_handling.rb +29 -0
  20. data/lib/simplecov/exit_codes/maximum_coverage_drop_check.rb +83 -0
  21. data/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb +54 -0
  22. data/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb +53 -0
  23. data/lib/simplecov/exit_codes.rb +15 -0
  24. data/lib/simplecov/file_list.rb +112 -36
  25. data/lib/simplecov/filter.rb +54 -4
  26. data/lib/simplecov/formatter/multi_formatter.rb +32 -0
  27. data/lib/simplecov/formatter/simple_formatter.rb +21 -15
  28. data/lib/simplecov/formatter.rb +4 -1
  29. data/lib/simplecov/last_run.rb +28 -0
  30. data/lib/simplecov/lines_classifier.rb +48 -0
  31. data/lib/simplecov/load_global_config.rb +8 -0
  32. data/lib/simplecov/no_defaults.rb +4 -0
  33. data/lib/simplecov/process.rb +19 -0
  34. data/lib/simplecov/profiles/bundler_filter.rb +5 -0
  35. data/lib/simplecov/profiles/hidden_filter.rb +5 -0
  36. data/lib/simplecov/profiles/rails.rb +18 -0
  37. data/lib/simplecov/profiles/root_filter.rb +10 -0
  38. data/lib/simplecov/profiles/test_frameworks.rb +8 -0
  39. data/lib/simplecov/profiles.rb +35 -0
  40. data/lib/simplecov/result.rb +33 -64
  41. data/lib/simplecov/result_adapter.rb +30 -0
  42. data/lib/simplecov/result_merger.rb +178 -64
  43. data/lib/simplecov/simulate_coverage.rb +29 -0
  44. data/lib/simplecov/source_file/branch.rb +84 -0
  45. data/lib/simplecov/source_file/line.rb +72 -0
  46. data/lib/simplecov/source_file.rb +304 -123
  47. data/lib/simplecov/useless_results_remover.rb +18 -0
  48. data/lib/simplecov/version.rb +4 -2
  49. data/lib/simplecov.rb +396 -49
  50. metadata +81 -242
  51. data/.gitignore +0 -30
  52. data/.rvmrc +0 -1
  53. data/.travis.yml +0 -13
  54. data/Gemfile +0 -9
  55. data/Rakefile +0 -16
  56. data/cucumber.yml +0 -13
  57. data/features/config_adapters.feature +0 -44
  58. data/features/config_autoload.feature +0 -46
  59. data/features/config_command_name.feature +0 -33
  60. data/features/config_coverage_dir.feature +0 -20
  61. data/features/config_deactivate_merging.feature +0 -42
  62. data/features/config_merge_timeout.feature +0 -38
  63. data/features/config_nocov_token.feature +0 -79
  64. data/features/config_project_name.feature +0 -27
  65. data/features/config_styles.feature +0 -93
  66. data/features/cucumber_basic.feature +0 -29
  67. data/features/merging_test_unit_and_rspec.feature +0 -44
  68. data/features/rspec_basic.feature +0 -31
  69. data/features/rspec_fails_on_initialization.feature +0 -14
  70. data/features/rspec_groups_and_filters_basic.feature +0 -29
  71. data/features/rspec_groups_and_filters_complex.feature +0 -35
  72. data/features/rspec_groups_using_filter_class.feature +0 -40
  73. data/features/rspec_without_simplecov.feature +0 -20
  74. data/features/skipping_code_blocks_manually.feature +0 -70
  75. data/features/step_definitions/html_steps.rb +0 -45
  76. data/features/step_definitions/simplecov_steps.rb +0 -61
  77. data/features/step_definitions/transformers.rb +0 -13
  78. data/features/step_definitions/web_steps.rb +0 -64
  79. data/features/support/env.rb +0 -26
  80. data/features/test_unit_basic.feature +0 -34
  81. data/features/test_unit_groups_and_filters_basic.feature +0 -29
  82. data/features/test_unit_groups_and_filters_complex.feature +0 -35
  83. data/features/test_unit_groups_using_filter_class.feature +0 -40
  84. data/features/test_unit_without_simplecov.feature +0 -20
  85. data/features/unicode_compatiblity.feature +0 -67
  86. data/lib/simplecov/adapters.rb +0 -29
  87. data/lib/simplecov/merge_helpers.rb +0 -39
  88. data/lib/simplecov/railtie.rb +0 -7
  89. data/lib/simplecov/railties/tasks.rake +0 -11
  90. data/simplecov.gemspec +0 -28
  91. data/test/faked_project/Gemfile +0 -6
  92. data/test/faked_project/Rakefile +0 -8
  93. data/test/faked_project/cucumber.yml +0 -13
  94. data/test/faked_project/features/step_definitions/my_steps.rb +0 -23
  95. data/test/faked_project/features/support/env.rb +0 -12
  96. data/test/faked_project/features/test_stuff.feature +0 -6
  97. data/test/faked_project/lib/faked_project/framework_specific.rb +0 -18
  98. data/test/faked_project/lib/faked_project/meta_magic.rb +0 -24
  99. data/test/faked_project/lib/faked_project/some_class.rb +0 -29
  100. data/test/faked_project/lib/faked_project.rb +0 -11
  101. data/test/faked_project/spec/faked_spec.rb +0 -11
  102. data/test/faked_project/spec/meta_magic_spec.rb +0 -10
  103. data/test/faked_project/spec/some_class_spec.rb +0 -10
  104. data/test/faked_project/spec/spec_helper.rb +0 -15
  105. data/test/faked_project/test/faked_test.rb +0 -11
  106. data/test/faked_project/test/meta_magic_test.rb +0 -13
  107. data/test/faked_project/test/some_class_test.rb +0 -15
  108. data/test/faked_project/test/test_helper.rb +0 -16
  109. data/test/fixtures/app/controllers/sample_controller.rb +0 -10
  110. data/test/fixtures/app/models/user.rb +0 -10
  111. data/test/fixtures/deleted_source_sample.rb +0 -15
  112. data/test/fixtures/frameworks/rspec_bad.rb +0 -9
  113. data/test/fixtures/frameworks/rspec_good.rb +0 -9
  114. data/test/fixtures/frameworks/testunit_bad.rb +0 -9
  115. data/test/fixtures/frameworks/testunit_good.rb +0 -9
  116. data/test/fixtures/resultset1.rb +0 -4
  117. data/test/fixtures/resultset2.rb +0 -5
  118. data/test/fixtures/sample.rb +0 -16
  119. data/test/fixtures/utf-8.rb +0 -3
  120. data/test/helper.rb +0 -35
  121. data/test/shoulda_macros.rb +0 -29
  122. data/test/test_1_8_fallbacks.rb +0 -33
  123. data/test/test_command_guesser.rb +0 -21
  124. data/test/test_deleted_source.rb +0 -16
  125. data/test/test_file_list.rb +0 -24
  126. data/test/test_filters.rb +0 -80
  127. data/test/test_merge_helpers.rb +0 -107
  128. data/test/test_result.rb +0 -147
  129. data/test/test_return_codes.rb +0 -39
  130. data/test/test_source_file.rb +0 -86
  131. data/test/test_source_file_line.rb +0 -110
data/lib/simplecov.rb CHANGED
@@ -1,19 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "English"
4
+
5
+ # Coverage may be inaccurate under JRUBY.
6
+ if defined?(JRUBY_VERSION) && defined?(JRuby) && !org.jruby.RubyInstanceConfig.FULL_TRACE_ENABLED
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/simplecov-ruby/simplecov/issues/420
11
+ # @see https://github.com/simplecov-ruby/simplecov/issues/86
12
+ # @see https://jira.codehaus.org/browse/JRUBY-6106
13
+
14
+ warn 'Coverage may be inaccurate; set the "--debug" command line option,' \
15
+ ' or do JRUBY_OPTS="--debug"' \
16
+ ' or set the "debug.fullTrace=true" option in your .jrubyrc'
17
+ end
18
+
1
19
  #
2
- # Code coverage for ruby 1.9. Please check out README for a full introduction.
20
+ # Code coverage for ruby. Please check out README for a full introduction.
3
21
  #
4
22
  module SimpleCov
5
- # Indicates invalid coverage data
6
- class CoverageDataError < StandardError; end;
7
-
8
23
  class << self
9
- attr_accessor :running#, :result # TODO: Remove result?
24
+ attr_accessor :running, :pid
25
+
26
+ # Basically, should we take care of at_exit behavior or something else?
27
+ # Used by the minitest plugin. See lib/minitest/simplecov_plugin.rb
28
+ attr_accessor :external_at_exit
29
+ alias external_at_exit? external_at_exit
10
30
 
11
31
  #
12
32
  # Sets up SimpleCov to run against your project.
13
- # You can optionally specify an adapter to use as well as configuration with a block:
33
+ # You can optionally specify a profile to use as well as configuration with a block:
14
34
  # SimpleCov.start
15
35
  # OR
16
- # SimpleCov.start 'rails' # using rails adapter
36
+ # SimpleCov.start 'rails' # using rails profile
17
37
  # OR
18
38
  # SimpleCov.start do
19
39
  # add_filter 'test'
@@ -25,15 +45,53 @@ module SimpleCov
25
45
  #
26
46
  # Please check out the RDoc for SimpleCov::Configuration to find about available config options
27
47
  #
28
- def start(adapter=nil, &block)
29
- return false unless SimpleCov.usable?
48
+ def start(profile = nil, &block)
49
+ require "coverage"
50
+ initial_setup(profile, &block)
51
+ require_relative "./simplecov/process" if SimpleCov.enabled_for_subprocesses? &&
52
+ ::Process.respond_to?(:fork)
53
+
54
+ make_parallel_tests_available
30
55
 
31
- require 'coverage'
32
- load_adapter(adapter) unless adapter.nil?
33
- Coverage.start
34
- configure(&block) if block_given?
35
56
  @result = nil
36
- self.running = true
57
+ self.pid = Process.pid
58
+
59
+ start_coverage_measurement
60
+ end
61
+
62
+ #
63
+ # Collate a series of SimpleCov result files into a single SimpleCov output.
64
+ #
65
+ # You can optionally specify configuration with a block:
66
+ # SimpleCov.collate Dir["simplecov-resultset-*/.resultset.json"]
67
+ # OR
68
+ # SimpleCov.collate Dir["simplecov-resultset-*/.resultset.json"], 'rails' # using rails profile
69
+ # OR
70
+ # SimpleCov.collate Dir["simplecov-resultset-*/.resultset.json"] do
71
+ # add_filter 'test'
72
+ # end
73
+ # OR
74
+ # SimpleCov.collate Dir["simplecov-resultset-*/.resultset.json"], 'rails' do
75
+ # add_filter 'test'
76
+ # end
77
+ #
78
+ # Please check out the RDoc for SimpleCov::Configuration to find about
79
+ # available config options, or checkout the README for more in-depth
80
+ # information about coverage collation
81
+ #
82
+ # By default `collate` ignores the merge_timeout so all results of all files specified will be
83
+ # merged together. If you want to honor the merge_timeout then provide the keyword argument
84
+ # `ignore_timeout: false`.
85
+ #
86
+ def collate(result_filenames, profile = nil, ignore_timeout: true, &block)
87
+ raise "There are no reports to be merged" if result_filenames.empty?
88
+
89
+ initial_setup(profile, &block)
90
+
91
+ # Use the ResultMerger to produce a single, merged result, ready to use.
92
+ @result = ResultMerger.merge_and_store(*result_filenames, ignore_timeout: ignore_timeout)
93
+
94
+ run_exit_tasks!
37
95
  end
38
96
 
39
97
  #
@@ -41,26 +99,39 @@ module SimpleCov
41
99
  # from cache using SimpleCov::ResultMerger if use_merging is activated (default)
42
100
  #
43
101
  def result
44
- @result ||= SimpleCov::Result.new(Coverage.result) if running
102
+ return @result if result?
103
+
104
+ # Collect our coverage result
105
+ process_coverage_result if running
106
+
45
107
  # If we're using merging of results, store the current result
46
- # first, then merge the results and return those
108
+ # first (if there is one), then merge the results and return those
47
109
  if use_merging
48
- SimpleCov::ResultMerger.store_result(@result) if @result
49
- return SimpleCov::ResultMerger.merged_result
50
- else
51
- return @result
110
+ wait_for_other_processes
111
+ SimpleCov::ResultMerger.store_result(@result) if result?
112
+ @result = SimpleCov::ResultMerger.merged_result
52
113
  end
114
+
115
+ @result
53
116
  ensure
54
117
  self.running = false
55
118
  end
56
119
 
120
+ #
121
+ # Returns nil if the result has not been computed
122
+ # Otherwise, returns the result
123
+ #
124
+ def result?
125
+ defined?(@result) && @result
126
+ end
127
+
57
128
  #
58
129
  # Applies the configured filters to the given array of SimpleCov::SourceFile items
59
130
  #
60
131
  def filtered(files)
61
132
  result = files.clone
62
133
  filters.each do |filter|
63
- result = result.reject {|source_file| filter.matches?(source_file) }
134
+ result = result.reject { |source_file| filter.matches?(source_file) }
64
135
  end
65
136
  SimpleCov::FileList.new result
66
137
  end
@@ -72,52 +143,328 @@ module SimpleCov
72
143
  grouped = {}
73
144
  grouped_files = []
74
145
  groups.each do |name, filter|
75
- grouped[name] = SimpleCov::FileList.new(files.select {|source_file| filter.matches?(source_file)})
146
+ grouped[name] = SimpleCov::FileList.new(files.select { |source_file| filter.matches?(source_file) })
76
147
  grouped_files += grouped[name]
77
148
  end
78
- if groups.length > 0 and (other_files = files.reject {|source_file| grouped_files.include?(source_file)}).length > 0
149
+ if !groups.empty? && !(other_files = files.reject { |source_file| grouped_files.include?(source_file) }).empty?
79
150
  grouped["Ungrouped"] = SimpleCov::FileList.new(other_files)
80
151
  end
81
152
  grouped
82
153
  end
83
154
 
84
155
  #
85
- # Applies the adapter of given name on SimpleCov configuration
156
+ # Applies the profile of given name on SimpleCov configuration
86
157
  #
158
+ def load_profile(name)
159
+ profiles.load(name)
160
+ end
161
+
87
162
  def load_adapter(name)
88
- adapters.load(name)
163
+ warn "#{Kernel.caller.first}: [DEPRECATION] #load_adapter is deprecated. Use #load_profile instead."
164
+ load_profile(name)
165
+ end
166
+
167
+ #
168
+ # Clear out the previously cached .result. Primarily useful in testing
169
+ #
170
+ def clear_result
171
+ @result = nil
172
+ end
173
+
174
+ def at_exit_behavior
175
+ # If we are in a different process than called start, don't interfere.
176
+ return if SimpleCov.pid != Process.pid
177
+
178
+ # If SimpleCov is no longer running then don't run exit tasks
179
+ SimpleCov.run_exit_tasks! if SimpleCov.running
180
+ end
181
+
182
+ # @api private
183
+ #
184
+ # Called from at_exit block
185
+ #
186
+ def run_exit_tasks!
187
+ error_exit_status = exit_status_from_exception
188
+
189
+ at_exit.call
190
+
191
+ exit_and_report_previous_error(error_exit_status) if previous_error?(error_exit_status)
192
+ process_results_and_report_error if ready_to_process_results?
193
+ end
194
+
195
+ #
196
+ # @api private
197
+ #
198
+ # Returns the exit status from the exit exception
199
+ #
200
+ def exit_status_from_exception
201
+ # Capture the current exception if it exists
202
+ @exit_exception = $ERROR_INFO
203
+ return nil unless @exit_exception
204
+
205
+ if @exit_exception.is_a?(SystemExit)
206
+ @exit_exception.status
207
+ else
208
+ SimpleCov::ExitCodes::EXCEPTION
209
+ end
210
+ end
211
+
212
+ # @api private
213
+ def previous_error?(error_exit_status)
214
+ # Normally it'd be enough to check for previous error but when running test_unit
215
+ # status is 0
216
+ error_exit_status && error_exit_status != SimpleCov::ExitCodes::SUCCESS
217
+ end
218
+
219
+ #
220
+ # @api private
221
+ #
222
+ # Thinking: Move this behavior earlier so if there was an error we do nothing?
223
+ def exit_and_report_previous_error(exit_status)
224
+ warn("Stopped processing SimpleCov as a previous error not related to SimpleCov has been detected") if print_error_status
225
+ Kernel.exit(exit_status)
226
+ end
227
+
228
+ # @api private
229
+ def ready_to_process_results?
230
+ final_result_process? && result?
231
+ end
232
+
233
+ def process_results_and_report_error
234
+ exit_status = process_result(result)
235
+
236
+ # Force exit with stored status (see github issue #5)
237
+ if exit_status.positive?
238
+ warn("SimpleCov failed with exit #{exit_status} due to a coverage related error") if print_error_status
239
+ Kernel.exit exit_status
240
+ end
241
+ end
242
+
243
+ # @api private
244
+ #
245
+ # Usage:
246
+ # exit_status = SimpleCov.process_result(SimpleCov.result, exit_status)
247
+ #
248
+ def process_result(result)
249
+ result_exit_status = result_exit_status(result)
250
+ write_last_run(result) if result_exit_status == SimpleCov::ExitCodes::SUCCESS
251
+ result_exit_status
252
+ end
253
+
254
+ # @api private
255
+ CoverageLimits = Struct.new(:minimum_coverage, :minimum_coverage_by_file, :maximum_coverage_drop, keyword_init: true)
256
+ def result_exit_status(result)
257
+ coverage_limits = CoverageLimits.new(
258
+ minimum_coverage: minimum_coverage, minimum_coverage_by_file: minimum_coverage_by_file,
259
+ maximum_coverage_drop: maximum_coverage_drop
260
+ )
261
+
262
+ ExitCodes::ExitCodeHandling.call(result, coverage_limits: coverage_limits)
263
+ end
264
+
265
+ #
266
+ # @api private
267
+ #
268
+ def final_result_process?
269
+ # checking for ENV["TEST_ENV_NUMBER"] to determine if the tests are being run in parallel
270
+ !defined?(ParallelTests) || !ENV["TEST_ENV_NUMBER"] || ParallelTests.last_process?
271
+ end
272
+
273
+ #
274
+ # @api private
275
+ #
276
+ def wait_for_other_processes
277
+ return unless defined?(ParallelTests) && final_result_process?
278
+
279
+ ParallelTests.wait_for_other_processes_to_finish
89
280
  end
90
281
 
91
282
  #
92
- # Checks whether we're on a proper version of ruby (1.9+) and returns false if this is not the case,
93
- # also printing an appropriate warning
283
+ # @api private
94
284
  #
95
- def usable?
96
- unless "1.9".respond_to?(:encoding)
97
- warn "WARNING: SimpleCov is activated, but you're not running Ruby 1.9+ - no coverage analysis will happen"
98
- return false
285
+ def write_last_run(result)
286
+ SimpleCov::LastRun.write(result:
287
+ result.coverage_statistics.transform_values do |stats|
288
+ round_coverage(stats.percent)
289
+ end)
290
+ end
291
+
292
+ #
293
+ # @api private
294
+ #
295
+ # Rounding down to be extra strict, see #679
296
+ def round_coverage(coverage)
297
+ coverage.floor(2)
298
+ end
299
+
300
+ private
301
+
302
+ def initial_setup(profile, &block)
303
+ load_profile(profile) if profile
304
+ configure(&block) if block_given?
305
+ self.running = true
306
+ end
307
+
308
+ #
309
+ # Trigger Coverage.start depends on given config coverage_criterion
310
+ #
311
+ # With Positive branch it supports all coverage measurement types
312
+ # With Negative branch it supports only line coverage measurement type
313
+ #
314
+ def start_coverage_measurement
315
+ # This blog post gives a good run down of the coverage criterias introduced
316
+ # in Ruby 2.5: https://blog.bigbinary.com/2018/04/11/ruby-2-5-supports-measuring-branch-and-method-coverages.html
317
+ # There is also a nice writeup of the different coverage criteria made in this
318
+ # comment https://github.com/simplecov-ruby/simplecov/pull/692#discussion_r281836176 :
319
+ # Ruby < 2.5:
320
+ # https://github.com/ruby/ruby/blob/v1_9_3_374/ext/coverage/coverage.c
321
+ # traditional mode (Array)
322
+ #
323
+ # Ruby 2.5:
324
+ # https://bugs.ruby-lang.org/issues/13901
325
+ # https://github.com/ruby/ruby/blob/v2_5_3/ext/coverage/coverage.c
326
+ # default: traditional/compatible mode (Array)
327
+ # :lines - like traditional mode but using Hash
328
+ # :branches
329
+ # :methods
330
+ # :all - same as lines + branches + methods
331
+ #
332
+ # Ruby >= 2.6:
333
+ # https://bugs.ruby-lang.org/issues/15022
334
+ # https://github.com/ruby/ruby/blob/v2_6_3/ext/coverage/coverage.c
335
+ # default: traditional/compatible mode (Array)
336
+ # :lines - like traditional mode but using Hash
337
+ # :branches
338
+ # :methods
339
+ # :oneshot_lines - can not be combined with lines
340
+ # :all - same as lines + branches + methods
341
+ #
342
+ if coverage_start_arguments_supported?
343
+ start_coverage_with_criteria
344
+ else
345
+ Coverage.start unless Coverage.running?
99
346
  end
100
- true
347
+ end
348
+
349
+ def start_coverage_with_criteria
350
+ start_arguments = coverage_criteria.map do |criterion|
351
+ [lookup_corresponding_ruby_coverage_name(criterion), true]
352
+ end.to_h
353
+
354
+ start_arguments[:eval] = true if coverage_for_eval_enabled?
355
+
356
+ Coverage.start(start_arguments) unless Coverage.running?
357
+ end
358
+
359
+ CRITERION_TO_RUBY_COVERAGE = {
360
+ branch: :branches,
361
+ line: :lines
362
+ }.freeze
363
+ def lookup_corresponding_ruby_coverage_name(criterion)
364
+ CRITERION_TO_RUBY_COVERAGE.fetch(criterion)
365
+ end
366
+
367
+ #
368
+ # Finds files that were to be tracked but were not loaded and initializes
369
+ # the line-by-line coverage to zero (if relevant) or nil (comments / whitespace etc).
370
+ #
371
+ def add_not_loaded_files(result)
372
+ if tracked_files
373
+ result = result.dup
374
+ Dir[tracked_files].each do |file|
375
+ absolute_path = File.expand_path(file)
376
+ result[absolute_path] ||= SimulateCoverage.call(absolute_path)
377
+ end
378
+ end
379
+
380
+ result
381
+ end
382
+
383
+ #
384
+ # Call steps that handle process coverage result
385
+ #
386
+ # @return [Hash]
387
+ #
388
+ def process_coverage_result
389
+ adapt_coverage_result
390
+ remove_useless_results
391
+ result_with_not_loaded_files
392
+ end
393
+
394
+ #
395
+ # Unite the result so it wouldn't matter what coverage type was called
396
+ #
397
+ # @return [Hash]
398
+ #
399
+ def adapt_coverage_result
400
+ @result = SimpleCov::ResultAdapter.call(Coverage.result)
401
+ end
402
+
403
+ #
404
+ # Filter coverage result
405
+ # The result before filter also has result of coverage for files
406
+ # are not related to the project like loaded gems coverage.
407
+ #
408
+ # @return [Hash]
409
+ #
410
+ def remove_useless_results
411
+ @result = SimpleCov::UselessResultsRemover.call(@result)
412
+ end
413
+
414
+ #
415
+ # Initialize result with files that are not included by coverage
416
+ # and added inside the config block
417
+ #
418
+ # @return [Hash]
419
+ #
420
+ def result_with_not_loaded_files
421
+ @result = SimpleCov::Result.new(add_not_loaded_files(@result))
422
+ end
423
+
424
+ # parallel_tests isn't always available, see: https://github.com/grosser/parallel_tests/issues/772
425
+ def make_parallel_tests_available
426
+ return if defined?(ParallelTests)
427
+ return unless probably_running_parallel_tests?
428
+
429
+ require "parallel_tests"
430
+ rescue LoadError
431
+ warn("SimpleCov guessed you were running inside parallel tests but couldn't load it. Please file a bug report with us!")
432
+ end
433
+
434
+ def probably_running_parallel_tests?
435
+ ENV["TEST_ENV_NUMBER"] && ENV["PARALLEL_TEST_GROUPS"]
101
436
  end
102
437
  end
103
438
  end
104
439
 
105
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__)))
106
- require 'simplecov/configuration'
107
- SimpleCov.send :extend, SimpleCov::Configuration
108
- require 'simplecov/adapters'
109
- require 'simplecov/source_file'
110
- require 'simplecov/file_list'
111
- require 'simplecov/result'
112
- require 'simplecov/filter'
113
- require 'simplecov/formatter'
114
- require 'simplecov/merge_helpers'
115
- require 'simplecov/result_merger'
116
- require 'simplecov/command_guesser'
117
- require 'simplecov/version'
440
+ # requires are down here here for a load order reason I'm not sure what it is about
441
+ require "set"
442
+ require "forwardable"
443
+ require_relative "simplecov/configuration"
444
+ SimpleCov.extend SimpleCov::Configuration
445
+ require_relative "simplecov/coverage_statistics"
446
+ require_relative "simplecov/exit_codes"
447
+ require_relative "simplecov/profiles"
448
+ require_relative "simplecov/source_file/line"
449
+ require_relative "simplecov/source_file/branch"
450
+ require_relative "simplecov/source_file"
451
+ require_relative "simplecov/file_list"
452
+ require_relative "simplecov/result"
453
+ require_relative "simplecov/filter"
454
+ require_relative "simplecov/formatter"
455
+ require_relative "simplecov/last_run"
456
+ require_relative "simplecov/lines_classifier"
457
+ require_relative "simplecov/result_merger"
458
+ require_relative "simplecov/command_guesser"
459
+ require_relative "simplecov/version"
460
+ require_relative "simplecov/result_adapter"
461
+ require_relative "simplecov/combine"
462
+ require_relative "simplecov/combine/branches_combiner"
463
+ require_relative "simplecov/combine/files_combiner"
464
+ require_relative "simplecov/combine/lines_combiner"
465
+ require_relative "simplecov/combine/results_combiner"
466
+ require_relative "simplecov/useless_results_remover"
467
+ require_relative "simplecov/simulate_coverage"
118
468
 
119
469
  # Load default config
120
- require 'simplecov/defaults'
121
-
122
- # Load Rails integration
123
- require 'simplecov/railtie' if defined? Rails
470
+ require_relative "simplecov/defaults" unless ENV["SIMPLECOV_NO_DEFAULTS"]