mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Reline: Fix changed test results due to change to UTF-8 on Windows
In commit f8ea2860b0
the Reline encoding
for native windows console was changed to hardcoded UTF-8.
This caused failures in reline and readline tests, but they were hidden,
because parallel ruby tests incorrectly used Reline::ANSI as IOGate.
Tests failures were raised in single process mode, but not with -j switch.
This patch corrects encodings on native Windows console.
This commit is contained in:
parent
d1166c6d39
commit
b0ca1fc21b
Notes:
git
2020-01-21 21:27:29 +09:00
4 changed files with 38 additions and 14 deletions
|
@ -238,7 +238,7 @@ module BasetestReadline
|
|||
append_character = Readline.completion_append_character
|
||||
Readline.completion_append_character = ""
|
||||
completion_case_fold = Readline.completion_case_fold
|
||||
locale = Encoding.find("locale")
|
||||
locale = get_default_internal_encoding
|
||||
if locale == Encoding::UTF_8
|
||||
enc1 = Encoding::EUC_JP
|
||||
else
|
||||
|
@ -545,7 +545,7 @@ module BasetestReadline
|
|||
saved_completer_quote_characters = Readline.completer_quote_characters
|
||||
saved_completer_word_break_characters = Readline.completer_word_break_characters
|
||||
return unless Readline.respond_to?(:quoting_detection_proc=)
|
||||
unless Encoding.find("locale") == Encoding::UTF_8
|
||||
unless Encoding.find("external") == Encoding::UTF_8
|
||||
return if assert_under_utf8
|
||||
skip 'this test needs UTF-8 locale'
|
||||
end
|
||||
|
@ -595,7 +595,7 @@ module BasetestReadline
|
|||
Readline.output = null
|
||||
Readline.completion_proc = ->(text) do
|
||||
['abcde', 'abc12'].map { |i|
|
||||
i.encode(Encoding.default_external)
|
||||
i.encode(get_default_internal_encoding)
|
||||
}
|
||||
end
|
||||
w.write("a\t\n")
|
||||
|
@ -620,7 +620,7 @@ module BasetestReadline
|
|||
Readline.completion_append_character = '!'
|
||||
Readline.completion_proc = ->(text) do
|
||||
['abcde'].map { |i|
|
||||
i.encode(Encoding.default_external)
|
||||
i.encode(get_default_internal_encoding)
|
||||
}
|
||||
end
|
||||
w.write("a\t\n")
|
||||
|
@ -790,4 +790,12 @@ class TestRelineAsReadline < Test::Unit::TestCase
|
|||
use_lib_reline
|
||||
super
|
||||
end
|
||||
|
||||
def get_default_internal_encoding
|
||||
if RUBY_PLATFORM =~ /mswin|mingw/
|
||||
Encoding.default_internal || Encoding::UTF_8
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -275,4 +275,12 @@ class TestRelineAsReadlineHistory < Test::Unit::TestCase
|
|||
use_lib_reline
|
||||
super
|
||||
end
|
||||
|
||||
def get_default_internal_encoding
|
||||
if RUBY_PLATFORM =~ /mswin|mingw/
|
||||
Encoding.default_internal || Encoding::UTF_8
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -268,6 +268,10 @@ class Reline::History::Test < Reline::TestCase
|
|||
end
|
||||
|
||||
def get_default_internal_encoding
|
||||
return Encoding.default_internal || Encoding.find("locale")
|
||||
if RUBY_PLATFORM =~ /mswin|mingw/
|
||||
Encoding.default_internal || Encoding::UTF_8
|
||||
else
|
||||
Encoding.default_internal || Encoding.find("locale")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,15 +21,15 @@ class Reline::Test < Reline::TestCase
|
|||
|
||||
Reline.completion_append_character = "a".encode(Encoding::ASCII)
|
||||
assert_equal("a", Reline.completion_append_character)
|
||||
assert_equal(Encoding::default_external, Reline.completion_append_character.encoding)
|
||||
assert_equal(get_reline_encoding, Reline.completion_append_character.encoding)
|
||||
|
||||
Reline.completion_append_character = "ba".encode(Encoding::ASCII)
|
||||
assert_equal("b", Reline.completion_append_character)
|
||||
assert_equal(Encoding::default_external, Reline.completion_append_character.encoding)
|
||||
assert_equal(get_reline_encoding, Reline.completion_append_character.encoding)
|
||||
|
||||
Reline.completion_append_character = "cba".encode(Encoding::ASCII)
|
||||
assert_equal("c", Reline.completion_append_character)
|
||||
assert_equal(Encoding::default_external, Reline.completion_append_character.encoding)
|
||||
assert_equal(get_reline_encoding, Reline.completion_append_character.encoding)
|
||||
|
||||
Reline.completion_append_character = nil
|
||||
assert_equal(nil, Reline.completion_append_character)
|
||||
|
@ -40,7 +40,7 @@ class Reline::Test < Reline::TestCase
|
|||
|
||||
Reline.basic_word_break_characters = "[".encode(Encoding::ASCII)
|
||||
assert_equal("[", Reline.basic_word_break_characters)
|
||||
assert_equal(Encoding::default_external, Reline.basic_word_break_characters.encoding)
|
||||
assert_equal(get_reline_encoding, Reline.basic_word_break_characters.encoding)
|
||||
end
|
||||
|
||||
def test_completer_word_break_characters
|
||||
|
@ -48,7 +48,7 @@ class Reline::Test < Reline::TestCase
|
|||
|
||||
Reline.completer_word_break_characters = "[".encode(Encoding::ASCII)
|
||||
assert_equal("[", Reline.completer_word_break_characters)
|
||||
assert_equal(Encoding::default_external, Reline.completer_word_break_characters.encoding)
|
||||
assert_equal(get_reline_encoding, Reline.completer_word_break_characters.encoding)
|
||||
end
|
||||
|
||||
def test_basic_quote_characters
|
||||
|
@ -56,7 +56,7 @@ class Reline::Test < Reline::TestCase
|
|||
|
||||
Reline.basic_quote_characters = "`".encode(Encoding::ASCII)
|
||||
assert_equal("`", Reline.basic_quote_characters)
|
||||
assert_equal(Encoding::default_external, Reline.basic_quote_characters.encoding)
|
||||
assert_equal(get_reline_encoding, Reline.basic_quote_characters.encoding)
|
||||
end
|
||||
|
||||
def test_completer_quote_characters
|
||||
|
@ -64,7 +64,7 @@ class Reline::Test < Reline::TestCase
|
|||
|
||||
Reline.completer_quote_characters = "`".encode(Encoding::ASCII)
|
||||
assert_equal("`", Reline.completer_quote_characters)
|
||||
assert_equal(Encoding::default_external, Reline.completer_quote_characters.encoding)
|
||||
assert_equal(get_reline_encoding, Reline.completer_quote_characters.encoding)
|
||||
end
|
||||
|
||||
def test_filename_quote_characters
|
||||
|
@ -72,7 +72,7 @@ class Reline::Test < Reline::TestCase
|
|||
|
||||
Reline.filename_quote_characters = "\'".encode(Encoding::ASCII)
|
||||
assert_equal("\'", Reline.filename_quote_characters)
|
||||
assert_equal(Encoding::default_external, Reline.filename_quote_characters.encoding)
|
||||
assert_equal(get_reline_encoding, Reline.filename_quote_characters.encoding)
|
||||
end
|
||||
|
||||
def test_special_prefixes
|
||||
|
@ -80,7 +80,7 @@ class Reline::Test < Reline::TestCase
|
|||
|
||||
Reline.special_prefixes = "\'".encode(Encoding::ASCII)
|
||||
assert_equal("\'", Reline.special_prefixes)
|
||||
assert_equal(Encoding::default_external, Reline.special_prefixes.encoding)
|
||||
assert_equal(get_reline_encoding, Reline.special_prefixes.encoding)
|
||||
end
|
||||
|
||||
def test_completion_case_fold
|
||||
|
@ -267,4 +267,8 @@ class Reline::Test < Reline::TestCase
|
|||
def test_may_req_ambiguous_char_width
|
||||
# TODO in Reline::Core
|
||||
end
|
||||
|
||||
def get_reline_encoding
|
||||
RUBY_PLATFORM =~ /mswin|mingw/ ? Encoding::UTF_8 : Encoding::default_external
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue