mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Add new test for Reline within pipe
This commit is contained in:
parent
28e01f006d
commit
e360688c4d
3 changed files with 30 additions and 0 deletions
|
@ -220,6 +220,8 @@ module Reline
|
|||
private_class_method def self.test_mode
|
||||
remove_const('IOGate') if const_defined?('IOGate')
|
||||
const_set('IOGate', Reline::GeneralIO)
|
||||
@@config.instance_variable_set(:@test_mode, true)
|
||||
@@config.reset
|
||||
end
|
||||
|
||||
def self.input=(val)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
require 'pathname'
|
||||
|
||||
class Reline::Config
|
||||
attr_reader :test_mode
|
||||
|
||||
DEFAULT_PATH = Pathname.new(Dir.home).join('.inputrc')
|
||||
|
||||
VARIABLE_NAMES = %w{
|
||||
|
@ -48,6 +50,7 @@ class Reline::Config
|
|||
@key_actors[:vi_command] = Reline::KeyActor::ViCommand.new
|
||||
@history_size = 500
|
||||
@keyseq_timeout = 500
|
||||
@test_mode = false
|
||||
end
|
||||
|
||||
def reset
|
||||
|
@ -75,6 +78,7 @@ class Reline::Config
|
|||
end
|
||||
|
||||
def read(file = DEFAULT_PATH)
|
||||
return if @test_mode
|
||||
file = ENV['INPUTRC'] if ENV['INPUTRC']
|
||||
begin
|
||||
if file.respond_to?(:readlines)
|
||||
|
|
24
test/reline/test_within_pipe.rb
Normal file
24
test/reline/test_within_pipe.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
require_relative 'helper'
|
||||
|
||||
class Reline::WithinPipeTest < Reline::TestCase
|
||||
def setup
|
||||
Reline.send(:test_mode)
|
||||
@reader, @writer = IO.pipe((RELINE_TEST_ENCODING rescue Encoding.default_external))
|
||||
Reline.input = @reader
|
||||
@config = Reline.class_variable_get(:@@config)
|
||||
@line_editor = Reline.class_variable_get(:@@line_editor)
|
||||
end
|
||||
|
||||
def teardown
|
||||
Reline.input = STDIN
|
||||
Reline.output = STDOUT
|
||||
@reader.close
|
||||
@writer.close
|
||||
@config.reset
|
||||
end
|
||||
|
||||
def test_simple_input
|
||||
@writer.write("abc\n")
|
||||
assert_equal 'abc', Reline.readmultiline(&proc{ true })
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue