[ruby/irb] Remove exit command workaround, handle IRB_EXIT in

debug_readline
(https://github.com/ruby/irb/pull/923)

* Remove exit and exti! command workaround when executed outside of IRB

Command was a method. It could be executed outside of IRB.
Workaround for it is no longer needed.

* Handle IRB_EXIT in debug mode

* Add exit and exit! command in rdbg mode

https://github.com/ruby/irb/commit/0b5dd6afd0
This commit is contained in:
tomoya ishida 2024-04-20 16:45:38 +09:00 коммит произвёл git
Родитель 9f9755664d
Коммит 125e1ed5f7
5 изменённых файлов: 41 добавлений и 33 удалений

Просмотреть файл

@ -962,20 +962,26 @@ module IRB
#
# Irb#eval_input will simply return the input, and we need to pass it to the
# debugger.
input = if IRB.conf[:SAVE_HISTORY] && context.io.support_history_saving?
# Previous IRB session's history has been saved when `Irb#run` is exited We need
# to make sure the saved history is not saved again by resetting the counter
context.io.reset_history_counter
input = nil
forced_exit = catch(:IRB_EXIT) do
if IRB.conf[:SAVE_HISTORY] && context.io.support_history_saving?
# Previous IRB session's history has been saved when `Irb#run` is exited We need
# to make sure the saved history is not saved again by resetting the counter
context.io.reset_history_counter
begin
eval_input
ensure
context.io.save_history
begin
input = eval_input
ensure
context.io.save_history
end
else
input = eval_input
end
else
eval_input
false
end
Kernel.exit if forced_exit
if input&.include?("\n")
@line_no += input.count("\n") - 1
end

Просмотреть файл

@ -8,10 +8,8 @@ module IRB
category "IRB"
description "Exit the current irb session."
def execute(*)
def execute(_arg)
IRB.irb_exit
rescue UncaughtThrowError
Kernel.exit
end
end
end

Просмотреть файл

@ -8,10 +8,8 @@ module IRB
category "IRB"
description "Exit the current process."
def execute(*)
def execute(_arg)
throw :IRB_EXIT, true
rescue UncaughtThrowError
Kernel.exit!
end
end
end

Просмотреть файл

@ -47,17 +47,5 @@ module TestIRB
assert_match(/irb\(main\):001> 123/, output)
end
def test_forced_exit_out_of_irb_session
write_ruby <<~'ruby'
at_exit { puts 'un' + 'reachable' }
binding.irb
exit! # this will call exit! method overrided by command
ruby
output = run_ruby_file do
type "exit"
end
assert_not_include(output, 'unreachable')
end
end
end

Просмотреть файл

@ -244,28 +244,46 @@ module TestIRB
def test_exit
write_ruby <<~'RUBY'
binding.irb
puts "hello"
puts "he" + "llo"
RUBY
output = run_ruby_file do
type "next"
type "debug"
type "exit"
end
assert_match(/irb\(main\):001> next/, output)
assert_match(/irb:rdbg\(main\):002>/, output)
assert_match(/hello/, output)
end
def test_force_exit
write_ruby <<~'RUBY'
binding.irb
puts "he" + "llo"
RUBY
output = run_ruby_file do
type "debug"
type "exit!"
end
assert_match(/irb:rdbg\(main\):002>/, output)
assert_not_match(/hello/, output)
end
def test_quit
write_ruby <<~'RUBY'
binding.irb
puts "he" + "llo"
RUBY
output = run_ruby_file do
type "next"
type "debug"
type "quit!"
end
assert_match(/irb\(main\):001> next/, output)
assert_match(/irb:rdbg\(main\):002>/, output)
assert_not_match(/hello/, output)
end
def test_prompt_line_number_continues