summaryrefslogtreecommitdiff
path: root/spec/ruby/core/exception/signal_exception_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/exception/signal_exception_spec.rb')
-rw-r--r--spec/ruby/core/exception/signal_exception_spec.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/ruby/core/exception/signal_exception_spec.rb b/spec/ruby/core/exception/signal_exception_spec.rb
index e0b30236f7..e494e18cde 100644
--- a/spec/ruby/core/exception/signal_exception_spec.rb
+++ b/spec/ruby/core/exception/signal_exception_spec.rb
@@ -30,6 +30,12 @@ describe "SignalException.new" do
-> { SignalException.new("NONEXISTENT") }.should raise_error(ArgumentError)
end
+ ruby_version_is "2.6" do
+ it "raises an exception with an invalid first argument type" do
+ -> { SignalException.new(Object.new) }.should raise_error(ArgumentError)
+ end
+ end
+
it "takes a signal symbol without SIG prefix as the first argument" do
exc = SignalException.new(:INT)
exc.signo.should == Signal.list["INT"]
@@ -72,3 +78,48 @@ describe "rescuing SignalException" do
end
end
end
+
+describe "SignalException" do
+ it "can be rescued" do
+ ruby_exe(<<-RUBY)
+ begin
+ raise SignalException, 'SIGKILL'
+ rescue SignalException
+ exit(0)
+ end
+ exit(1)
+ RUBY
+
+ $?.exitstatus.should == 0
+ end
+
+ platform_is_not :windows do
+ it "runs after at_exit" do
+ output = ruby_exe(<<-RUBY)
+ at_exit do
+ puts "hello"
+ $stdout.flush
+ end
+
+ raise SignalException, 'SIGKILL'
+ RUBY
+
+ $?.termsig.should == Signal.list.fetch("KILL")
+ output.should == "hello\n"
+ end
+
+ it "cannot be trapped with Signal.trap" do
+ ruby_exe(<<-RUBY)
+ Signal.trap("PROF") {}
+ raise(SignalException, "PROF")
+ RUBY
+
+ $?.termsig.should == Signal.list.fetch("PROF")
+ end
+
+ it "self-signals for USR1" do
+ ruby_exe("raise(SignalException, 'USR1')")
+ $?.termsig.should == Signal.list.fetch('USR1')
+ end
+ end
+end