[ruby/irb] Restore standard input/output encodings after input method tests

This commit is contained in:
Stan Lo 2022-10-24 17:32:58 +01:00 committed by git
parent 120b747b7d
commit abeef41c95

View File

@ -8,10 +8,22 @@ module TestIRB
def setup def setup
@conf_backup = IRB.conf.dup @conf_backup = IRB.conf.dup
IRB.conf[:LC_MESSAGES] = IRB::Locale.new IRB.conf[:LC_MESSAGES] = IRB::Locale.new
# RelineInputMethod#initialize calls IRB.set_encoding, which mutates standard input/output's encoding
# so we need to make sure we set them back
@original_encodings = {
STDIN => [STDIN.external_encoding, STDIN.internal_encoding],
STDOUT => [STDOUT.external_encoding, STDOUT.internal_encoding],
STDERR => [STDERR.external_encoding, STDERR.internal_encoding],
}
end end
def teardown def teardown
IRB.conf.replace(@conf_backup) IRB.conf.replace(@conf_backup)
@original_encodings.each do |io, (external_encoding, internal_encoding)|
io.set_encoding(external_encoding, internal_encoding)
end
end end
def test_initialization def test_initialization