diff options
Diffstat (limited to 'test/readline/test_readline.rb')
-rw-r--r-- | test/readline/test_readline.rb | 65 |
1 files changed, 31 insertions, 34 deletions
diff --git a/test/readline/test_readline.rb b/test/readline/test_readline.rb index 88ad10195b..a4c8e581a3 100644 --- a/test/readline/test_readline.rb +++ b/test/readline/test_readline.rb @@ -72,13 +72,13 @@ class TestReadline < Test::Unit::TestCase with_temp_stdio do |stdin, stdout| stdin.write("hello\n") stdin.close - stdout.close + stdout.flush line = replace_stdio(stdin.path, stdout.path) { Readline.readline("> ", true) } assert_equal("hello", line) assert_equal(true, line.tainted?) - stdout.open + stdout.rewind assert_equal("> ", stdout.read(2)) assert_equal(1, Readline::HISTORY.length) assert_equal("hello", Readline::HISTORY[0]) @@ -118,8 +118,8 @@ class TestReadline < Test::Unit::TestCase actual_point = Readline.point actual_line_buffer = Readline.line_buffer stdin.write(" finish\n") - stdin.close - stdout.close + stdin.flush + stdout.flush return ["complete"] } @@ -137,8 +137,8 @@ class TestReadline < Test::Unit::TestCase assert_equal(true, Readline.line_buffer.tainted?) assert_equal(22, Readline.point) - stdin.open - stdout.open + stdin.rewind + stdout.rewind stdin.write("first second\t") stdin.flush @@ -377,31 +377,29 @@ class TestReadline < Test::Unit::TestCase end if !/EditLine/n.match(Readline::VERSION) def test_modify_text_in_pre_input_hook - begin - stdin = Tempfile.new("readline_redisplay_stdin") - stdout = Tempfile.new("readline_redisplay_stdout") - stdin.write("world\n") - stdin.close - Readline.pre_input_hook = proc do - assert_equal("", Readline.line_buffer) - Readline.insert_text("hello ") - Readline.redisplay - end - replace_stdio(stdin.path, stdout.path) do - line = Readline.readline("> ") - assert_equal("hello world", line) - end - assert_equal("> hello world\n", stdout.read) - stdout.close - rescue NotImplementedError - ensure + with_temp_stdio {|stdin, stdout| begin - Readline.pre_input_hook = nil + stdin.write("world\n") + stdin.close + Readline.pre_input_hook = proc do + assert_equal("", Readline.line_buffer) + Readline.insert_text("hello ") + Readline.redisplay + end + replace_stdio(stdin.path, stdout.path) do + line = Readline.readline("> ") + assert_equal("hello world", line) + end + assert_equal("> hello world\n", stdout.read) + stdout.close rescue NotImplementedError + ensure + begin + Readline.pre_input_hook = nil + rescue NotImplementedError + end end - stdin.close(true) - stdout.close(true) - end + } end if !/EditLine|\A4\.3\z/n.match(Readline::VERSION) def test_input_metachar @@ -472,12 +470,11 @@ class TestReadline < Test::Unit::TestCase end def with_temp_stdio - stdin = Tempfile.new("test_readline_stdin") - stdout = Tempfile.new("test_readline_stdout") - yield stdin, stdout - ensure - stdin.close(true) if stdin - stdout.close(true) if stdout + Tempfile.create("test_readline_stdin") {|stdin| + Tempfile.create("test_readline_stdout") {|stdout| + yield stdin, stdout + } + } end def with_pipe |