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

ruby-changes:18965

From: sorah <ko1@a...>
Date: Tue, 1 Mar 2011 21:54:46 +0900 (JST)
Subject: [ruby-changes:18965] Ruby:r30999 (trunk): * lib/test/unit/parallel.rb: For Windows.

sorah	2011-03-01 21:54:39 +0900 (Tue, 01 Mar 2011)

  New Revision: 30999

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

  Log:
    * lib/test/unit/parallel.rb: For Windows.
    
    * test/testunit/test_parallel.rb(TestParallelWorker#test_quit_in_test):
      Fix for above specification change.
    * test/testunit/test_parallel.rb(TestParallel#spawn_runner):
      Fix outputing empty line in running test.

  Modified files:
    trunk/ChangeLog
    trunk/lib/test/unit/parallel.rb
    trunk/test/testunit/test_parallel.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30998)
+++ ChangeLog	(revision 30999)
@@ -1,3 +1,12 @@
+Tue Mar  1 21:48:22 2011  Shota Fukumori  <sorah@t...>
+
+	* lib/test/unit/parallel.rb: For Windows.
+
+	* test/testunit/test_parallel.rb(TestParallelWorker#test_quit_in_test):
+	  Fix for above specification change.
+	* test/testunit/test_parallel.rb(TestParallel#spawn_runner):
+	  Fix outputing empty line in running test.
+
 Tue Mar  1 20:51:57 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* test/ruby/test_system.rb (TestSystem#test_system_at):
Index: lib/test/unit/parallel.rb
===================================================================
--- lib/test/unit/parallel.rb	(revision 30998)
+++ lib/test/unit/parallel.rb	(revision 30999)
@@ -12,6 +12,12 @@
       undef _run_suites
       undef run
 
+      def inclement_io orig
+        *rest, io = 500.times.inject([orig.dup]){|ios, | ios << ios.last.dup }
+        rest.each(&:close)
+        io
+      end
+
       def _run_suites suites, type
         suites.map do |suite|
           result = _run_suite(suite, type)
@@ -24,12 +30,10 @@
         i,o = IO.pipe
         MiniTest::Unit.output = o
 
-        stdout = STDOUT.dup
-
         th = Thread.new do
           begin
             while buf = (self.verbose ? i.gets : i.read(5))
-              stdout.puts "p #{[buf].pack("m").gsub("\n","")}"
+              @stdout.puts "p #{[buf].pack("m").gsub("\n","")}"
             end
           rescue IOError
           rescue Errno::EPIPE
@@ -56,7 +60,7 @@
         result << suite.name
 
         begin
-          STDOUT.puts "done #{[Marshal.dump(result)].pack("m").gsub("\n","")}"
+          @stdout.puts "done #{[Marshal.dump(result)].pack("m").gsub("\n","")}"
         rescue Errno::EPIPE; end
         return result
       ensure
@@ -73,50 +77,34 @@
         Signal.trap(:INT,"IGNORE")
         @old_loadpath = []
         begin
-          STDOUT.sync = true
-          STDOUT.puts "ready"
-          stdin = STDIN.dup
-          stdout = STDOUT.dup
-          while buf = stdin.gets
+          @stdout = inclement_io(STDOUT)
+          @stdin = inclement_io(STDIN)
+          @stdout.sync = true
+          @stdout.puts "ready"
+          while buf = @stdin.gets
             case buf.chomp
             when /^loadpath (.+?)$/
               @old_loadpath = $:.dup
               $:.push(*Marshal.load($1.unpack("m")[0].force_encoding("ASCII-8BIT"))).uniq!
             when /^run (.+?) (.+?)$/
-              STDOUT.puts "okay"
+              @stdout.puts "okay"
 
-              th = Thread.new do
-                while puf = stdin.gets
-                  if puf.chomp == "quit"
-                    begin
-                      stdout.puts "bye"
-                    rescue Errno::EPIPE; end
-                    exit
-                  end
-                end
-              end
-
               @options = @opts.dup
               suites = MiniTest::Unit::TestCase.test_suites
 
               begin
                 require $1
               rescue LoadError
-                th.kill
-                STDOUT.puts "after #{[Marshal.dump([$1, $!])].pack("m").gsub("\n","")}"
-                STDOUT.puts "ready"
+                @stdout.puts "after #{[Marshal.dump([$1, $!])].pack("m").gsub("\n","")}"
+                @stdout.puts "ready"
                 next
               end
               _run_suites MiniTest::Unit::TestCase.test_suites-suites, $2.to_sym
 
-              STDIN.reopen(stdin)
-              STDOUT.reopen(stdout)
-
-              th.kill
-              STDOUT.puts "ready"
+              @stdout.puts "ready"
             when /^quit$/
               begin
-                STDOUT.puts "bye"
+                @stdout.puts "bye"
               rescue Errno::EPIPE; end
               exit
             end
@@ -124,11 +112,12 @@
         rescue Errno::EPIPE
         rescue Exception => e
           begin
-            STDOUT.puts "bye #{[Marshal.dump(e)].pack("m").gsub("\n","")}"
+            @stdout.puts "bye #{[Marshal.dump(e)].pack("m").gsub("\n","")}"
           rescue Errno::EPIPE;end
           exit
         ensure
-          stdin.close
+          @stdin.close
+          @stdout.close
         end
       end
     end
Index: test/testunit/test_parallel.rb
===================================================================
--- test/testunit/test_parallel.rb	(revision 30998)
+++ test/testunit/test_parallel.rb	(revision 30999)
@@ -117,14 +117,6 @@
         assert_match(/^bye$/m,@worker_out.read)
       end
     end
-
-    def test_quit_in_test
-      timeout(10) do
-        @worker_in.puts "run #{TESTS}/test_third.rb ptest"
-        @worker_in.puts "quit"
-        assert_match(/^ready\nokay\nbye/m,@worker_out.read)
-      end
-    end
   end
 
   class TestParallel < Test::Unit::TestCase
@@ -137,7 +129,7 @@
     def spawn_runner(*opt_args)
       @test_out, o = IO.pipe
       @test_pid = spawn(*@options[:ruby], TESTS+"/runner.rb",
-                        "-j","t2","-x","sleeping",*opt_args, out: o)
+                        "-j","t2","-x","sleeping",*opt_args, out: o, err: :out)
       o.close
     end
 

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

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