From a85b247171373d079d98eeef42c6014980062609 Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 22 May 2008 02:40:50 +0000 Subject: * test/ruby/envutil.rb (assert_normal_exit): capture stdout and stderr of the child process. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ test/ruby/envutil.rb | 26 ++++++++++++++++++++++---- test/ruby/test_continuation.rb | 12 ++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 72f03dc678..da20198daf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu May 22 11:39:59 2008 Tanaka Akira + + * test/ruby/envutil.rb (assert_normal_exit): capture stdout and stderr + of the child process. + Thu May 22 08:28:49 2008 Yukihiro Matsumoto * array.c (flatten): free memo hash table before raising exception. diff --git a/test/ruby/envutil.rb b/test/ruby/envutil.rb index bfecb60084..910b475232 100644 --- a/test/ruby/envutil.rb +++ b/test/ruby/envutil.rb @@ -72,9 +72,16 @@ module Test module Assertions public def assert_normal_exit(testsrc, message = '') - IO.popen([EnvUtil.rubybin, '-W0'], 'w') {|io| - io.write testsrc - } + in_c, in_p = IO.pipe + out_p, out_c = IO.pipe + pid = spawn(EnvUtil.rubybin, '-W0', STDIN=>in_c, STDOUT=>out_c, STDERR=>out_c) + in_c.close + out_c.close + in_p.write testsrc + in_p.close + msg = out_p.read + out_p.close + Process.wait pid status = $? faildesc = nil if status.signaled? @@ -84,9 +91,20 @@ module Test if signame sigdesc = "SIG#{signame} (#{sigdesc})" end - full_message = build_message(message, "killed by ?", sigdesc) + if msg.empty? + full_message = build_message(message, "killed by ?", sigdesc) + else + msg << "\n" if /\n\z/ !~ msg + full_message = build_message(message, "killed by ?\n?", sigdesc, + AssertionMessage::Literal.new(msg.gsub(/^/, '| '))) + end end assert_block(full_message) { !status.signaled? } + ensure + in_c.close if in_c && !in_c.closed? + in_p.close if in_p && !in_p.closed? + out_c.close if out_c && !out_c.closed? + out_p.close if out_p && !out_p.closed? end end end diff --git a/test/ruby/test_continuation.rb b/test/ruby/test_continuation.rb index 09787c1589..f8302abdc1 100644 --- a/test/ruby/test_continuation.rb +++ b/test/ruby/test_continuation.rb @@ -51,5 +51,17 @@ class TestContinuation < Test::Unit::TestCase c.call } end + + def test_ary_flatten + assert_normal_exit %q{ + require 'continuation' + n = 0 + o = Object.new + def o.to_ary() callcc {|k| $k = k; [1,2,3]} end + [10,20,o,30,o,40].flatten.inspect + n += 1 + $k.call if n < 100 + }, '[ruby-dev:34798]' + end end -- cgit v1.2.3