diff --git a/.simplecov b/.simplecov new file mode 100644 index 0000000..61a52c0 --- /dev/null +++ b/.simplecov @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'digest' + +digest = Digest::MD5.new +digest.update('test') +digest.update(ENV.fetch('BUNDLE_GEMFILE', 'gemfile')) if ENV['APPRAISAL_INITIALIZED'] + +ENV['ENABLE_COVERAGE'] ||= '1' + +if ENV['ENABLE_COVERAGE'].to_i.positive? + SimpleCov.command_name(ENV['SIMPLECOV_COMMAND_NAME'] || digest.hexdigest) + + # Hook Process._fork so forked children store their own coverage slice. + SimpleCov.merge_subprocesses true + + SimpleCov.start do + merging true + add_filter %r{^/test/} + end +end diff --git a/Gemfile b/Gemfile index 12cceea..6216c1a 100644 --- a/Gemfile +++ b/Gemfile @@ -17,7 +17,7 @@ group :test do gem 'rubocop-performance', '~> 1.26.0' gem 'rubocop-rake', '~> 0.7.1' gem 'rubocop-rspec', '~> 3.10.0' - gem 'simplecov', '~> 0.22.0' + gem 'simplecov', '~> 1.0.0' gem 'yard', '~> 0.9.44' if RUBY_VERSION >= '3.4' gem 'base64' diff --git a/test/test_helper.rb b/test/test_helper.rb index 1d22d12..6c5fa89 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -5,8 +5,6 @@ # SPDX-License-Identifier: Apache-2.0 require 'simplecov' -SimpleCov.start - require 'rake' require 'minitest' require 'minitest/autorun' @@ -44,7 +42,6 @@ def run_in_subprocess(env_vars = {}, opts = {}) read_pipe, write_pipe = IO.pipe pid = fork do - SimpleCov.command_name "subprocess-#{Process.pid}" read_pipe.close env_vars.each { |key, value| ENV[key] = value } ENV['OTEL_RUBY_REQUIRE_BUNDLER'] = 'false' @@ -149,10 +146,7 @@ def run_in_subprocess(env_vars = {}, opts = {}) ensure $stderr = old_stderr if defined?(old_stderr) write_pipe.close - - # Store the simplecov result for this process - SimpleCov::ResultMerger.store_result(SimpleCov::Result.new(Coverage.result)) if SimpleCov.running - exit!(0) + exit(0) end end