Skip to content

Conversation

@st0012
Copy link
Member

@st0012 st0012 commented Nov 3, 2022

Because RelineInputMethod#initializes calls set_encoding, which changes stdio/out/err and Encoding's default encoding values, we need to make sure any test that directly or indirectly (e.g. through Context) initializes RelineInputMethod restores encodings.

ReadlineInputMethod also changes encodings but currently no tests cover it.

Because `RelineInputMethod#initializes` calls `set_encoding`, which
changes stdio/out/err and Encoding's default encoding values, we need to
make sure any test that directly or indirectly (e.g. through Context)
initializes `RelineInputMethod` restores encodings.

`ReadlineInputMethod` also changes encodings but currently no tests
cover it.
Since we now have a base TestCase, without_rdoc can just live there.
@st0012 st0012 force-pushed the restructure-tests branch from 2951a5e to c781820 Compare November 3, 2022 21:28
@st0012
Copy link
Member Author

st0012 commented Nov 3, 2022

FWIW, I also patched this locally to make sure nothing is missed:

--- a/test/irb/helper.rb
+++ b/test/irb/helper.rb
@@ -2,6 +2,15 @@ require "test/unit"

 module TestIRB
   class TestCase < Test::Unit::TestCase
+    def teardown
+      assert_equal(Encoding.default_external, STDIN.external_encoding)
+      assert_equal(nil, STDIN.internal_encoding)
+      assert_equal(nil, STDOUT.external_encoding)
+      assert_equal(nil, STDOUT.internal_encoding)
+      assert_equal(nil, STDERR.external_encoding)
+      assert_equal(nil, STDERR.internal_encoding)
+    end
+

Copy link
Member

@k0kubun k0kubun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this will reduce the number of future problems in encoding.

@k0kubun k0kubun merged commit c2874ec into ruby:master Nov 3, 2022
matzbot pushed a commit to ruby/ruby that referenced this pull request Nov 3, 2022
conveniently
(ruby/irb#429)

* Create a base TestIRB::TestCase class

* Save/restore encodings for tests that initializes InputMethod classes

Because `RelineInputMethod#initializes` calls `set_encoding`, which
changes stdio/out/err and Encoding's default encoding values, we need to
make sure any test that directly or indirectly (e.g. through Context)
initializes `RelineInputMethod` restores encodings.

`ReadlineInputMethod` also changes encodings but currently no tests
cover it.

* Remove unnecessary TestHelper module

Since we now have a base TestCase, without_rdoc can just live there.

ruby/irb@c2874ec121
@st0012 st0012 deleted the restructure-tests branch November 3, 2022 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants