Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't call SimpleCov.result before checking SimpleCov.result? #674

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/simplecov.rb
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions spec/result_merger_spec.rb
Expand Up @@ -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
Expand Down