summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/reline.rb2
-rw-r--r--lib/reline/config.rb4
-rw-r--r--test/reline/test_within_pipe.rb24
3 files changed, 30 insertions, 0 deletions
diff --git a/lib/reline.rb b/lib/reline.rb
index 437cf45b57..2b21968371 100644
--- a/lib/reline.rb
+++ b/lib/reline.rb
@@ -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)
diff --git a/lib/reline/config.rb b/lib/reline/config.rb
index 6fdeb7006f..7639882027 100644
--- a/lib/reline/config.rb
+++ b/lib/reline/config.rb
@@ -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)
diff --git a/test/reline/test_within_pipe.rb b/test/reline/test_within_pipe.rb
new file mode 100644
index 0000000000..586e782be4
--- /dev/null
+++ b/test/reline/test_within_pipe.rb
@@ -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