-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 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 for helper method 'conf' is not supported") | ||
assert_not_include(out, "Maybe IRB bug!") | ||
end | ||
|
||
def test_incorrect_alias_triggers_warning | ||
out = run_ruby_file do | ||
type "f" | ||
type "exit" | ||
end | ||
assert_include(out, "Command 'foo' does not exist") | ||
assert_not_include(out, "Maybe IRB bug!") | ||
end | ||
end | ||
end |