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

autorun: run tests when exit() called explicitly #183

Closed
wants to merge 1 commit 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
3 changes: 2 additions & 1 deletion lib/minitest/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,8 @@ def self.after_tests &block

def self.autorun
at_exit {
next if $! # don't run if there was an exception
# don't run if there was an exception
next if $! and not $!.kind_of? SystemExit

# the order here is important. The at_exit handler must be
# installed before anyone else gets a chance to install their
Expand Down
20 changes: 20 additions & 0 deletions test/minitest/test_minitest_autorun.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'minitest/autorun'

describe 'at_exit', 'when dealing with exceptions' do
ruby = 'ruby -I lib -r minitest/autorun'

it 'runs tests if no exception was raised' do
`#{ruby} -e nil`.wont_be_empty
end

it 'runs tests if SystemExit was raised' do
`#{ruby} -e exit`.wont_be_empty
`#{ruby} -e 'at_exit { exit }'`.wont_be_empty
`#{ruby} -e 'at_exit { raise SystemExit }'`.wont_be_empty
end

it 'does not run tests if an exception other than SystemExit was raised' do
`#{ruby} -e 'at_exit { raise }' 2>/dev/null`.must_be_empty
`#{ruby} -e 'at_exit { raise Exception }' 2>/dev/null`.must_be_empty
end
end