2008-04-23 11:22:13 -04:00
|
|
|
require "open3"
|
|
|
|
require "timeout"
|
|
|
|
|
2003-10-04 22:56:42 -04:00
|
|
|
module EnvUtil
|
|
|
|
def rubybin
|
2006-02-03 04:15:42 -05:00
|
|
|
unless ENV["RUBYOPT"]
|
|
|
|
|
|
|
|
end
|
2004-05-19 10:45:49 -04:00
|
|
|
if ruby = ENV["RUBY"]
|
|
|
|
return ruby
|
|
|
|
end
|
2005-12-29 03:05:26 -05:00
|
|
|
ruby = "ruby"
|
2006-02-03 04:15:42 -05:00
|
|
|
rubyexe = ruby+".exe"
|
2003-10-13 09:05:24 -04:00
|
|
|
3.times do
|
2006-02-03 04:15:42 -05:00
|
|
|
if File.exist? ruby and File.executable? ruby and !File.directory? ruby
|
|
|
|
return File.expand_path(ruby)
|
|
|
|
end
|
|
|
|
if File.exist? rubyexe and File.executable? rubyexe
|
2008-05-12 08:35:37 -04:00
|
|
|
return File.expand_path(rubyexe)
|
2003-10-13 09:05:24 -04:00
|
|
|
end
|
2005-12-29 03:05:26 -05:00
|
|
|
ruby = File.join("..", ruby)
|
2003-10-13 10:59:25 -04:00
|
|
|
end
|
|
|
|
begin
|
|
|
|
require "rbconfig"
|
|
|
|
File.join(
|
* mkconfig.rb: generate RbConfig instead of Config.
* instruby.rb, rubytest.rb, runruby.rb, bcc32/Makefile.sub,
ext/extmk.rb, ext/dl/extconf.rb, ext/iconv/charset_alias.rb,
lib/mkmf.rb, lib/rdoc/ri/ri_paths.rb,
lib/webrick/httpservlet/cgihandler.rb,
test/dbm/test_dbm.rb, test/gdbm/test_gdbm.rb,
test/ruby/envutil.rb, test/soap/calc/test_calc_cgi.rb,
test/soap/header/test_authheader_cgi.rb, test/soap/ssl/test_ssl.rb,
win32/mkexports.rb, win32/resource.rb: Use RbConfig instead of
Config.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-02-20 03:34:53 -05:00
|
|
|
RbConfig::CONFIG["bindir"],
|
|
|
|
RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"]
|
2003-10-13 10:59:25 -04:00
|
|
|
)
|
|
|
|
rescue LoadError
|
|
|
|
"ruby"
|
2003-10-04 22:56:42 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
module_function :rubybin
|
2008-04-23 11:22:13 -04:00
|
|
|
|
|
|
|
LANG_ENVS = %w"LANG LC_ALL LC_CTYPE"
|
|
|
|
def rubyexec(*args)
|
|
|
|
ruby = EnvUtil.rubybin
|
|
|
|
c = "C"
|
|
|
|
env = {}
|
|
|
|
LANG_ENVS.each {|lc| env[lc], ENV[lc] = ENV[lc], c}
|
2008-04-24 10:02:15 -04:00
|
|
|
stdin = stdout = stderr = nil
|
2008-04-23 11:22:13 -04:00
|
|
|
Timeout.timeout(10) do
|
2008-04-24 10:02:15 -04:00
|
|
|
stdin, stdout, stderr = Open3.popen3(*([ruby] + args))
|
|
|
|
env.each_pair {|lc, v|
|
|
|
|
if v
|
|
|
|
ENV[lc] = v
|
|
|
|
else
|
|
|
|
ENV.delete(lc)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
env = nil
|
2008-04-23 11:22:13 -04:00
|
|
|
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
|
2003-10-04 22:56:42 -04:00
|
|
|
end
|
2008-05-03 07:57:55 -04:00
|
|
|
|
|
|
|
module Test
|
|
|
|
module Unit
|
|
|
|
module Assertions
|
|
|
|
public
|
|
|
|
def assert_normal_exit(testsrc, message = '')
|
|
|
|
IO.popen([EnvUtil.rubybin, '-W0'], 'w') {|io|
|
|
|
|
io.write testsrc
|
|
|
|
}
|
|
|
|
status = $?
|
|
|
|
faildesc = nil
|
|
|
|
if status.signaled?
|
|
|
|
signo = status.termsig
|
|
|
|
signame = Signal.list.invert[signo]
|
|
|
|
sigdesc = "signal #{signo}"
|
|
|
|
if signame
|
|
|
|
sigdesc = "SIG#{signame} (#{sigdesc})"
|
|
|
|
end
|
|
|
|
full_message = build_message(message, "killed by ?", sigdesc)
|
|
|
|
end
|
|
|
|
assert_block(full_message) { !status.signaled? }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|