diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-23 15:22:13 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-23 15:22:13 +0000 |
commit | f7ef694a712d8deccfba67a4860b0272e335f17a (patch) | |
tree | de1333bc139328e336cb974ab6f33644a72b97ea /test/ruby/envutil.rb | |
parent | c0d8e6cbf9d7e068e98ff2053bff18ee13e338df (diff) | |
download | ruby-f7ef694a712d8deccfba67a4860b0272e335f17a.tar.gz |
* test/ruby/test_settracefunc.rb: add a test for set_trace_func.
* test/ruby/envutil.rb: move "rubyexec" method from test_rubyoptions.rb.
* test/ruby/test_rubyoptions.rb: use rubyexec in envutil.rb.
* test/ruby/test_thread.rb: add tests to achieve over 90% test coverage
of thread.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/envutil.rb')
-rw-r--r-- | test/ruby/envutil.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/ruby/envutil.rb b/test/ruby/envutil.rb index bbcab83d06..37efdde84e 100644 --- a/test/ruby/envutil.rb +++ b/test/ruby/envutil.rb @@ -1,3 +1,6 @@ +require "open3" +require "timeout" + module EnvUtil def rubybin unless ENV["RUBYOPT"] @@ -28,4 +31,42 @@ module EnvUtil end end module_function :rubybin + + LANG_ENVS = %w"LANG LC_ALL LC_CTYPE" + def rubyexec(*args) + if /(mswin|bccwin|mingw|emx)/ =~ RUBY_PLATFORM + flunk("cannot test in win32") + return + end + + ruby = EnvUtil.rubybin + c = "C" + env = {} + LANG_ENVS.each {|lc| env[lc], ENV[lc] = ENV[lc], c} + stdin, stdout, stderr = Open3.popen3(*([ruby] + args)) + env.each_pair {|lc, v| + if v + ENV[lc] = v + else + ENV.delete(lc) + end + } + env = nil + Timeout.timeout(10) do + yield(stdin, stdout, stderr) + end + + ensure + env.each_pair {|lc, v| + if v + ENV[lc] = v + else + ENV.delete(lc) + end + } if env + stdin .close unless !stdin || stdin .closed? + stdout.close unless !stdout || stdout.closed? + stderr.close unless !stderr || stderr.closed? + end + module_function :rubyexec end |