File tree Expand file tree Collapse file tree 5 files changed +29
-0
lines changed Expand file tree Collapse file tree 5 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 37
37
result . lines . should . include? ( "The exception matches: true (message=foo)\n " )
38
38
end
39
39
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\n last\n "
55
+ $?. exitstatus . should == 43
56
+ end
40
57
end
41
58
42
59
describe "Kernel#at_exit" do
Original file line number Diff line number Diff line change 92
92
$?. exitstatus . should == 21
93
93
end
94
94
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
+
95
101
it "overrides the original exception and exit status when called from #at_exit" do
96
102
code = <<-RUBY
97
103
at_exit do
Original file line number Diff line number Diff line change @@ -2,3 +2,6 @@ slow:Kernel.at_exit runs after all other code
2
2
slow:Kernel.at_exit runs in reverse order of registration
3
3
slow:Kernel.at_exit allows calling exit inside at_exit handler
4
4
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
Original file line number Diff line number Diff line change @@ -6,3 +6,5 @@ slow:Kernel.exit! exits when called from a thread
6
6
slow:Kernel.exit! exits when called from a fiber
7
7
slow:Kernel#exit! overrides the original exception and exit status when called from #at_exit
8
8
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
Original file line number Diff line number Diff line change @@ -2,3 +2,4 @@ slow:Process.exit! exits with the given status
2
2
slow:Process.exit! exits when called from a thread
3
3
slow:Process.exit! exits when called from a fiber
4
4
slow:Process.exit! overrides the original exception and exit status when called from #at_exit
5
+ slow:Process.exit! skips at_exit handlers
You can’t perform that action at this time.
0 commit comments