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) 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