mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/irb] Always add input method when calling Irb.new in tests
When passes input method as nil to Context.new through Irb.new, ReidlineInputMethod.new is executed and the global internal state of Reline is rewritten, therefore other tests are failed in the Ruby repository. This commit changes to use TestInputMethod. https://github.com/ruby/irb/commit/010dce9210
This commit is contained in:
parent
1cdecb4349
commit
a1938ec308
1 changed files with 44 additions and 46 deletions
|
@ -5,6 +5,32 @@ require "irb/extend-command"
|
||||||
|
|
||||||
module TestIRB
|
module TestIRB
|
||||||
class ExtendCommand < Test::Unit::TestCase
|
class ExtendCommand < Test::Unit::TestCase
|
||||||
|
class TestInputMethod < ::IRB::InputMethod
|
||||||
|
attr_reader :list, :line_no
|
||||||
|
|
||||||
|
def initialize(list = [])
|
||||||
|
super("test")
|
||||||
|
@line_no = 0
|
||||||
|
@list = list
|
||||||
|
end
|
||||||
|
|
||||||
|
def gets
|
||||||
|
@list[@line_no]&.tap {@line_no += 1}
|
||||||
|
end
|
||||||
|
|
||||||
|
def eof?
|
||||||
|
@line_no >= @list.size
|
||||||
|
end
|
||||||
|
|
||||||
|
def encoding
|
||||||
|
Encoding.default_external
|
||||||
|
end
|
||||||
|
|
||||||
|
def reset
|
||||||
|
@line_no = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@pwd = Dir.pwd
|
@pwd = Dir.pwd
|
||||||
@tmpdir = File.join(Dir.tmpdir, "test_reline_config_#{$$}")
|
@tmpdir = File.join(Dir.tmpdir, "test_reline_config_#{$$}")
|
||||||
|
@ -44,12 +70,12 @@ module TestIRB
|
||||||
IRB.conf[:USE_SINGLELINE] = false
|
IRB.conf[:USE_SINGLELINE] = false
|
||||||
IRB.conf[:VERBOSE] = false
|
IRB.conf[:VERBOSE] = false
|
||||||
workspace = IRB::WorkSpace.new(self)
|
workspace = IRB::WorkSpace.new(self)
|
||||||
irb = IRB::Irb.new(workspace)
|
irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
|
||||||
IRB.conf[:MAIN_CONTEXT] = irb.context
|
IRB.conf[:MAIN_CONTEXT] = irb.context
|
||||||
expected = %r{
|
expected = %r{
|
||||||
Ruby\sversion: .+\n
|
Ruby\sversion: .+\n
|
||||||
IRB\sversion:\sirb .+\n
|
IRB\sversion:\sirb .+\n
|
||||||
InputMethod:\sReidlineInputMethod\swith\sReline .+ and .+\n
|
InputMethod:\sAbstract\sInputMethod\n
|
||||||
\.irbrc\spath: .+\n
|
\.irbrc\spath: .+\n
|
||||||
RUBY_PLATFORM: .+
|
RUBY_PLATFORM: .+
|
||||||
}x
|
}x
|
||||||
|
@ -64,12 +90,12 @@ module TestIRB
|
||||||
IRB.conf[:USE_SINGLELINE] = true
|
IRB.conf[:USE_SINGLELINE] = true
|
||||||
IRB.conf[:VERBOSE] = false
|
IRB.conf[:VERBOSE] = false
|
||||||
workspace = IRB::WorkSpace.new(self)
|
workspace = IRB::WorkSpace.new(self)
|
||||||
irb = IRB::Irb.new(workspace)
|
irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
|
||||||
IRB.conf[:MAIN_CONTEXT] = irb.context
|
IRB.conf[:MAIN_CONTEXT] = irb.context
|
||||||
expected = %r{
|
expected = %r{
|
||||||
Ruby\sversion: .+\n
|
Ruby\sversion: .+\n
|
||||||
IRB\sversion:\sirb .+\n
|
IRB\sversion:\sirb .+\n
|
||||||
InputMethod:\sReadlineInputMethod\swith .+ and .+\n
|
InputMethod:\sAbstract\sInputMethod\n
|
||||||
\.irbrc\spath: .+\n
|
\.irbrc\spath: .+\n
|
||||||
RUBY_PLATFORM: .+
|
RUBY_PLATFORM: .+
|
||||||
}x
|
}x
|
||||||
|
@ -87,12 +113,12 @@ module TestIRB
|
||||||
IRB.conf[:USE_SINGLELINE] = false
|
IRB.conf[:USE_SINGLELINE] = false
|
||||||
IRB.conf[:VERBOSE] = false
|
IRB.conf[:VERBOSE] = false
|
||||||
workspace = IRB::WorkSpace.new(self)
|
workspace = IRB::WorkSpace.new(self)
|
||||||
irb = IRB::Irb.new(workspace)
|
irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
|
||||||
IRB.conf[:MAIN_CONTEXT] = irb.context
|
IRB.conf[:MAIN_CONTEXT] = irb.context
|
||||||
expected = %r{
|
expected = %r{
|
||||||
Ruby\sversion: .+\n
|
Ruby\sversion: .+\n
|
||||||
IRB\sversion:\sirb .+\n
|
IRB\sversion:\sirb .+\n
|
||||||
InputMethod:\sReidlineInputMethod\swith\sReline\s[^ ]+(?!\sand\s.+)\n
|
InputMethod:\sAbstract\sInputMethod\n
|
||||||
RUBY_PLATFORM: .+\n
|
RUBY_PLATFORM: .+\n
|
||||||
\z
|
\z
|
||||||
}x
|
}x
|
||||||
|
@ -114,12 +140,12 @@ module TestIRB
|
||||||
IRB.conf[:USE_SINGLELINE] = true
|
IRB.conf[:USE_SINGLELINE] = true
|
||||||
IRB.conf[:VERBOSE] = false
|
IRB.conf[:VERBOSE] = false
|
||||||
workspace = IRB::WorkSpace.new(self)
|
workspace = IRB::WorkSpace.new(self)
|
||||||
irb = IRB::Irb.new(workspace)
|
irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
|
||||||
IRB.conf[:MAIN_CONTEXT] = irb.context
|
IRB.conf[:MAIN_CONTEXT] = irb.context
|
||||||
expected = %r{
|
expected = %r{
|
||||||
Ruby\sversion: .+\n
|
Ruby\sversion: .+\n
|
||||||
IRB\sversion:\sirb .+\n
|
IRB\sversion:\sirb .+\n
|
||||||
InputMethod:\sReadlineInputMethod\swith\s(?~.*\sand\s.+)\n
|
InputMethod:\sAbstract\sInputMethod\n
|
||||||
RUBY_PLATFORM: .+\n
|
RUBY_PLATFORM: .+\n
|
||||||
\z
|
\z
|
||||||
}x
|
}x
|
||||||
|
@ -130,32 +156,6 @@ module TestIRB
|
||||||
IRB.const_set(:IRBRC_EXT, ext_backup)
|
IRB.const_set(:IRBRC_EXT, ext_backup)
|
||||||
end
|
end
|
||||||
|
|
||||||
class TestInputMethod < ::IRB::InputMethod
|
|
||||||
attr_reader :list, :line_no
|
|
||||||
|
|
||||||
def initialize(list = [])
|
|
||||||
super("test")
|
|
||||||
@line_no = 0
|
|
||||||
@list = list
|
|
||||||
end
|
|
||||||
|
|
||||||
def gets
|
|
||||||
@list[@line_no]&.tap {@line_no += 1}
|
|
||||||
end
|
|
||||||
|
|
||||||
def eof?
|
|
||||||
@line_no >= @list.size
|
|
||||||
end
|
|
||||||
|
|
||||||
def encoding
|
|
||||||
Encoding.default_external
|
|
||||||
end
|
|
||||||
|
|
||||||
def reset
|
|
||||||
@line_no = 0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_measure
|
def test_measure
|
||||||
IRB.init_config(nil)
|
IRB.init_config(nil)
|
||||||
IRB.conf[:PROMPT] = {
|
IRB.conf[:PROMPT] = {
|
||||||
|
@ -376,15 +376,14 @@ module TestIRB
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ls
|
def test_ls
|
||||||
IRB.init_config(nil)
|
|
||||||
workspace = IRB::WorkSpace.new(self)
|
|
||||||
IRB.conf[:VERBOSE] = false
|
|
||||||
irb = IRB::Irb.new(workspace)
|
|
||||||
IRB.conf[:MAIN_CONTEXT] = irb.context
|
|
||||||
input = TestInputMethod.new([
|
input = TestInputMethod.new([
|
||||||
"ls Object.new.tap { |o| o.instance_variable_set(:@a, 1) }\n",
|
"ls Object.new.tap { |o| o.instance_variable_set(:@a, 1) }\n",
|
||||||
])
|
])
|
||||||
irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
|
IRB.init_config(nil)
|
||||||
|
workspace = IRB::WorkSpace.new(self)
|
||||||
|
irb = IRB::Irb.new(workspace, input)
|
||||||
|
IRB.conf[:VERBOSE] = false
|
||||||
|
IRB.conf[:MAIN_CONTEXT] = irb.context
|
||||||
irb.context.return_format = "=> %s\n"
|
irb.context.return_format = "=> %s\n"
|
||||||
out, err = capture_output do
|
out, err = capture_output do
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
|
@ -394,15 +393,14 @@ module TestIRB
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_whereami
|
def test_whereami
|
||||||
IRB.init_config(nil)
|
|
||||||
workspace = IRB::WorkSpace.new(self)
|
|
||||||
IRB.conf[:VERBOSE] = false
|
|
||||||
irb = IRB::Irb.new(workspace)
|
|
||||||
IRB.conf[:MAIN_CONTEXT] = irb.context
|
|
||||||
input = TestInputMethod.new([
|
input = TestInputMethod.new([
|
||||||
"whereami\n",
|
"whereami\n",
|
||||||
])
|
])
|
||||||
irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
|
IRB.init_config(nil)
|
||||||
|
workspace = IRB::WorkSpace.new(self)
|
||||||
|
irb = IRB::Irb.new(workspace, input)
|
||||||
|
IRB.conf[:VERBOSE] = false
|
||||||
|
IRB.conf[:MAIN_CONTEXT] = irb.context
|
||||||
irb.context.return_format = "=> %s\n"
|
irb.context.return_format = "=> %s\n"
|
||||||
out, err = capture_output do
|
out, err = capture_output do
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
|
|
Loading…
Reference in a new issue