Skip to content

Commit

Permalink
use status 0 for kernel.exit
Browse files Browse the repository at this point in the history
  • Loading branch information
ignacio-chiazzo committed Feb 2, 2024
1 parent 0990055 commit 77146ff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
13 changes: 5 additions & 8 deletions lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -986,19 +986,16 @@ def run(conf = IRB.conf)
begin
@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
context.io.save_history if supports_history_saving
Kernel.exit!
Kernel.exit!(0)
else
context.io.save_history if save_history
end
Expand Down
2 changes: 1 addition & 1 deletion lib/irb/cmd/exit_forced_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ExitForcedAction < Nop
def execute(*)
IRB.irb_exit!
rescue UncaughtThrowError
Kernel.exit
Kernel.exit(0)
end
end
end
Expand Down
14 changes: 8 additions & 6 deletions test/irb/test_debug_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 77146ff

Please sign in to comment.