summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-10 01:41:15 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-10 01:41:15 +0000
commit9fa668f34aa13367a9adc9903de9a8a782cf2910 (patch)
tree4bc408125fd68fff063f442bc44b9c4ddf9e1f40 /test
parent71935466b7d42eb883c76c472f07913dd85e550e (diff)
* ext/readline/readline.c (readline_attempted_completion_function):
empty completion result does not mean memory error. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34254 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/readline/test_readline.rb36
1 files changed, 24 insertions, 12 deletions
diff --git a/test/readline/test_readline.rb b/test/readline/test_readline.rb
index 0d5efeac01..4ef696f25f 100644
--- a/test/readline/test_readline.rb
+++ b/test/readline/test_readline.rb
@@ -85,9 +85,7 @@ class TestReadline < Test::Unit::TestCase
if !/EditLine/n.match(Readline::VERSION)
def test_readline
- stdin = Tempfile.new("test_readline_stdin")
- stdout = Tempfile.new("test_readline_stdout")
- begin
+ with_temp_stdio do |stdin, stdout|
stdin.write("hello\n")
stdin.close
stdout.close
@@ -114,9 +112,6 @@ class TestReadline < Test::Unit::TestCase
replace_stdio(stdin.path, stdout.path) { Readline.readline("> ") }
}.join
end
- ensure
- stdin.close(true)
- stdout.close(true)
end
end
@@ -130,9 +125,7 @@ class TestReadline < Test::Unit::TestCase
return
end
- stdin = Tempfile.new("test_readline_stdin")
- stdout = Tempfile.new("test_readline_stdout")
- begin
+ with_temp_stdio do |stdin, stdout|
actual_text = nil
actual_line_buffer = nil
actual_point = nil
@@ -176,9 +169,6 @@ class TestReadline < Test::Unit::TestCase
assert_equal(Encoding.find("locale"), Readline.line_buffer.encoding)
assert_equal(true, Readline.line_buffer.tainted?)
assert_equal(21, Readline.point)
- ensure
- stdin.close(true)
- stdout.close(true)
end
end
end
@@ -213,6 +203,19 @@ class TestReadline < Test::Unit::TestCase
end
end
+ def test_completion_proc_empty_result
+ with_temp_stdio do |stdin, stdout|
+ stdin.write("first\t")
+ stdin.flush
+ actual_text = nil
+ Readline.completion_proc = ->(text) {[]}
+ line = replace_stdio(stdin.path, stdout.path) {
+ Readline.readline("> ")
+ }
+ assert_equal("first", line)
+ end
+ end
+
def test_get_screen_size
begin
res = Readline.get_screen_size
@@ -336,6 +339,15 @@ 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
+ end
+
def get_default_internal_encoding
return Encoding.default_internal || Encoding.find("locale")
end