From a6f5ee7efc0ac336ca8558886e65c38b0ab52337 Mon Sep 17 00:00:00 2001 From: Tobias Pfeiffer Date: Thu, 6 Feb 2020 14:05:13 +0100 Subject: [PATCH] Move at exit behavior into mainline SimpleCov not defaults Naming it "custom" is slightly odd, as it's in the defaults and if people wanted to differ they could define their own at_exit hook and call whatever they wanted. --- lib/minitest/simplecov_plugin.rb | 2 +- lib/simplecov.rb | 8 ++++++++ lib/simplecov/defaults.rb | 12 +----------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/minitest/simplecov_plugin.rb b/lib/minitest/simplecov_plugin.rb index 96f1938d..ac4cf076 100644 --- a/lib/minitest/simplecov_plugin.rb +++ b/lib/minitest/simplecov_plugin.rb @@ -3,7 +3,7 @@ module Minitest def self.plugin_simplecov_init(_options) Minitest.after_run do - SimpleCov.custom_at_exit if SimpleCov.respond_to?(:custom_at_exit) + SimpleCov.at_exit_behvior if SimpleCov.respond_to?(:at_exit_behvior) end end end diff --git a/lib/simplecov.rb b/lib/simplecov.rb index f8edae47..ac668264 100644 --- a/lib/simplecov.rb +++ b/lib/simplecov.rb @@ -189,6 +189,14 @@ def exit_status_from_exception end end + def at_exit_behvior + # If we are in a different process than called start, don't interfere. + return if SimpleCov.pid != Process.pid + + # If SimpleCov is no longer running then don't run exit tasks + SimpleCov.run_exit_tasks! if SimpleCov.running + end + # @api private # # Called from at_exit block diff --git a/lib/simplecov/defaults.rb b/lib/simplecov/defaults.rb index 2ec88501..364e247f 100644 --- a/lib/simplecov/defaults.rb +++ b/lib/simplecov/defaults.rb @@ -21,21 +21,11 @@ # Gotta stash this a-s-a-p, see the CommandGuesser class and i.e. #110 for further info SimpleCov::CommandGuesser.original_run_command = "#{$PROGRAM_NAME} #{ARGV.join(' ')}" -module SimpleCov - def self.custom_at_exit - # If we are in a different process than called start, don't interfere. - return if SimpleCov.pid != Process.pid - - # If SimpleCov is no longer running then don't run exit tasks - SimpleCov.run_exit_tasks! if SimpleCov.running - end -end - at_exit do # Exit hook for Minitest defined in Minitest plugin next if defined?(Minitest) - SimpleCov.custom_at_exit + SimpleCov.at_exit_behvior end # Autoload config from ~/.simplecov if present