summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSorah Fukumori <her@sorah.jp>2024-01-01 19:58:32 +0900
committergit <svn-admin@ruby-lang.org>2024-01-01 10:58:35 +0000
commitcd411778159618dd926614e0acd52ac5549a9408 (patch)
treed5041c3d6939985cd911b6b44fdb60868951ed7a
parent5c81fd68865bdfacbb3496bb077b9f8ce6e411fd (diff)
[ruby/irb] test_recovery_sigint: Ensure precondition is met
(https://github.com/ruby/irb/pull/829) * test_recovery_sigint: Ensure precondition is met test_recovery_sigint depends on its process has SIG_DEF sigaction for SIGINT. When its parent process set SIG_IGN which inherits to children, then this test fails. This patch ensures this precondition met regardless of inherited sigaction from its parent. * Add test for restoration of other SIGINT handlers Add another variant of test_recovery_sigint to ensure IRB to preserve existing SIGINT handler other than SIG_DEF. https://github.com/ruby/irb/commit/77ee59d026
-rw-r--r--test/irb/test_init.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb
index 7d11b5b507..0365098132 100644
--- a/test/irb/test_init.rb
+++ b/test/irb/test_init.rb
@@ -66,10 +66,18 @@ module TestIRB
end
end
- def test_recovery_sigint
+ def test_sigint_restore_default
pend "This test gets stuck on Solaris for unknown reason; contribution is welcome" if RUBY_PLATFORM =~ /solaris/
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
- status = assert_in_out_err(bundle_exec + %w[-W0 -rirb -e binding.irb;loop{Process.kill("SIGINT",$$)} -- -f --], "exit\n", //, //)
+ # IRB should restore SIGINT handler
+ status = assert_in_out_err(bundle_exec + %w[-W0 -rirb -e Signal.trap("SIGINT","DEFAULT");binding.irb;loop{Process.kill("SIGINT",$$)} -- -f --], "exit\n", //, //)
+ Process.kill("SIGKILL", status.pid) if !status.exited? && !status.stopped? && !status.signaled?
+ end
+
+ def test_sigint_restore_block
+ bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
+ # IRB should restore SIGINT handler
+ status = assert_in_out_err(bundle_exec + %w[-W0 -rirb -e x=false;Signal.trap("SIGINT"){x=true};binding.irb;loop{Process.kill("SIGINT",$$);if(x);break;end} -- -f --], "exit\n", //, //)
Process.kill("SIGKILL", status.pid) if !status.exited? && !status.stopped? && !status.signaled?
end