Set LANG/LC_ALL/LC_MESSAGES/LANGUAGE to 'C' whenever we execute things, so that the output that comes back is more easily parsed, without needing to understand all sorts of foreign languages

git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2456 980ebf18-57e1-0310-9a29-db15c13687c0
This commit is contained in:
mpalmer 2007-05-03 04:38:51 +00:00
Родитель a1d4f3567d
Коммит 79dcd33aeb
2 изменённых файлов: 27 добавлений и 0 удалений

Просмотреть файл

@ -344,6 +344,7 @@ module Util
Process.euid = arguments[:uid]
Process.uid = arguments[:uid] unless @@os == "Darwin"
end
ENV['LANG'] = ENV['LC_ALL'] = ENV['LC_MESSAGES'] = ENV['LANGUAGE'] = 'C'
if command.is_a?(Array)
Kernel.exec(*command)
else

Просмотреть файл

@ -331,6 +331,32 @@ class TestPuppetUtil < Test::Unit::TestCase
output = Puppet::Util.execute([patricidecommand], :failonfail => false)
end
end
def test_lang_environ_in_execute
orig_lang = ENV["LANG"]
orig_lc_all = ENV["LC_ALL"]
orig_lc_messages = ENV["LC_MESSAGES"]
orig_language = ENV["LANGUAGE"]
# Mmm, we love gettext(3)
ENV["LANG"] = "en_US"
ENV["LC_ALL"] = "en_US"
ENV["LC_MESSAGES"] = "en_US"
ENV["LANGUAGE"] = "en_US"
%w{LANG LC_ALL LC_MESSAGES LANGUAGE}.each do |env|
assert_equal 'C',
Puppet::Util.execute(['ruby', '-e', "print ENV['#{env}']"]),
"Environment var #{env} wasn't set to 'C'"
assert_equal 'en_US', ENV[env], "Environment var #{env} not set back correctly"
end
ENV["LANG"] = orig_lang
ENV["LC_ALL"] = orig_lc_all
ENV["LC_MESSAGES"] = orig_lc_messages
ENV["LANGUAGE"] = orig_lc_messages
end
# Check whether execute() accepts strings in addition to arrays.
def test_string_exec