Skip to content

Commit b431742

Browse files
aycabtanobu
andcommitted
Show LANG and LC_ALL env by irb_info
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
1 parent 54ee960 commit b431742

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

lib/irb/cmd/info.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def inspect
1414
str += "InputMethod: #{IRB.CurrentContext.io.inspect}\n"
1515
str += ".irbrc path: #{IRB.rc_file}\n" if File.exist?(IRB.rc_file)
1616
str += "RUBY_PLATFORM: #{RUBY_PLATFORM}\n"
17+
str += "LANG env: #{ENV["LANG"]}\n" if ENV["LANG"] && !ENV["LANG"].empty?
18+
str += "LC_ALL env: #{ENV["LC_ALL"]}\n" if ENV["LC_ALL"] && !ENV["LC_ALL"].empty?
1719
str
1820
end
1921
alias_method :to_s, :inspect

test/irb/test_cmd.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def test_irb_info_multiline
6969
IRB.conf[:USE_MULTILINE] = true
7070
IRB.conf[:USE_SINGLELINE] = false
7171
IRB.conf[:VERBOSE] = false
72+
lang_backup = ENV.delete("LANG")
73+
lc_all_backup = ENV.delete("LC_ALL")
7274
workspace = IRB::WorkSpace.new(self)
7375
irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
7476
IRB.conf[:MAIN_CONTEXT] = irb.context
@@ -80,6 +82,9 @@ def test_irb_info_multiline
8082
RUBY_PLATFORM: .+
8183
}x
8284
assert_match expected, irb.context.main.irb_info.to_s
85+
ensure
86+
ENV["LANG"] = lang_backup
87+
ENV["LC_ALL"] = lc_all_backup
8388
end
8489

8590
def test_irb_info_singleline
@@ -89,6 +94,8 @@ def test_irb_info_singleline
8994
IRB.conf[:USE_MULTILINE] = false
9095
IRB.conf[:USE_SINGLELINE] = true
9196
IRB.conf[:VERBOSE] = false
97+
lang_backup = ENV.delete("LANG")
98+
lc_all_backup = ENV.delete("LC_ALL")
9299
workspace = IRB::WorkSpace.new(self)
93100
irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
94101
IRB.conf[:MAIN_CONTEXT] = irb.context
@@ -100,6 +107,9 @@ def test_irb_info_singleline
100107
RUBY_PLATFORM: .+
101108
}x
102109
assert_match expected, irb.context.main.irb_info.to_s
110+
ensure
111+
ENV["LANG"] = lang_backup
112+
ENV["LC_ALL"] = lc_all_backup
103113
end
104114

105115
def test_irb_info_multiline_without_rc_files
@@ -112,6 +122,8 @@ def test_irb_info_multiline_without_rc_files
112122
IRB.conf[:USE_MULTILINE] = true
113123
IRB.conf[:USE_SINGLELINE] = false
114124
IRB.conf[:VERBOSE] = false
125+
lang_backup = ENV.delete("LANG")
126+
lc_all_backup = ENV.delete("LC_ALL")
115127
workspace = IRB::WorkSpace.new(self)
116128
irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
117129
IRB.conf[:MAIN_CONTEXT] = irb.context
@@ -127,6 +139,8 @@ def test_irb_info_multiline_without_rc_files
127139
ENV["INPUTRC"] = inputrc_backup
128140
IRB.__send__(:remove_const, :IRBRC_EXT)
129141
IRB.const_set(:IRBRC_EXT, ext_backup)
142+
ENV["LANG"] = lang_backup
143+
ENV["LC_ALL"] = lc_all_backup
130144
end
131145

132146
def test_irb_info_singleline_without_rc_files
@@ -139,6 +153,8 @@ def test_irb_info_singleline_without_rc_files
139153
IRB.conf[:USE_MULTILINE] = false
140154
IRB.conf[:USE_SINGLELINE] = true
141155
IRB.conf[:VERBOSE] = false
156+
lang_backup = ENV.delete("LANG")
157+
lc_all_backup = ENV.delete("LC_ALL")
142158
workspace = IRB::WorkSpace.new(self)
143159
irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
144160
IRB.conf[:MAIN_CONTEXT] = irb.context
@@ -154,6 +170,37 @@ def test_irb_info_singleline_without_rc_files
154170
ENV["INPUTRC"] = inputrc_backup
155171
IRB.__send__(:remove_const, :IRBRC_EXT)
156172
IRB.const_set(:IRBRC_EXT, ext_backup)
173+
ENV["LANG"] = lang_backup
174+
ENV["LC_ALL"] = lc_all_backup
175+
end
176+
177+
def test_irb_info_lang
178+
FileUtils.touch("#{@tmpdir}/.inputrc")
179+
FileUtils.touch("#{@tmpdir}/.irbrc")
180+
IRB.setup(__FILE__, argv: [])
181+
IRB.conf[:USE_MULTILINE] = true
182+
IRB.conf[:USE_SINGLELINE] = false
183+
IRB.conf[:VERBOSE] = false
184+
lang_backup = ENV.delete("LANG")
185+
lc_all_backup = ENV.delete("LC_ALL")
186+
ENV["LANG"] = "ja_JP.UTF-8"
187+
ENV["LC_ALL"] = "en_US.UTF-8"
188+
workspace = IRB::WorkSpace.new(self)
189+
irb = IRB::Irb.new(workspace, TestInputMethod.new([]))
190+
IRB.conf[:MAIN_CONTEXT] = irb.context
191+
expected = %r{
192+
Ruby\sversion: .+\n
193+
IRB\sversion:\sirb .+\n
194+
InputMethod:\sAbstract\sInputMethod\n
195+
\.irbrc\spath: .+\n
196+
RUBY_PLATFORM: .+\n
197+
LANG\senv:\sja_JP\.UTF-8\n
198+
LC_ALL\s env:\sen_US\.UTF-8\n
199+
}x
200+
assert_match expected, irb.context.main.irb_info.to_s
201+
ensure
202+
ENV["LANG"] = lang_backup
203+
ENV["LC_ALL"] = lc_all_backup
157204
end
158205

159206
def test_measure

0 commit comments

Comments
 (0)