From 5ca9f023580d5db2de7285b771c8e55041d28fef Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Fri, 3 May 2024 15:38:59 +0900 Subject: [PATCH 1/2] Avoid raising errors while running help for custom commands Raising an error from the help command is not a pleasure for the end user, even if the command does not define any attributes --- lib/irb/command/help.rb | 2 +- test/irb/command/test_custom_command.rb | 27 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/irb/command/help.rb b/lib/irb/command/help.rb index 1ed7a7707..995b81bf1 100644 --- a/lib/irb/command/help.rb +++ b/lib/irb/command/help.rb @@ -12,7 +12,7 @@ def execute(command_name) help_message else if command_class = Command.load_command(command_name) - command_class.help_message || command_class.description + command_class.help_message || command_class.description || "" else "Can't find command `#{command_name}`. Please check the command name and try again.\n\n" end diff --git a/test/irb/command/test_custom_command.rb b/test/irb/command/test_custom_command.rb index 6642d2b16..934b6129b 100644 --- a/test/irb/command/test_custom_command.rb +++ b/test/irb/command/test_custom_command.rb @@ -123,5 +123,32 @@ def execute(*) assert_include(output, "2 FooBar executed") assert_include(output, "foobar_description") end + + def test_no_meta_command_also_works + write_ruby <<~RUBY + require "irb" + require "irb/command" + + class NoMetaCommand < IRB::Command::Base + def execute(*) + puts "This command does not override meta attributes" + nil + end + end + + IRB::Command.register(:no_meta, NoMetaCommand) + + binding.irb + RUBY + + output = run_ruby_file do + type "no_meta\n" + type "help no_meta\n" + type "exit" + end + + assert_include(output, "This command does not override meta attributes") + assert_not_include(output, "Maybe IRB bug") + end end end From 35f8991418adcf9a67050834b223b48e4ef0c72e Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Fri, 3 May 2024 23:00:30 +0100 Subject: [PATCH 2/2] Update test/irb/command/test_custom_command.rb --- test/irb/command/test_custom_command.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/irb/command/test_custom_command.rb b/test/irb/command/test_custom_command.rb index d944e5cc5..eac0bd349 100644 --- a/test/irb/command/test_custom_command.rb +++ b/test/irb/command/test_custom_command.rb @@ -126,7 +126,6 @@ def execute(*) def test_no_meta_command_also_works write_ruby <<~RUBY - require "irb" require "irb/command" class NoMetaCommand < IRB::Command::Base