aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2023-07-25 19:33:18 +0100
committergit <svn-admin@ruby-lang.org>2023-07-25 18:33:23 +0000
commitd8cee5507361b2cd3f3baccb8fda45bad8389a70 (patch)
tree90550675d7f90c2fab62701d6135e3355e9e5987 /test
parente1104017e3080fd432c0b5fdc3ae6e004ffd0834 (diff)
downloadruby-d8cee5507361b2cd3f3baccb8fda45bad8389a70.tar.gz
[ruby/irb] Display `show_cmds`'s output in a pager when in TTY
environment (https://github.com/ruby/irb/pull/647) This can: - Make it easier to scroll up and down the commands list - Avoid pushing up users' previous output - Allow users to do basic search with `/<word>` https://github.com/ruby/irb/commit/f94e8a66dd
Diffstat (limited to 'test')
-rw-r--r--test/irb/test_cmd.rb10
-rw-r--r--test/irb/yamatanooroti/test_rendering.rb18
2 files changed, 28 insertions, 0 deletions
diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb
index 71df60db14..71d64a0ec2 100644
--- a/test/irb/test_cmd.rb
+++ b/test/irb/test_cmd.rb
@@ -688,6 +688,16 @@ module TestIRB
class ShowCmdsTest < CommandTestCase
+ def setup
+ STDIN.singleton_class.define_method :tty? do
+ false
+ end
+ end
+
+ def teardown
+ STDIN.singleton_class.remove_method :tty?
+ end
+
def test_show_cmds
out, err = execute_lines(
"show_cmds\n"
diff --git a/test/irb/yamatanooroti/test_rendering.rb b/test/irb/yamatanooroti/test_rendering.rb
index d2342d6a23..12467b0913 100644
--- a/test/irb/yamatanooroti/test_rendering.rb
+++ b/test/irb/yamatanooroti/test_rendering.rb
@@ -252,6 +252,24 @@ class IRB::RenderingTest < Yamatanooroti::TestCase
EOC
end
+ def test_show_cmds_with_pager_can_quit_with_ctrl_c
+ write_irbrc <<~'LINES'
+ puts 'start IRB'
+ LINES
+ start_terminal(40, 80, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
+ write("show_cmds\n")
+ write("G") # move to the end of the screen
+ write("\C-c") # quit pager
+ write("'foo' + 'bar'\n") # eval something to make sure IRB resumes
+ close
+
+ screen = result.join("\n").sub(/\n*\z/, "\n")
+ # IRB::Abort should be rescued
+ assert_not_match(/IRB::Abort/, screen)
+ # IRB should resume
+ assert_match(/foobar/, screen)
+ end
+
private
def write_irbrc(content)