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

Add method to shutdown and collect results before at_exit #731

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/simplecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ def start(profile = nil, &block)
Coverage.start
end

#
# Method added by NREL to shutdown SimpleCov and collect results
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is NREL?

# this will set running to false which will prevent from running again at_exit
def end_now
SimpleCov.set_exit_exception
exit_status = SimpleCov.exit_status_from_exception
SimpleCov.result.format!
exit_status = SimpleCov.process_result(SimpleCov.result, exit_status)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think SimpleCov should be self here so no need to address it directly imo. Also I think the last assignment and return aren't needed :)

exit_status
end

#
# Finds files that were to be tracked but were not loaded and initializes
# the line-by-line coverage to zero (if relevant) or nil (comments / whitespace etc).
Expand Down
5 changes: 3 additions & 2 deletions lib/simplecov/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@

at_exit do
# If we are in a different process than called start, don't interfere.
next if SimpleCov.pid != Process.pid

next unless SimpleCov.pid == Process.pid
# If SimpleCov is no longer running (e.g. `end_now` was called) then don't run exit tasks
next unless SimpleCov.running
SimpleCov.set_exit_exception
SimpleCov.run_exit_tasks!
end
Expand Down