From bb382eacdbed717c7790cf0d886b57301850585e Mon Sep 17 00:00:00 2001 From: ignacio chiazzo Date: Fri, 2 Feb 2024 17:21:33 -0300 Subject: [PATCH] use status 0 for kernel.exit --- lib/irb.rb | 17 +++++++---------- lib/irb/cmd/exit_forced_action.rb | 4 ++-- test/irb/test_debug_cmd.rb | 14 ++++++++------ 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/irb.rb b/lib/irb.rb index 4ea1ed3de..8fcf5d336 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -886,11 +886,11 @@ def IRB.start(ap_path = nil) # Quits irb def IRB.irb_exit(*) - throw :IRB_EXIT + throw :IRB_EXIT, false end def IRB.irb_exit!(*) - throw :IRB_EXIT! + throw :IRB_EXIT, true end # Aborts then interrupts irb. @@ -984,21 +984,18 @@ def run(conf = IRB.conf) end begin - @forced_exit = false + forced_exit = false - catch(:IRB_EXIT) do - catch(:IRB_EXIT!) do - eval_input - end - @forced_exit = true + forced_exit = catch(:IRB_EXIT) do + eval_input end ensure trap("SIGINT", prev_trap) conf[:AT_EXIT].each{|hook| hook.call} - if @forced_exit + if forced_exit context.io.save_history if supports_history_saving - Kernel.exit! + Kernel.exit!(0) else context.io.save_history if save_history end diff --git a/lib/irb/cmd/exit_forced_action.rb b/lib/irb/cmd/exit_forced_action.rb index 2613d339a..e5df75b68 100644 --- a/lib/irb/cmd/exit_forced_action.rb +++ b/lib/irb/cmd/exit_forced_action.rb @@ -8,12 +8,12 @@ module IRB module ExtendCommand class ExitForcedAction < Nop category "IRB" - description "Exit the current irb session with exit!." + description "Exit the current process." def execute(*) IRB.irb_exit! rescue UncaughtThrowError - Kernel.exit + Kernel.exit(0) end end end diff --git a/test/irb/test_debug_cmd.rb b/test/irb/test_debug_cmd.rb index d8adce3fc..8aec7e4bb 100644 --- a/test/irb/test_debug_cmd.rb +++ b/test/irb/test_debug_cmd.rb @@ -257,12 +257,12 @@ def test_exit def test_forced_exit write_ruby <<~'ruby' - puts "first line" + puts "First line" + puts "Second line" binding.irb - puts "second line" - binding.irb - puts "third" + puts "Third line" binding.irb + puts "Fourth line" ruby output = run_ruby_file do @@ -271,10 +271,12 @@ def test_forced_exit type "exit!" end + assert_match(/First line\r\n/, output) + assert_match(/Second line\r\n/, output) assert_match(/irb\(main\):001> 123/, output) assert_match(/irb\(main\):002> 456/, output) - assert_match(/irb\(main\):003> exit!/, output) - output.end_with?("003> exit!") + refute_match(/Third line\r\n/, output) + refute_match(/Fourth line\r\n/, output) end def test_quit