diff options
author | aycabta <aycabta@gmail.com> | 2019-05-14 07:00:03 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2019-05-14 15:37:45 +0900 |
commit | c754e979d3eeca51f1b13778f19f347df3da656e (patch) | |
tree | e419285e513f2e33f40636e7e7925cc5c962e4b9 /test/readline/test_readline.rb | |
parent | 07e7ae9ed78d0891a1c4755e2faf3c8d15d95102 (diff) | |
download | ruby-c754e979d3eeca51f1b13778f19f347df3da656e.tar.gz |
Test ext/readline and lib/reline by test/readline
Diffstat (limited to 'test/readline/test_readline.rb')
-rw-r--r-- | test/readline/test_readline.rb | 224 |
1 files changed, 125 insertions, 99 deletions
diff --git a/test/readline/test_readline.rb b/test/readline/test_readline.rb index 8628e9d670..e8e5a5aec2 100644 --- a/test/readline/test_readline.rb +++ b/test/readline/test_readline.rb @@ -1,14 +1,10 @@ # frozen_string_literal: false -begin - require "readline" -rescue LoadError -else - require "test/unit" - require "tempfile" - require "timeout" -end +require_relative "helper" +require "test/unit" +require "tempfile" +require "timeout" -class TestReadline < Test::Unit::TestCase +module BasetestReadline INPUTRC = "INPUTRC" SAVED_ENV = %w[COLUMNS LINES] @@ -30,90 +26,91 @@ class TestReadline < Test::Unit::TestCase SAVED_ENV.each_with_index {|k, i| ENV[k] = @saved_env[i] } end - if !/EditLine/n.match(Readline::VERSION) - def test_readline - with_temp_stdio do |stdin, stdout| - stdin.write("hello\n") - stdin.close - stdout.flush - line = replace_stdio(stdin.path, stdout.path) { - Readline.readline("> ", true) - } - assert_equal("hello", line) - assert_equal(true, line.tainted?) - stdout.rewind - assert_equal("> ", stdout.read(2)) - assert_equal(1, Readline::HISTORY.length) - assert_equal("hello", Readline::HISTORY[0]) - Thread.start { - $SAFE = 1 - assert_raise(SecurityError) do - replace_stdio(stdin.path, stdout.path) do - Readline.readline("> ".taint) - end + def test_readline + skip "Skip Editline" if /EditLine/n.match(Readline::VERSION) + with_temp_stdio do |stdin, stdout| + stdin.write("hello\n") + stdin.close + stdout.flush + line = replace_stdio(stdin.path, stdout.path) { + Readline.readline("> ", true) + } + assert_equal("hello", line) + assert_equal(true, line.tainted?) + stdout.rewind + assert_equal("> ", stdout.read(2)) + assert_equal(1, Readline::HISTORY.length) + assert_equal("hello", Readline::HISTORY[0]) + Thread.start { + $SAFE = 1 + assert_raise(SecurityError) do + replace_stdio(stdin.path, stdout.path) do + Readline.readline("> ".taint) end - }.join - ensure - $SAFE = 0 - end + end + }.join + ensure + $SAFE = 0 end + end - # line_buffer - # point - def test_line_buffer__point - begin - Readline.line_buffer - Readline.point - rescue NotImplementedError - return - end + # line_buffer + # point + def test_line_buffer__point + skip "Skip Editline" if /EditLine/n.match(Readline::VERSION) + skip "GNU Readline has special behaviors" if defined?(Reline) and Readline == Reline + begin + Readline.line_buffer + Readline.point + rescue NotImplementedError + return + end - with_temp_stdio do |stdin, stdout| - actual_text = nil - actual_line_buffer = nil - actual_point = nil - Readline.completion_proc = ->(text) { - actual_text = text - actual_point = Readline.point - actual_line_buffer = Readline.line_buffer - stdin.write(" finish\n") - stdin.flush - stdout.flush - return ["complete"] - } - - stdin.write("first second\t") - stdin.flush - Readline.completion_append_character = " " - replace_stdio(stdin.path, stdout.path) { - Readline.readline("> ", false) - } - assert_equal("second", actual_text) - assert_equal("first second", actual_line_buffer) - assert_equal(12, actual_point) - assert_equal("first complete finish", Readline.line_buffer) - assert_equal(Encoding.find("locale"), Readline.line_buffer.encoding) - assert_equal(true, Readline.line_buffer.tainted?) - assert_equal(22, Readline.point) - - stdin.rewind - stdout.rewind - - stdin.write("first second\t") + with_temp_stdio do |stdin, stdout| + actual_text = nil + actual_line_buffer = nil + actual_point = nil + Readline.completion_proc = ->(text) { + actual_text = text + actual_point = Readline.point + actual_line_buffer = Readline.line_buffer + stdin.write(" finish\n") stdin.flush - Readline.completion_append_character = nil - replace_stdio(stdin.path, stdout.path) { - Readline.readline("> ", false) - } - assert_equal("second", actual_text) - assert_equal("first second", actual_line_buffer) - assert_equal(12, actual_point) - assert_equal("first complete finish", Readline.line_buffer) - assert_equal(Encoding.find("locale"), Readline.line_buffer.encoding) - assert_equal(true, Readline.line_buffer.tainted?) - assert_equal(21, Readline.point) - end - end if !defined?(Reline) or Readline != Reline + stdout.flush + return ["complete"] + } + + stdin.write("first second\t") + stdin.flush + Readline.completion_append_character = " " + replace_stdio(stdin.path, stdout.path) { + Readline.readline("> ", false) + } + assert_equal("second", actual_text) + assert_equal("first second", actual_line_buffer) + assert_equal(12, actual_point) + assert_equal("first complete finish", Readline.line_buffer) + assert_equal(Encoding.find("locale"), Readline.line_buffer.encoding) + assert_equal(true, Readline.line_buffer.tainted?) + assert_equal(22, Readline.point) + + stdin.rewind + stdout.rewind + + stdin.write("first second\t") + stdin.flush + Readline.completion_append_character = nil + replace_stdio(stdin.path, stdout.path) { + Readline.readline("> ", false) + } + assert_equal("second", actual_text) + assert_equal("first second", actual_line_buffer) + assert_equal(12, actual_point) + assert_equal("first complete finish", Readline.line_buffer) + assert_equal(Encoding.find("locale"), Readline.line_buffer.encoding) + assert_equal(true, Readline.line_buffer.tainted?) + assert_equal(21, Readline.point) + end end def test_input= @@ -147,6 +144,7 @@ class TestReadline < Test::Unit::TestCase end def test_completion_proc_empty_result + skip "Skip Editline" if /EditLine/n.match(Readline::VERSION) with_temp_stdio do |stdin, stdout| stdin.write("first\t") stdin.flush @@ -165,7 +163,7 @@ class TestReadline < Test::Unit::TestCase rescue NotimplementedError end end - end if !/EditLine/n.match(Readline::VERSION) + end def test_get_screen_size begin @@ -225,6 +223,7 @@ class TestReadline < Test::Unit::TestCase end def test_completion_encoding + skip "Skip Editline" if /EditLine/n.match(Readline::VERSION) bug5941 = '[Bug #5941]' append_character = Readline.completion_append_character Readline.completion_append_character = "" @@ -264,9 +263,10 @@ class TestReadline < Test::Unit::TestCase with_pipe {|r, w| w << "\t"} end ensure + return if /EditLine/n.match(Readline::VERSION) Readline.completion_case_fold = completion_case_fold Readline.completion_append_character = append_character - end if !/EditLine/n.match(Readline::VERSION) + end # basic_word_break_characters # completer_word_break_characters @@ -325,6 +325,7 @@ class TestReadline < Test::Unit::TestCase end def test_point + skip "Skip Editline" if /EditLine/n.match(Readline::VERSION) assert_equal(0, Readline.point) Readline.insert_text('12345') assert_equal(5, Readline.point) @@ -336,9 +337,10 @@ class TestReadline < Test::Unit::TestCase assert_equal('1234abc5', Readline.line_buffer) rescue NotImplementedError - end if !/EditLine/n.match(Readline::VERSION) + end def test_insert_text + skip "Skip Editline" if /EditLine/n.match(Readline::VERSION) str = "test_insert_text" assert_equal(0, Readline.point) assert_equal(Readline, Readline.insert_text(str)) @@ -366,9 +368,10 @@ class TestReadline < Test::Unit::TestCase Readline.delete_text assert_equal("", Readline.line_buffer) rescue NotImplementedError - end if !/EditLine/n.match(Readline::VERSION) + end def test_delete_text + skip "Skip Editline" if /EditLine/n.match(Readline::VERSION) str = "test_insert_text" assert_equal(0, Readline.point) assert_equal(Readline, Readline.insert_text(str)) @@ -385,9 +388,10 @@ class TestReadline < Test::Unit::TestCase assert_equal("", Readline.line_buffer) end rescue NotImplementedError - end if !/EditLine/n.match(Readline::VERSION) + end def test_modify_text_in_pre_input_hook + skip "Skip Editline" if /EditLine/n.match(Readline::VERSION) with_temp_stdio {|stdin, stdout| begin stdin.write("world\n") @@ -413,9 +417,10 @@ class TestReadline < Test::Unit::TestCase end end } - end if !/EditLine|\A4\.3\z/n.match(Readline::VERSION) + end def test_input_metachar + skip "Skip Editline" if /EditLine/n.match(Readline::VERSION) skip("Won't pass on mingw w/readline 7.0.005 [ruby-core:45682]") if mingw? bug6601 = '[ruby-core:45682]' Readline::HISTORY << "hello" @@ -427,11 +432,13 @@ class TestReadline < Test::Unit::TestCase assert_equal("hello", line, bug6601) ensure wo&.close + return if /EditLine/n.match(Readline::VERSION) Readline.delete_text Readline::HISTORY.clear - end if !/EditLine/n.match(Readline::VERSION) + end def test_input_metachar_multibyte + skip "Skip Editline" if /EditLine/n.match(Readline::VERSION) unless Encoding.find("locale") == Encoding::UTF_8 return if assert_under_utf8 skip 'this test needs UTF-8 locale' @@ -455,11 +462,13 @@ class TestReadline < Test::Unit::TestCase end end ensure + return if /EditLine/n.match(Readline::VERSION) Readline.delete_text Readline::HISTORY.clear - end if !/EditLine/n.match(Readline::VERSION) + end def test_refresh_line + skip "Only when refresh_line exists" unless Readline.respond_to?(:refresh_line) bug6232 = '[ruby-core:43957] [Bug #6232] refresh_line after set_screen_size' with_temp_stdio do |stdin, stdout| replace_stdio(stdin.path, stdout.path) do @@ -469,7 +478,7 @@ class TestReadline < Test::Unit::TestCase end; end end - end if Readline.respond_to?(:refresh_line) + end def test_setting_quoting_detection_proc return unless Readline.respond_to?(:quoting_detection_proc=) @@ -692,5 +701,22 @@ class TestReadline < Test::Unit::TestCase SRC return true end -end if defined?(::Readline) && !(/mswin|mingw/ =~ RUBY_PLATFORM && defined?(Reline) && Readline == Reline) -# skip on Windows now when using reline because it causes hang of whole tests +end + +class TestReadline < Test::Unit::TestCase + include BasetestReadline + + def setup + use_ext_readline + super + end +end if defined?(ReadlineSo) + +class TestRelineAsReadline < Test::Unit::TestCase + include BasetestReadline + + def setup + use_lib_reline + super + end +end |