ruby-changes:5027
From: akr <ko1@a...>
Date: Thu, 22 May 2008 11:41:08 +0900 (JST)
Subject: [ruby-changes:5027] akr - Ruby:r16520 (trunk): * test/ruby/envutil.rb (assert_normal_exit): capture stdout and stderr
akr 2008-05-22 11:40:50 +0900 (Thu, 22 May 2008) New Revision: 16520 Modified files: trunk/ChangeLog trunk/test/ruby/envutil.rb trunk/test/ruby/test_continuation.rb Log: * test/ruby/envutil.rb (assert_normal_exit): capture stdout and stderr of the child process. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16520&r2=16519&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_continuation.rb?r1=16520&r2=16519&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/envutil.rb?r1=16520&r2=16519&diff_format=u Index: ChangeLog =================================================================== --- ChangeLog (revision 16519) +++ ChangeLog (revision 16520) @@ -1,3 +1,8 @@ +Thu May 22 11:39:59 2008 Tanaka Akira <akr@f...> + + * test/ruby/envutil.rb (assert_normal_exit): capture stdout and stderr + of the child process. + Thu May 22 08:28:49 2008 Yukihiro Matsumoto <matz@r...> * array.c (flatten): free memo hash table before raising exception. Index: test/ruby/test_continuation.rb =================================================================== --- test/ruby/test_continuation.rb (revision 16519) +++ test/ruby/test_continuation.rb (revision 16520) @@ -51,5 +51,17 @@ 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 Index: test/ruby/envutil.rb =================================================================== --- test/ruby/envutil.rb (revision 16519) +++ test/ruby/envutil.rb (revision 16520) @@ -72,9 +72,16 @@ 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 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/