diff options
Diffstat (limited to 'spec/ruby/shared/process')
| -rw-r--r-- | spec/ruby/shared/process/exit.rb | 38 | ||||
| -rw-r--r-- | spec/ruby/shared/process/fork.rb | 10 |
2 files changed, 40 insertions, 8 deletions
diff --git a/spec/ruby/shared/process/exit.rb b/spec/ruby/shared/process/exit.rb index 1820dd17fd..1e073614a3 100644 --- a/spec/ruby/shared/process/exit.rb +++ b/spec/ruby/shared/process/exit.rb @@ -21,6 +21,12 @@ describe :process_exit, shared: true do end end + it "raises a SystemExit with message 'exit'" do + -> { @object.exit }.should raise_error(SystemExit) { |e| + e.message.should == "exit" + } + end + it "tries to convert the passed argument to an Integer using #to_int" do obj = mock('5') obj.should_receive(:to_int).and_return(5) @@ -75,20 +81,46 @@ end describe :process_exit!, shared: true do it "exits with the given status" do - out = ruby_exe("#{@object}.send(:exit!, 21)", args: '2>&1') + out = ruby_exe("#{@object}.send(:exit!, 21)", args: '2>&1', exit_status: 21) out.should == "" $?.exitstatus.should == 21 end it "exits when called from a thread" do - out = ruby_exe("Thread.new { #{@object}.send(:exit!, 21) }.join; sleep", args: '2>&1') + out = ruby_exe("Thread.new { #{@object}.send(:exit!, 21) }.join; sleep", args: '2>&1', exit_status: 21) out.should == "" $?.exitstatus.should == 21 end it "exits when called from a fiber" do - out = ruby_exe("Fiber.new { #{@object}.send(:exit!, 21) }.resume", args: '2>&1') + out = ruby_exe("Fiber.new { #{@object}.send(:exit!, 21) }.resume", args: '2>&1', exit_status: 21) + out.should == "" + $?.exitstatus.should == 21 + end + + it "skips at_exit handlers" do + out = ruby_exe("at_exit { STDERR.puts 'at_exit' }; #{@object}.send(:exit!, 21)", args: '2>&1', exit_status: 21) out.should == "" $?.exitstatus.should == 21 end + + it "skips ensure clauses" do + out = ruby_exe("begin; STDERR.puts 'before'; #{@object}.send(:exit!, 21); ensure; STDERR.puts 'ensure'; end", args: '2>&1', exit_status: 21) + out.should == "before\n" + $?.exitstatus.should == 21 + end + + it "overrides the original exception and exit status when called from #at_exit" do + code = <<-RUBY + at_exit do + STDERR.puts 'in at_exit' + STDERR.puts "$! is \#{$!.class}:\#{$!.message}" + #{@object}.send(:exit!, 21) + end + raise 'original error' + RUBY + out = ruby_exe(code, args: '2>&1', exit_status: 21) + out.should == "in at_exit\n$! is RuntimeError:original error\n" + $?.exitstatus.should == 21 + end end diff --git a/spec/ruby/shared/process/fork.rb b/spec/ruby/shared/process/fork.rb index 11e18d7b1c..8dbb3d0da4 100644 --- a/spec/ruby/shared/process/fork.rb +++ b/spec/ruby/shared/process/fork.rb @@ -23,31 +23,31 @@ describe :process_fork, shared: true do end it "returns status zero" do - pid = Process.fork { exit! 0 } + pid = @object.fork { exit! 0 } _, result = Process.wait2(pid) result.exitstatus.should == 0 end it "returns status zero" do - pid = Process.fork { exit 0 } + pid = @object.fork { exit 0 } _, result = Process.wait2(pid) result.exitstatus.should == 0 end it "returns status zero" do - pid = Process.fork {} + pid = @object.fork {} _, result = Process.wait2(pid) result.exitstatus.should == 0 end it "returns status non-zero" do - pid = Process.fork { exit! 42 } + pid = @object.fork { exit! 42 } _, result = Process.wait2(pid) result.exitstatus.should == 42 end it "returns status non-zero" do - pid = Process.fork { exit 42 } + pid = @object.fork { exit 42 } _, result = Process.wait2(pid) result.exitstatus.should == 42 end |
