summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2026-06-29 20:11:37 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2026-06-29 20:53:09 +0900
commit4ef40e52b2b3f7d18634ff5476e5914d1e16e8b1 (patch)
tree3e70bb7dcb736612652df64784084044f7a57745
parentd3d4d3379ac473268a47299fea431766b033499a (diff)
Account for Windows console stdin encoding in test_stdinHEADmaster
On Windows default_external is UTF-8, but an interactive console STDIN is read in the locale (console code page) encoding and transcoded to the default external encoding. The previous assertion held only when stdin was redirected, so it failed on a console with a non-UTF-8 code page. Expect the locale encoding when stdin is a tty. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
-rw-r--r--test/ruby/test_io_m17n.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index 83d4fb0c7b..1736d01f78 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -404,8 +404,17 @@ EOT
end
def test_stdin
- assert_equal(Encoding.default_external, STDIN.external_encoding)
- assert_equal(nil, STDIN.internal_encoding)
+ encoding = Encoding.default_external
+ internal = nil
+ if /mswin|mingw/ =~ RUBY_PLATFORM and STDIN.tty?
+ # Interactive console input on Windows is read in the locale (console
+ # code page) encoding and transcoded to the default external encoding.
+ encoding = Encoding.find("locale")
+ internal = Encoding.default_internal || Encoding.default_external
+ internal = nil if internal == encoding
+ end
+ assert_equal(encoding, STDIN.external_encoding)
+ assert_equal(internal, STDIN.internal_encoding)
end
def test_stdout