From 649149c21c7a20c03f12d6e7f34e6fa96b25acf2 Mon Sep 17 00:00:00 2001 From: Matt Schreiber Date: Wed, 11 Apr 2018 16:11:56 -0400 Subject: [PATCH 1/2] simplecov.rb: check .result? in .run_exit_tasks! rather than in .process_result in order to avoid instantiating SimpleCov.result prior to performing the .result? check, as doing so guarantees that .result? will always return 'true' --- lib/simplecov.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/simplecov.rb b/lib/simplecov.rb index 11ab2db3..4f945685 100644 --- a/lib/simplecov.rb +++ b/lib/simplecov.rb @@ -199,7 +199,9 @@ def run_exit_tasks! SimpleCov.at_exit.call - exit_status = SimpleCov.process_result(SimpleCov.result, exit_status) + # Don't modify the exit status unless the result has already been + # computed + exit_status = SimpleCov.process_result(SimpleCov.result, exit_status) if SimpleCov.result? # Force exit with stored status (see github issue #5) # unless it's nil or 0 (see github issue #281) @@ -212,7 +214,6 @@ def run_exit_tasks! # exit_status = SimpleCov.process_result(SimpleCov.result, exit_status) # def process_result(result, exit_status) - return exit_status unless SimpleCov.result? # Result has been computed return exit_status if exit_status != SimpleCov::ExitCodes::SUCCESS # Existing errors covered_percent = result.covered_percent.round(2) From 4e853f1301eb3f208445ea4a690e68f25b5ea95b Mon Sep 17 00:00:00 2001 From: Matt Schreiber Date: Wed, 11 Apr 2018 16:18:39 -0400 Subject: [PATCH 2/2] spec/result_merger_spec.rb: test that manually-stored merged results data isn't clobbered by SimpleCov.run_exit_tasks\!/.process_results --- spec/result_merger_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/spec/result_merger_spec.rb b/spec/result_merger_spec.rb index 78fb8fe8..0e239252 100644 --- a/spec/result_merger_spec.rb +++ b/spec/result_merger_spec.rb @@ -104,6 +104,31 @@ expect(SimpleCov::ResultMerger).to receive(:synchronize_resultset) SimpleCov::ResultMerger.store_result({}) end + + it "persists after exit" do + skip "fork not available on JRuby" if RUBY_ENGINE == "jruby" + + coverage = {__FILE__ => 5.downto(1).to_a} + + # Fork to ensure that the Kernel.at_exit block defined in + # simplecov/defaults.rb runs + pid = Kernel.fork do + SimpleCov.start + + # Override the default SimpleCov.at_exit block to avoid instantiating + # SimpleCov.result + SimpleCov.at_exit {} + SimpleCov.command_name "merged result persistence" + + result = SimpleCov::Result.new(coverage) + SimpleCov::ResultMerger.store_result(result) + end + + Process.waitpid pid + + merged_result = SimpleCov::ResultMerger.merged_result + expect(merged_result.original_result).to include(coverage) + end end describe ".resultset" do