From 25d040780fcff44b3b03062d1d2c4540df7b33ef Mon Sep 17 00:00:00 2001 From: kosaki Date: Thu, 5 May 2011 14:09:21 +0000 Subject: * test/ruby/test_io.rb (TestIO#test_O_CLOEXEC): fix false positive detection. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io.rb | 58 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 19 deletions(-) (limited to 'test/ruby') diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 5a55722115..07308a07ce 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1244,28 +1244,48 @@ class TestIO < Test::Unit::TestCase end mkcdtmpdir do - normal_file = Tempfile.new("normal_file"); - assert_equal(false, normal_file.close_on_exec?) - - cloexec_file = Tempfile.new("cloexec_file", :mode => File::CLOEXEC); - assert_equal(true, cloexec_file.close_on_exec?) - - argfile = Tempfile.new("argfile"); + ary = [] + begin + 10.times { + ary.concat IO.pipe + } - argfile.puts normal_file.fileno - argfile.puts cloexec_file.fileno - argfile.flush + normal_file = Tempfile.new("normal_file"); + assert_equal(false, normal_file.close_on_exec?) + cloexec_file = Tempfile.new("cloexec_file", :mode => File::CLOEXEC); + assert_equal(true, cloexec_file.close_on_exec?) + arg, argw = IO.pipe + argw.puts normal_file.fileno + argw.puts cloexec_file.fileno + argw.flush + ret, retw = IO.pipe + + while (e = ary.shift) != nil + e.close + end - ruby('-e', <<-'End', argfile.path) { |f| - begin - puts IO.for_fd(ARGF.gets.to_i).fileno - puts IO.for_fd(ARGF.gets.to_i).fileno - rescue - puts "nofile" + spawn("ruby", "-e", <<-'End', :close_others=>false, :in=>arg, :out=>retw) + begin + puts IO.for_fd(gets.to_i).fileno + puts IO.for_fd(gets.to_i).fileno + rescue + puts "nofile" + ensure + exit + end + End + retw.close + Process.wait + assert_equal("#{normal_file.fileno}\nnofile\n", ret.read) + ensure + while (e = ary.shift) != nil + e.close end - End - assert_equal("#{normal_file.fileno}\nnofile\n", f.read) - } + arg.close unless arg.closed? + argw.close unless argw.closed? + ret.close unless ret.closed? + retw.close unless retw.closed? + end end end -- cgit v1.2.3