diff options
author | Stan Lo <stan.lo@shopify.com> | 2022-10-24 17:32:58 +0100 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-10-24 17:02:34 +0000 |
commit | abeef41c9573b458dec1b960d4251a38aeaa8e03 (patch) | |
tree | 6ab83851ec769b6622e1d0054d3b5781afd7961b /test | |
parent | 120b747b7df25722c982ff4ba0f8be9a1463bd78 (diff) |
[ruby/irb] Restore standard input/output encodings after input method tests
Diffstat (limited to 'test')
-rw-r--r-- | test/irb/test_input_method.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/irb/test_input_method.rb b/test/irb/test_input_method.rb index 77f10774e9..b9832d39ed 100644 --- a/test/irb/test_input_method.rb +++ b/test/irb/test_input_method.rb @@ -8,10 +8,22 @@ module TestIRB def setup @conf_backup = IRB.conf.dup 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 def teardown IRB.conf.replace(@conf_backup) + + @original_encodings.each do |io, (external_encoding, internal_encoding)| + io.set_encoding(external_encoding, internal_encoding) + end end def test_initialization |