From a510175e8f95f4d8f7bc56c184996526b530bf94 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Sat, 4 May 2024 07:08:44 +0900 Subject: [PATCH] [ruby/irb] Avoid raising errors while running help for custom commands (https://github.com/ruby/irb/pull/944) * 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 * Update test/irb/command/test_custom_command.rb --------- https://github.com/ruby/irb/commit/c8bba9f8dc Co-authored-by: Stan Lo --- lib/irb/command/help.rb | 2 +- test/irb/command/test_custom_command.rb | 26 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/irb/command/help.rb b/lib/irb/command/help.rb index 1ed7a7707c..995b81bf11 100644 --- a/lib/irb/command/help.rb +++ b/lib/irb/command/help.rb @@ -12,7 +12,7 @@ module IRB 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 16800db2c8..eac0bd3495 100644 --- a/test/irb/command/test_custom_command.rb +++ b/test/irb/command/test_custom_command.rb @@ -123,5 +123,31 @@ module TestIRB assert_include(output, "2 FooBar executed") assert_include(output, "foobar_description") end + + def test_no_meta_command_also_works + write_ruby <<~RUBY + 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