From 99cabd0453c5f5bdb54e71c59b3859af73c10171 Mon Sep 17 00:00:00 2001 From: monkeyWzr Date: Sun, 20 Oct 2024 01:09:09 +0900 Subject: [PATCH 1/2] improve history test's encoding setting --- test/irb/test_history.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/irb/test_history.rb b/test/irb/test_history.rb index 791eef1ac..71de0b577 100644 --- a/test/irb/test_history.rb +++ b/test/irb/test_history.rb @@ -10,17 +10,19 @@ module TestIRB class HistoryTest < TestCase def setup + @conf_backup = IRB.conf.dup @original_verbose, $VERBOSE = $VERBOSE, nil @tmpdir = Dir.mktmpdir("test_irb_history_") setup_envs(home: @tmpdir) - @backup_default_external = Encoding.default_external + save_encodings IRB.instance_variable_set(:@existing_rc_name_generators, nil) end def teardown + IRB.conf.replace(@conf_backup) IRB.instance_variable_set(:@existing_rc_name_generators, nil) teardown_envs - Encoding.default_external = @backup_default_external + restore_encodings $VERBOSE = @original_verbose FileUtils.rm_rf(@tmpdir) end @@ -163,7 +165,7 @@ def test_history_concurrent_use_not_present def test_history_different_encodings IRB.conf[:SAVE_HISTORY] = 2 - Encoding.default_external = Encoding::US_ASCII + IRB.__send__(:set_encoding, Encoding::US_ASCII.name) locale = IRB::Locale.new("en_US.ASCII") assert_history(<<~EXPECTED_HISTORY.encode(Encoding::US_ASCII), <<~INITIAL_HISTORY.encode(Encoding::UTF_8), <<~INPUT, locale: locale) ???? From 3476eefc617bd5056ce6ef85d9d8e407cdf552a2 Mon Sep 17 00:00:00 2001 From: monkeyWzr Date: Sun, 20 Oct 2024 01:35:37 +0900 Subject: [PATCH 2/2] fix missing locale error for ci and refactoring --- test/irb/test_history.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/irb/test_history.rb b/test/irb/test_history.rb index 71de0b577..15c16ed89 100644 --- a/test/irb/test_history.rb +++ b/test/irb/test_history.rb @@ -14,6 +14,7 @@ def setup @original_verbose, $VERBOSE = $VERBOSE, nil @tmpdir = Dir.mktmpdir("test_irb_history_") setup_envs(home: @tmpdir) + IRB.conf[:LC_MESSAGES] = IRB::Locale.new save_encodings IRB.instance_variable_set(:@existing_rc_name_generators, nil) end @@ -148,7 +149,6 @@ def test_history_concurrent_use_readline end def test_history_concurrent_use_not_present - IRB.conf[:LC_MESSAGES] = IRB::Locale.new IRB.conf[:SAVE_HISTORY] = 1 io = TestInputMethodWithRelineHistory.new io.class::HISTORY.clear @@ -165,9 +165,9 @@ def test_history_concurrent_use_not_present def test_history_different_encodings IRB.conf[:SAVE_HISTORY] = 2 - IRB.__send__(:set_encoding, Encoding::US_ASCII.name) - locale = IRB::Locale.new("en_US.ASCII") - assert_history(<<~EXPECTED_HISTORY.encode(Encoding::US_ASCII), <<~INITIAL_HISTORY.encode(Encoding::UTF_8), <<~INPUT, locale: locale) + IRB.conf[:LC_MESSAGES] = IRB::Locale.new("en_US.ASCII") + IRB.__send__(:set_encoding, Encoding::US_ASCII.name, override: false) + assert_history(<<~EXPECTED_HISTORY.encode(Encoding::US_ASCII), <<~INITIAL_HISTORY.encode(Encoding::UTF_8), <<~INPUT) ???? exit EXPECTED_HISTORY @@ -236,8 +236,7 @@ def history_concurrent_use_for_input_method(input_method) end end - def assert_history(expected_history, initial_irb_history, input, input_method = TestInputMethodWithRelineHistory, locale: IRB::Locale.new) - IRB.conf[:LC_MESSAGES] = locale + def assert_history(expected_history, initial_irb_history, input, input_method = TestInputMethodWithRelineHistory) actual_history = nil history_file = IRB.rc_file("_history") ENV["HOME"] = @tmpdir