[前][次][番号順一覧][スレッド一覧]

ruby-changes:19400

From: kosaki <ko1@a...>
Date: Thu, 5 May 2011 23:10:03 +0900 (JST)
Subject: [ruby-changes:19400] Ruby:r31440 (trunk): * test/ruby/test_io.rb (TestIO#test_O_CLOEXEC): fix false positive

kosaki	2011-05-05 23:09:21 +0900 (Thu, 05 May 2011)

  New Revision: 31440

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31440

  Log:
    * test/ruby/test_io.rb (TestIO#test_O_CLOEXEC): fix false positive
      detection.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_io.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31439)
+++ ChangeLog	(revision 31440)
@@ -1,3 +1,8 @@
+Thu May  5 23:08:32 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* test/ruby/test_io.rb (TestIO#test_O_CLOEXEC): fix false positive
+	  detection.
+
 Thu May  5 22:23:34 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* thread_pthread.c (native_mutex_reinitialize_atfork): removed
Index: test/ruby/test_io.rb
===================================================================
--- test/ruby/test_io.rb	(revision 31439)
+++ test/ruby/test_io.rb	(revision 31440)
@@ -1244,28 +1244,48 @@
     end
 
     mkcdtmpdir do
-      normal_file = Tempfile.new("normal_file");
-      assert_equal(false, normal_file.close_on_exec?)
+      ary = []
+      begin
+        10.times {
+          ary.concat IO.pipe
+        }
 
-      cloexec_file = Tempfile.new("cloexec_file", :mode => File::CLOEXEC);
-      assert_equal(true, cloexec_file.close_on_exec?)
+        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
 
-      argfile = Tempfile.new("argfile");
+        while (e = ary.shift) != nil
+          e.close
+        end
 
-      argfile.puts normal_file.fileno
-      argfile.puts cloexec_file.fileno
-      argfile.flush
-
-      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
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]