Skip to content

Commit cc37760

Browse files
committed
Add more #at_exit specs
1 parent 3b91db2 commit cc37760

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

spec/ruby/core/kernel/at_exit_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@
3737
result.lines.should.include?("The exception matches: true (message=foo)\n")
3838
end
3939

40+
it "both exceptions in at_exit and in the main script are printed" do
41+
result = ruby_exe('at_exit { raise "at_exit_error" }; raise "main_script_error"', args: "2>&1")
42+
result.should.include?('at_exit_error (RuntimeError)')
43+
result.should.include?('main_script_error (RuntimeError)')
44+
end
45+
46+
it "decides the exit status if both at_exit and the main script raise SystemExit" do
47+
ruby_exe('at_exit { exit 43 }; exit 42', args: "2>&1")
48+
$?.exitstatus.should == 43
49+
end
50+
51+
it "runs all at_exit even if some raise exceptions" do
52+
code = 'at_exit { STDERR.puts "last" }; at_exit { exit 43 }; at_exit { STDERR.puts "first" }; exit 42'
53+
result = ruby_exe(code, args: "2>&1")
54+
result.should == "first\nlast\n"
55+
$?.exitstatus.should == 43
56+
end
4057
end
4158

4259
describe "Kernel#at_exit" do

spec/ruby/shared/process/exit.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@
9292
$?.exitstatus.should == 21
9393
end
9494

95+
it "skips at_exit handlers" do
96+
out = ruby_exe("at_exit { STDERR.puts 'at_exit' }; #{@object}.send(:exit!, 21)", args: '2>&1')
97+
out.should == ""
98+
$?.exitstatus.should == 21
99+
end
100+
95101
it "overrides the original exception and exit status when called from #at_exit" do
96102
code = <<-RUBY
97103
at_exit do

spec/tags/core/kernel/at_exit_tags.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ slow:Kernel.at_exit runs after all other code
22
slow:Kernel.at_exit runs in reverse order of registration
33
slow:Kernel.at_exit allows calling exit inside at_exit handler
44
slow:Kernel.at_exit gives access to the last raised exception
5+
slow:Kernel.at_exit both exceptions in at_exit and in the main script are printed
6+
slow:Kernel.at_exit decides the exit status if both at_exit and the main script raise SystemExit
7+
slow:Kernel.at_exit runs all at_exit even if some raise exceptions

spec/tags/core/kernel/exit_tags.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ slow:Kernel.exit! exits when called from a thread
66
slow:Kernel.exit! exits when called from a fiber
77
slow:Kernel#exit! overrides the original exception and exit status when called from #at_exit
88
slow:Kernel.exit! overrides the original exception and exit status when called from #at_exit
9+
slow:Kernel#exit! skips at_exit handlers
10+
slow:Kernel.exit! skips at_exit handlers

spec/tags/core/process/exit_tags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ slow:Process.exit! exits with the given status
22
slow:Process.exit! exits when called from a thread
33
slow:Process.exit! exits when called from a fiber
44
slow:Process.exit! overrides the original exception and exit status when called from #at_exit
5+
slow:Process.exit! skips at_exit handlers

0 commit comments

Comments
 (0)