mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parent
98a346d065
commit
3864fbc6d8
3 changed files with 62 additions and 9 deletions
|
@ -9,12 +9,11 @@ module IRB
|
||||||
def execute
|
def execute
|
||||||
Class.new {
|
Class.new {
|
||||||
def inspect
|
def inspect
|
||||||
<<~EOM.chomp
|
str = "Ruby version: #{RUBY_VERSION}\n"
|
||||||
Ruby version: #{RUBY_VERSION}
|
str += "IRB version: #{IRB.version}\n"
|
||||||
IRB version: #{IRB.version}
|
str += "InputMethod: #{IRB.CurrentContext.io.inspect}\n"
|
||||||
InputMethod: #{IRB.CurrentContext.io.inspect}
|
str += ".irbrc path: #{IRB.rc_file}\n" if File.exist?(IRB.rc_file)
|
||||||
.irbrc path: #{IRB.rc_file}
|
str
|
||||||
EOM
|
|
||||||
end
|
end
|
||||||
alias_method :to_s, :inspect
|
alias_method :to_s, :inspect
|
||||||
}.new
|
}.new
|
||||||
|
|
|
@ -220,9 +220,11 @@ module IRB
|
||||||
|
|
||||||
# For debug message
|
# For debug message
|
||||||
def inspect
|
def inspect
|
||||||
inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
|
|
||||||
readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline'
|
readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline'
|
||||||
"ReadlineInputMethod with #{readline_impl} #{Readline::VERSION} and #{inputrc_path}"
|
str = "ReadlineInputMethod with #{readline_impl} #{Readline::VERSION}"
|
||||||
|
inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
|
||||||
|
str += " and #{inputrc_path}" if File.exist?(inputrc_path)
|
||||||
|
str
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
|
@ -323,12 +325,14 @@ module IRB
|
||||||
# For debug message
|
# For debug message
|
||||||
def inspect
|
def inspect
|
||||||
config = Reline::Config.new
|
config = Reline::Config.new
|
||||||
|
str = "ReidlineInputMethod with Reline #{Reline::VERSION}"
|
||||||
if config.respond_to?(:inputrc_path)
|
if config.respond_to?(:inputrc_path)
|
||||||
inputrc_path = config.inputrc_path
|
inputrc_path = config.inputrc_path
|
||||||
else
|
else
|
||||||
inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
|
inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
|
||||||
end
|
end
|
||||||
"ReidlineInputMethod with Reline #{Reline::VERSION} and #{inputrc_path}"
|
str += " and #{inputrc_path}" if File.exist?(inputrc_path)
|
||||||
|
str
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -60,5 +60,55 @@ module TestIRB
|
||||||
}x
|
}x
|
||||||
assert_match expected, irb.context.main.irb_info.to_s
|
assert_match expected, irb.context.main.irb_info.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_irb_info_multiline_without_rc_files
|
||||||
|
inputrc_backup = ENV["INPUTRC"]
|
||||||
|
ENV["INPUTRC"] = "unkown_inpurc"
|
||||||
|
ext_backup = IRB::IRBRC_EXT
|
||||||
|
IRB.__send__(:remove_const, :IRBRC_EXT)
|
||||||
|
IRB.const_set(:IRBRC_EXT, "unkown_ext")
|
||||||
|
IRB.setup(__FILE__, argv: [])
|
||||||
|
IRB.conf[:USE_MULTILINE] = true
|
||||||
|
IRB.conf[:USE_SINGLELINE] = false
|
||||||
|
workspace = IRB::WorkSpace.new(self)
|
||||||
|
irb = IRB::Irb.new(workspace)
|
||||||
|
IRB.conf[:MAIN_CONTEXT] = irb.context
|
||||||
|
expected = %r{
|
||||||
|
Ruby\sversion: .+\n
|
||||||
|
IRB\sversion:\sirb .+\n
|
||||||
|
InputMethod:\sReidlineInputMethod\swith\sReline\s[^ ]+(?!\sand\s.+)\n
|
||||||
|
\z
|
||||||
|
}x
|
||||||
|
assert_match expected, irb.context.main.irb_info.to_s
|
||||||
|
ensure
|
||||||
|
ENV["INPUTRC"] = inputrc_backup
|
||||||
|
IRB.__send__(:remove_const, :IRBRC_EXT)
|
||||||
|
IRB.const_set(:IRBRC_EXT, ext_backup)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_irb_info_singleline_without_rc_files
|
||||||
|
inputrc_backup = ENV["INPUTRC"]
|
||||||
|
ENV["INPUTRC"] = "unkown_inpurc"
|
||||||
|
ext_backup = IRB::IRBRC_EXT
|
||||||
|
IRB.__send__(:remove_const, :IRBRC_EXT)
|
||||||
|
IRB.const_set(:IRBRC_EXT, "unkown_ext")
|
||||||
|
IRB.setup(__FILE__, argv: [])
|
||||||
|
IRB.conf[:USE_MULTILINE] = false
|
||||||
|
IRB.conf[:USE_SINGLELINE] = true
|
||||||
|
workspace = IRB::WorkSpace.new(self)
|
||||||
|
irb = IRB::Irb.new(workspace)
|
||||||
|
IRB.conf[:MAIN_CONTEXT] = irb.context
|
||||||
|
expected = %r{
|
||||||
|
Ruby\sversion: .+\n
|
||||||
|
IRB\sversion:\sirb .+\n
|
||||||
|
InputMethod:\sReadlineInputMethod\swith\s[^ ]+\s[^ ]+(?!\sand\s.+)\n
|
||||||
|
\z
|
||||||
|
}x
|
||||||
|
assert_match expected, irb.context.main.irb_info.to_s
|
||||||
|
ensure
|
||||||
|
ENV["INPUTRC"] = inputrc_backup
|
||||||
|
IRB.__send__(:remove_const, :IRBRC_EXT)
|
||||||
|
IRB.const_set(:IRBRC_EXT, ext_backup)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue