Skip to content

Commit

Permalink
Merge pull request #257 from aycabta/show-lang-and-lc_all-env-by-irb_…
Browse files Browse the repository at this point in the history
…info

Show LANG and LC_ALL env by irb_info
  • Loading branch information
aycabta authored Jul 10, 2021
2 parents 4ed2187 + b431742 commit c72cd84
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/irb/cmd/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def inspect
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
Expand Down
47 changes: 47 additions & 0 deletions test/irb/test_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def test_irb_info_multiline
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
Expand All @@ -80,6 +82,9 @@ def test_irb_info_multiline
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
Expand All @@ -89,6 +94,8 @@ def test_irb_info_singleline
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
Expand All @@ -100,6 +107,9 @@ def test_irb_info_singleline
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
Expand All @@ -112,6 +122,8 @@ def test_irb_info_multiline_without_rc_files
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
Expand All @@ -127,6 +139,8 @@ def test_irb_info_multiline_without_rc_files
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
Expand All @@ -139,6 +153,8 @@ def test_irb_info_singleline_without_rc_files
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
Expand All @@ -154,6 +170,37 @@ def test_irb_info_singleline_without_rc_files
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
Expand Down

0 comments on commit c72cd84

Please sign in to comment.