diff options
author | Benoit Daloze <eregontp@gmail.com> | 2020-07-27 21:41:08 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2020-07-27 21:41:08 +0200 |
commit | 126fd5f15cff0d3bf314d90d8c21a3ae25ae8e68 (patch) | |
tree | 33350f7170436c32ed4c8e79f0be2c334c7bc8a9 /spec/ruby/shared | |
parent | 7429841ab6494b849106e6d3b119f147adfee3b7 (diff) | |
download | ruby-126fd5f15cff0d3bf314d90d8c21a3ae25ae8e68.tar.gz |
Update to ruby/spec@07164da
Diffstat (limited to 'spec/ruby/shared')
-rw-r--r-- | spec/ruby/shared/kernel/raise.rb | 27 | ||||
-rw-r--r-- | spec/ruby/shared/process/exit.rb | 20 |
2 files changed, 28 insertions, 19 deletions
diff --git a/spec/ruby/shared/kernel/raise.rb b/spec/ruby/shared/kernel/raise.rb index d4553775f4..7d9954e29a 100644 --- a/spec/ruby/shared/kernel/raise.rb +++ b/spec/ruby/shared/kernel/raise.rb @@ -25,6 +25,14 @@ describe :kernel_raise, shared: true do -> { @object.raise("a bad thing") }.should raise_error(RuntimeError) end + it "passes no arguments to the constructor when given only an exception class" do + klass = Class.new(Exception) do + def initialize + end + end + -> { @object.raise(klass) }.should raise_error(klass) { |e| e.message.should == klass.to_s } + end + it "raises a TypeError when passed a non-Exception object" do -> { @object.raise(Object.new) }.should raise_error(TypeError) end @@ -41,25 +49,6 @@ describe :kernel_raise, shared: true do -> { @object.raise(nil) }.should raise_error(TypeError) end - it "re-raises the previously rescued exception if no exception is specified" do - -> do - begin - @object.raise Exception, "outer" - ScratchPad.record :no_abort - rescue - begin - @object.raise StandardError, "inner" - rescue - end - - @object.raise - ScratchPad.record :no_reraise - end - end.should raise_error(Exception, "outer") - - ScratchPad.recorded.should be_nil - end - it "re-raises a previously rescued exception without overwriting the backtrace" do begin initial_raise_line = __LINE__; @object.raise 'raised' diff --git a/spec/ruby/shared/process/exit.rb b/spec/ruby/shared/process/exit.rb index 1820dd17fd..e633afc73a 100644 --- a/spec/ruby/shared/process/exit.rb +++ b/spec/ruby/shared/process/exit.rb @@ -91,4 +91,24 @@ describe :process_exit!, shared: true do 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') + out.should == "" + $?.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') + out.should == "in at_exit\n$! is RuntimeError:original error\n" + $?.exitstatus.should == 21 + end end |