Skip to content

Commit 7f385bc

Browse files
authored
Improve history test's encoding setting (#1022)
* improve history test's encoding setting * fix missing locale error for ci and refactoring
1 parent 3da04b9 commit 7f385bc

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

test/irb/test_history.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@
1010
module TestIRB
1111
class HistoryTest < TestCase
1212
def setup
13+
@conf_backup = IRB.conf.dup
1314
@original_verbose, $VERBOSE = $VERBOSE, nil
1415
@tmpdir = Dir.mktmpdir("test_irb_history_")
1516
setup_envs(home: @tmpdir)
16-
@backup_default_external = Encoding.default_external
17+
IRB.conf[:LC_MESSAGES] = IRB::Locale.new
18+
save_encodings
1719
IRB.instance_variable_set(:@existing_rc_name_generators, nil)
1820
end
1921

2022
def teardown
23+
IRB.conf.replace(@conf_backup)
2124
IRB.instance_variable_set(:@existing_rc_name_generators, nil)
2225
teardown_envs
23-
Encoding.default_external = @backup_default_external
26+
restore_encodings
2427
$VERBOSE = @original_verbose
2528
FileUtils.rm_rf(@tmpdir)
2629
end
@@ -146,7 +149,6 @@ def test_history_concurrent_use_readline
146149
end
147150

148151
def test_history_concurrent_use_not_present
149-
IRB.conf[:LC_MESSAGES] = IRB::Locale.new
150152
IRB.conf[:SAVE_HISTORY] = 1
151153
io = TestInputMethodWithRelineHistory.new
152154
io.class::HISTORY.clear
@@ -163,9 +165,9 @@ def test_history_concurrent_use_not_present
163165

164166
def test_history_different_encodings
165167
IRB.conf[:SAVE_HISTORY] = 2
166-
Encoding.default_external = Encoding::US_ASCII
167-
locale = IRB::Locale.new("en_US.ASCII")
168-
assert_history(<<~EXPECTED_HISTORY.encode(Encoding::US_ASCII), <<~INITIAL_HISTORY.encode(Encoding::UTF_8), <<~INPUT, locale: locale)
168+
IRB.conf[:LC_MESSAGES] = IRB::Locale.new("en_US.ASCII")
169+
IRB.__send__(:set_encoding, Encoding::US_ASCII.name, override: false)
170+
assert_history(<<~EXPECTED_HISTORY.encode(Encoding::US_ASCII), <<~INITIAL_HISTORY.encode(Encoding::UTF_8), <<~INPUT)
169171
????
170172
exit
171173
EXPECTED_HISTORY
@@ -234,8 +236,7 @@ def history_concurrent_use_for_input_method(input_method)
234236
end
235237
end
236238

237-
def assert_history(expected_history, initial_irb_history, input, input_method = TestInputMethodWithRelineHistory, locale: IRB::Locale.new)
238-
IRB.conf[:LC_MESSAGES] = locale
239+
def assert_history(expected_history, initial_irb_history, input, input_method = TestInputMethodWithRelineHistory)
239240
actual_history = nil
240241
history_file = IRB.rc_file("_history")
241242
ENV["HOME"] = @tmpdir

0 commit comments

Comments
 (0)