summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomoya ishida <tomoyapenguin@gmail.com>2024-04-20 16:45:38 +0900
committergit <svn-admin@ruby-lang.org>2024-04-20 07:45:41 +0000
commit125e1ed5f7dc60ec492a1646ccc0912626c95bd1 (patch)
tree93c4e84b014aff07654d2911725156d0fa013ede
parent9f9755664ddc4447dd498ec75613d996238169c0 (diff)
[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
-rw-r--r--lib/irb.rb26
-rw-r--r--lib/irb/command/exit.rb4
-rw-r--r--lib/irb/command/force_exit.rb4
-rw-r--r--test/irb/command/test_force_exit.rb12
-rw-r--r--test/irb/test_debugger_integration.rb28
5 files changed, 41 insertions, 33 deletions
diff --git a/lib/irb.rb b/lib/irb.rb
index d6afd6e510..faf82f32d3 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -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
diff --git a/lib/irb/command/exit.rb b/lib/irb/command/exit.rb
index 3109ec16e3..b4436f0343 100644
--- a/lib/irb/command/exit.rb
+++ b/lib/irb/command/exit.rb
@@ -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
diff --git a/lib/irb/command/force_exit.rb b/lib/irb/command/force_exit.rb
index c2c5542e24..14086aa849 100644
--- a/lib/irb/command/force_exit.rb
+++ b/lib/irb/command/force_exit.rb
@@ -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
diff --git a/test/irb/command/test_force_exit.rb b/test/irb/command/test_force_exit.rb
index 9e86c644d6..191a786872 100644
--- a/test/irb/command/test_force_exit.rb
+++ b/test/irb/command/test_force_exit.rb
@@ -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
diff --git a/test/irb/test_debugger_integration.rb b/test/irb/test_debugger_integration.rb
index 839a0d43f0..eca40c5702 100644
--- a/test/irb/test_debugger_integration.rb
+++ b/test/irb/test_debugger_integration.rb
@@ -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