1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* test/ruby/envutil.rb (EnvUtil.invoke_ruby): merge stdout and stderr

if capture_stderr is :merge_to_stdout.
  (assert_normal_exit): print abnormal output propery.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28906 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2010-08-07 10:53:13 +00:00
parent 2f2b6ace05
commit 06efb04e8e
2 changed files with 18 additions and 13 deletions

View file

@ -1,3 +1,9 @@
Sat Aug 7 19:51:10 2010 Tanaka Akira <akr@fsij.org>
* test/ruby/envutil.rb (EnvUtil.invoke_ruby): merge stdout and stderr
if capture_stderr is :merge_to_stdout.
(assert_normal_exit): print abnormal output propery.
Sat Aug 7 19:04:49 2010 Tanaka Akira <akr@fsij.org> Sat Aug 7 19:04:49 2010 Tanaka Akira <akr@fsij.org>
* missing/close.c: undef the macros "getpeername", "getsockname" and * missing/close.c: undef the macros "getpeername", "getsockname" and

View file

@ -33,11 +33,11 @@ module EnvUtil
def invoke_ruby(args, stdin_data="", capture_stdout=false, capture_stderr=false, opt={}) def invoke_ruby(args, stdin_data="", capture_stdout=false, capture_stderr=false, opt={})
in_c, in_p = IO.pipe in_c, in_p = IO.pipe
out_p, out_c = IO.pipe if capture_stdout out_p, out_c = IO.pipe if capture_stdout
err_p, err_c = IO.pipe if capture_stderr err_p, err_c = IO.pipe if capture_stderr && capture_stderr != :merge_to_stdout
opt = opt.dup opt = opt.dup
opt[:in] = in_c opt[:in] = in_c
opt[:out] = out_c if capture_stdout opt[:out] = out_c if capture_stdout
opt[:err] = err_c if capture_stderr opt[:err] = capture_stderr == :merge_to_stdout ? out_c : err_c if capture_stderr
if enc = opt.delete(:encoding) if enc = opt.delete(:encoding)
out_p.set_encoding(enc) if out_p out_p.set_encoding(enc) if out_p
err_p.set_encoding(enc) if err_p err_p.set_encoding(enc) if err_p
@ -52,23 +52,23 @@ module EnvUtil
pid = spawn(child_env, EnvUtil.rubybin, *args, opt) pid = spawn(child_env, EnvUtil.rubybin, *args, opt)
in_c.close in_c.close
out_c.close if capture_stdout out_c.close if capture_stdout
err_c.close if capture_stderr err_c.close if capture_stderr && capture_stderr != :merge_to_stdout
if block_given? if block_given?
return yield in_p, out_p, err_p return yield in_p, out_p, err_p
else else
th_stdout = Thread.new { out_p.read } if capture_stdout th_stdout = Thread.new { out_p.read } if capture_stdout
th_stderr = Thread.new { err_p.read } if capture_stderr th_stderr = Thread.new { err_p.read } if capture_stderr && capture_stderr != :merge_to_stdout
in_p.write stdin_data.to_str in_p.write stdin_data.to_str
in_p.close in_p.close
timeout = opt.fetch(:timeout, 10) timeout = opt.fetch(:timeout, 10)
if (!capture_stdout || th_stdout.join(timeout)) && (!capture_stderr || th_stderr.join(timeout)) if (!th_stdout || th_stdout.join(timeout)) && (!th_stderr || th_stderr.join(timeout))
stdout = th_stdout.value if capture_stdout stdout = th_stdout.value if capture_stdout
stderr = th_stderr.value if capture_stderr stderr = th_stderr.value if capture_stderr && capture_stderr != :merge_to_stdout
else else
raise Timeout::Error raise Timeout::Error
end end
out_p.close if capture_stdout out_p.close if capture_stdout
err_p.close if capture_stderr err_p.close if capture_stderr && capture_stderr != :merge_to_stdout
Process.wait pid Process.wait pid
status = $? status = $?
return stdout, stderr, status return stdout, stderr, status
@ -122,7 +122,7 @@ module Test
module Assertions module Assertions
public public
def assert_normal_exit(testsrc, message = '', opt = {}) def assert_normal_exit(testsrc, message = '', opt = {})
_, _, status = EnvUtil.invoke_ruby(%W'-W0', testsrc, true, true, opt) out, _, status = EnvUtil.invoke_ruby(%W'-W0', testsrc, true, :merge_to_stdout, opt)
pid = status.pid pid = status.pid
faildesc = proc do faildesc = proc do
signo = status.termsig signo = status.termsig
@ -138,11 +138,10 @@ module Test
if !message.empty? if !message.empty?
full_message << message << "\n" full_message << message << "\n"
end end
if message.empty?
full_message << "pid #{pid} killed by #{sigdesc}" full_message << "pid #{pid} killed by #{sigdesc}"
else if !out.empty?
message << "\n" if /\n\z/ !~ message out << "\n" if /\n\z/ !~ out
full_message << "pid #{pid} killed by #{sigdesc}\n#{message.gsub(/^/, '| ')}" full_message << "\n#{out.gsub(/^/, '| ')}"
end end
full_message full_message
end end