From b53cf149ad8d7c46572e4567ca949b4f82ebb22c Mon Sep 17 00:00:00 2001 From: eregon Date: Fri, 3 Aug 2018 16:19:40 +0000 Subject: Update to ruby/spec@9be7c7e git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/ruby/core/signal/trap_spec.rb | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'spec/ruby/core/signal/trap_spec.rb') diff --git a/spec/ruby/core/signal/trap_spec.rb b/spec/ruby/core/signal/trap_spec.rb index d621b6ae6d..66101ee5a0 100644 --- a/spec/ruby/core/signal/trap_spec.rb +++ b/spec/ruby/core/signal/trap_spec.rb @@ -115,6 +115,49 @@ platform_is_not :windows do end describe "Signal.trap" do + cannot_be_trapped = %w[KILL STOP] # See man 2 signal + reserved_signals = %w[VTALRM] + + if PlatformGuard.implementation?(:ruby) + reserved_signals += %w[SEGV ILL FPE BUS] + end + + if PlatformGuard.implementation?(:truffleruby) + if !TruffleRuby.native? + reserved_signals += %w[SEGV ILL FPE USR1 QUIT] + end + end + + if PlatformGuard.implementation?(:jruby) + reserved_signals += %w[SEGV ILL FPE BUS USR1 QUIT] + end + + cannot_be_trapped.each do |signal| + it "raises ArgumentError or Errno::EINVAL for SIG#{signal}" do + -> { + trap(signal, -> {}) + }.should raise_error(StandardError) { |e| + [ArgumentError, Errno::EINVAL].should include(e.class) + e.message.should =~ /Invalid argument|Signal already used by VM or OS/ + } + end + end + + reserved_signals.each do |signal| + it "raises ArgumentError for reserved signal SIG#{signal}" do + -> { + trap(signal, -> {}) + }.should raise_error(ArgumentError, /can't trap reserved signal|Signal already used by VM or OS/) + end + end + + it "allows to register a handler for all known signals, except reserved signals" do + excluded = cannot_be_trapped + reserved_signals + out = ruby_exe(fixture(__FILE__, "trap_all.rb"), args: [*excluded, "2>&1"]) + out.should == "OK\n" + $?.exitstatus.should == 0 + end + it "returns SYSTEM_DEFAULT if passed DEFAULT and no handler was ever set" do Signal.trap("PROF", "DEFAULT").should == "SYSTEM_DEFAULT" end -- cgit v1.2.3