[前][次][番号順一覧][スレッド一覧]

ruby-changes:66746

From: aycabta <ko1@a...>
Date: Sun, 11 Jul 2021 06:12:23 +0900 (JST)
Subject: [ruby-changes:66746] 947d0198e0 (master): [ruby/irb] Show LANG and LC_ALL env by irb_info

https://git.ruby-lang.org/ruby.git/commit/?id=947d0198e0

From 947d0198e00b2ba991a566e503a66675de625c2f Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Sat, 10 Jul 2021 22:32:51 +0900
Subject: [ruby/irb] Show LANG and LC_ALL env by irb_info

Co-authored-by: Nobuyoshi Nakada <nobu@r...>

https://github.com/ruby/irb/commit/b431742430
---
 lib/irb/cmd/info.rb  |  2 ++
 test/irb/test_cmd.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/lib/irb/cmd/info.rb b/lib/irb/cmd/info.rb
index d122c88..a23d502 100644
--- a/lib/irb/cmd/info.rb
+++ b/lib/irb/cmd/info.rb
@@ -14,6 +14,8 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/cmd/info.rb#L14
             str += "InputMethod: #{IRB.CurrentContext.io.inspect}\n"
             str += ".irbrc path: #{IRB.rc_file}\n" if File.exist?(IRB.rc_file)
             str += "RUBY_PLATFORM: #{RUBY_PLATFORM}\n"
+            str += "LANG env: #{ENV["LANG"]}\n" if ENV["LANG"] && !ENV["LANG"].empty?
+            str += "LC_ALL env: #{ENV["LC_ALL"]}\n" if ENV["LC_ALL"] && !ENV["LC_ALL"].empty?
             str
           end
           alias_method :to_s, :inspect
diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb
index 3db490c..e306137 100644
--- a/test/irb/test_cmd.rb
+++ b/test/irb/test_cmd.rb
@@ -69,6 +69,8 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L69
       IRB.conf[:USE_MULTILINE] = true
       IRB.conf[:USE_SINGLELINE] = false
       IRB.conf[:VERBOSE] = false
+      lang_backup = ENV.delete("LANG")
+      lc_all_backup = ENV.delete("LC_ALL")
       workspace = IRB::WorkSpace.new(self)
       irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
       IRB.conf[:MAIN_CONTEXT] = irb.context
@@ -80,6 +82,9 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L82
         RUBY_PLATFORM: .+
       }x
       assert_match expected, irb.context.main.irb_info.to_s
+    ensure
+      ENV["LANG"] = lang_backup
+      ENV["LC_ALL"] = lc_all_backup
     end
 
     def test_irb_info_singleline
@@ -89,6 +94,8 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L94
       IRB.conf[:USE_MULTILINE] = false
       IRB.conf[:USE_SINGLELINE] = true
       IRB.conf[:VERBOSE] = false
+      lang_backup = ENV.delete("LANG")
+      lc_all_backup = ENV.delete("LC_ALL")
       workspace = IRB::WorkSpace.new(self)
       irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
       IRB.conf[:MAIN_CONTEXT] = irb.context
@@ -100,6 +107,9 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L107
         RUBY_PLATFORM: .+
       }x
       assert_match expected, irb.context.main.irb_info.to_s
+    ensure
+      ENV["LANG"] = lang_backup
+      ENV["LC_ALL"] = lc_all_backup
     end
 
     def test_irb_info_multiline_without_rc_files
@@ -112,6 +122,8 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L122
       IRB.conf[:USE_MULTILINE] = true
       IRB.conf[:USE_SINGLELINE] = false
       IRB.conf[:VERBOSE] = false
+      lang_backup = ENV.delete("LANG")
+      lc_all_backup = ENV.delete("LC_ALL")
       workspace = IRB::WorkSpace.new(self)
       irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
       IRB.conf[:MAIN_CONTEXT] = irb.context
@@ -127,6 +139,8 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L139
       ENV["INPUTRC"] = inputrc_backup
       IRB.__send__(:remove_const, :IRBRC_EXT)
       IRB.const_set(:IRBRC_EXT, ext_backup)
+      ENV["LANG"] = lang_backup
+      ENV["LC_ALL"] = lc_all_backup
     end
 
     def test_irb_info_singleline_without_rc_files
@@ -139,6 +153,8 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L153
       IRB.conf[:USE_MULTILINE] = false
       IRB.conf[:USE_SINGLELINE] = true
       IRB.conf[:VERBOSE] = false
+      lang_backup = ENV.delete("LANG")
+      lc_all_backup = ENV.delete("LC_ALL")
       workspace = IRB::WorkSpace.new(self)
       irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
       IRB.conf[:MAIN_CONTEXT] = irb.context
@@ -154,6 +170,37 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L170
       ENV["INPUTRC"] = inputrc_backup
       IRB.__send__(:remove_const, :IRBRC_EXT)
       IRB.const_set(:IRBRC_EXT, ext_backup)
+      ENV["LANG"] = lang_backup
+      ENV["LC_ALL"] = lc_all_backup
+    end
+
+    def test_irb_info_lang
+      FileUtils.touch("#{@tmpdir}/.inputrc")
+      FileUtils.touch("#{@tmpdir}/.irbrc")
+      IRB.setup(__FILE__, argv: [])
+      IRB.conf[:USE_MULTILINE] = true
+      IRB.conf[:USE_SINGLELINE] = false
+      IRB.conf[:VERBOSE] = false
+      lang_backup = ENV.delete("LANG")
+      lc_all_backup = ENV.delete("LC_ALL")
+      ENV["LANG"] = "ja_JP.UTF-8"
+      ENV["LC_ALL"] = "en_US.UTF-8"
+      workspace = IRB::WorkSpace.new(self)
+      irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
+      IRB.conf[:MAIN_CONTEXT] = irb.context
+      expected = %r{
+        Ruby\sversion: .+\n
+        IRB\sversion:\sirb .+\n
+        InputMethod:\sAbstract\sInputMethod\n
+        \.irbrc\spath: .+\n
+        RUBY_PLATFORM: .+\n
+        LANG\senv:\sja_JP\.UTF-8\n
+        LC_ALL\s env:\sen_US\.UTF-8\n
+      }x
+      assert_match expected, irb.context.main.irb_info.to_s
+    ensure
+      ENV["LANG"] = lang_backup
+      ENV["LC_ALL"] = lc_all_backup
     end
 
     def test_measure
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]