ruby-changes:59764
From: Lars <ko1@a...>
Date: Tue, 21 Jan 2020 21:27:29 +0900 (JST)
Subject: [ruby-changes:59764] b0ca1fc21b (master): Reline: Fix changed test results due to change to UTF-8 on Windows
https://git.ruby-lang.org/ruby.git/commit/?id=b0ca1fc21b From b0ca1fc21bbb9dac65a3b3f7b5935e691ece1501 Mon Sep 17 00:00:00 2001 From: Lars Kanis <lars@g...> Date: Sat, 18 Jan 2020 21:22:24 +0100 Subject: Reline: Fix changed test results due to change to UTF-8 on Windows In commit f8ea2860b0cac1aec79978e6c44168802958e8af 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. diff --git a/test/readline/test_readline.rb b/test/readline/test_readline.rb index b77e3a0..a4b7cb4 100644 --- a/test/readline/test_readline.rb +++ b/test/readline/test_readline.rb @@ -238,7 +238,7 @@ module BasetestReadline https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline.rb#L238 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 https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline.rb#L545 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 https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline.rb#L595 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 https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline.rb#L620 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 https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline.rb#L790 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 diff --git a/test/readline/test_readline_history.rb b/test/readline/test_readline_history.rb index 34ab745..509f1d6 100644 --- a/test/readline/test_readline_history.rb +++ b/test/readline/test_readline_history.rb @@ -275,4 +275,12 @@ class TestRelineAsReadlineHistory < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline_history.rb#L275 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 diff --git a/test/reline/test_history.rb b/test/reline/test_history.rb index 260b6e8..13d3d2f 100644 --- a/test/reline/test_history.rb +++ b/test/reline/test_history.rb @@ -268,6 +268,10 @@ class Reline::History::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_history.rb#L268 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 diff --git a/test/reline/test_reline.rb b/test/reline/test_reline.rb index 274f1aa..d6a6e21 100644 --- a/test/reline/test_reline.rb +++ b/test/reline/test_reline.rb @@ -21,15 +21,15 @@ class Reline::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_reline.rb#L21 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 https://github.com/ruby/ruby/blob/trunk/test/reline/test_reline.rb#L40 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 https://github.com/ruby/ruby/blob/trunk/test/reline/test_reline.rb#L48 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 https://github.com/ruby/ruby/blob/trunk/test/reline/test_reline.rb#L56 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 https://github.com/ruby/ruby/blob/trunk/test/reline/test_reline.rb#L64 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 https://github.com/ruby/ruby/blob/trunk/test/reline/test_reline.rb#L72 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 https://github.com/ruby/ruby/blob/trunk/test/reline/test_reline.rb#L80 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 https://github.com/ruby/ruby/blob/trunk/test/reline/test_reline.rb#L267 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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/