summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2025-01-11 05:29:27 +0800
committergit <svn-admin@ruby-lang.org>2025-01-10 21:29:34 +0000
commit039446f601663ff7c25bbc2d46dc7de02ba640c2 (patch)
tree2607f65d29285923dcfa337367f03cf5857e2ea9 /test
parent4a2702dafb0852d7a7575fd4c7717402f02ccc25 (diff)
[ruby/irb] Gracefully handle incorrect command aliases
(https://github.com/ruby/irb/pull/1059) * Gracefully handle incorrect command aliases Even if the aliased target is a helper method or does not exist, IRB should not crash. This commit warns users in such cases and treat the input as normal expression. * Streamline command parsing and introduce warnings for incorrect command aliases https://github.com/ruby/irb/commit/9fc14eb74b
Diffstat (limited to 'test')
-rw-r--r--test/irb/command/test_command_aliasing.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/irb/command/test_command_aliasing.rb b/test/irb/command/test_command_aliasing.rb
new file mode 100644
index 0000000000..4ecc88c0aa
--- /dev/null
+++ b/test/irb/command/test_command_aliasing.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+require "tempfile"
+require_relative "../helper"
+
+module TestIRB
+ class CommandAliasingTest < IntegrationTestCase
+ def setup
+ super
+ write_rc <<~RUBY
+ IRB.conf[:COMMAND_ALIASES] = {
+ :c => :conf, # alias to helper method
+ :f => :foo
+ }
+ RUBY
+
+ write_ruby <<~'RUBY'
+ binding.irb
+ RUBY
+ end
+
+ def test_aliasing_to_helper_method_triggers_warning
+ out = run_ruby_file do
+ type "c"
+ type "exit"
+ end
+ assert_include(out, "Using command alias `c` for helper method `conf` is not supported.")
+ assert_not_include(out, "Maybe IRB bug!")
+ end
+
+ def test_alias_to_non_existent_command_triggers_warning
+ message = "You're trying to use command alias `f` for command `foo`, but `foo` does not exist."
+ out = run_ruby_file do
+ type "f"
+ type "exit"
+ end
+ assert_include(out, message)
+ assert_not_include(out, "Maybe IRB bug!")
+
+ # Local variables take precedence over command aliases
+ out = run_ruby_file do
+ type "f = 123"
+ type "f"
+ type "exit"
+ end
+ assert_not_include(out, message)
+ assert_not_include(out, "Maybe IRB bug!")
+ end
+ end
+end