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

ruby-changes:29364

From: nobu <ko1@a...>
Date: Wed, 19 Jun 2013 16:47:31 +0900 (JST)
Subject: [ruby-changes:29364] nobu:r41416 (trunk): test_signal.rb: use assert_in_out_err

nobu	2013-06-19 16:47:15 +0900 (Wed, 19 Jun 2013)

  New Revision: 41416

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

  Log:
    test_signal.rb: use assert_in_out_err
    
    * test/ruby/test_signal.rb (test_kill_immediately_before_termination):
      use assert_in_out_err instead of separated fork and assert.

  Modified files:
    trunk/test/ruby/test_signal.rb

Index: test/ruby/test_signal.rb
===================================================================
--- test/ruby/test_signal.rb	(revision 41415)
+++ test/ruby/test_signal.rb	(revision 41416)
@@ -4,17 +4,7 @@ require 'tempfile' https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L4
 require_relative 'envutil'
 
 class TestSignal < Test::Unit::TestCase
-  def have_fork?
-    begin
-      Process.wait(Process.fork {})
-      return true
-    rescue NotImplementedError
-      return false
-    end
-  end
-
   def test_signal
-    return unless Process.respond_to?(:kill)
     begin
       x = 0
       oldtrap = Signal.trap(:INT) {|sig| x = 2 }
@@ -35,12 +25,9 @@ class TestSignal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L25
     ensure
       Signal.trap :INT, oldtrap if oldtrap
     end
-  end
+  end if Process.respond_to?(:kill)
 
   def test_signal_process_group
-    return unless Process.respond_to?(:kill)
-    return unless Process.respond_to?(:pgroup) # for mswin32
-
     bug4362 = '[ruby-dev:43169]'
     assert_nothing_raised(bug4362) do
       pid = Process.spawn(EnvUtil.rubybin, '-e', 'sleep 10', :pgroup => true)
@@ -49,7 +36,8 @@ class TestSignal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L36
       assert_equal(true, $?.signaled?)
       assert_equal(Signal.list["TERM"], $?.termsig)
     end
-  end
+  end if Process.respond_to?(:kill) and
+    Process.respond_to?(:pgroup) # for mswin32
 
   def test_exit_action
     begin
@@ -87,13 +75,11 @@ class TestSignal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L75
       r0.close
       w0.close
     end
-  end
+  end if Process.respond_to?(:kill)
 
   def test_invalid_signal_name
-    return unless Process.respond_to?(:kill)
-
     assert_raise(ArgumentError) { Process.kill(:XXXXXXXXXX, $$) }
-  end
+  end if Process.respond_to?(:kill)
 
   def test_signal_exception
     assert_raise(ArgumentError) { SignalException.new }
@@ -112,7 +98,6 @@ class TestSignal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L98
   end
 
   def test_signal2
-    return unless Process.respond_to?(:kill)
     begin
       x = false
       oldtrap = Signal.trap(:INT) {|sig| x = true }
@@ -145,10 +130,9 @@ class TestSignal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L130
     ensure
       Signal.trap(:INT, oldtrap) if oldtrap
     end
-  end
+  end if Process.respond_to?(:kill)
 
   def test_trap
-    return unless Process.respond_to?(:kill)
     begin
       oldtrap = Signal.trap(:INT) {|sig| }
 
@@ -186,22 +170,14 @@ class TestSignal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L170
     ensure
       Signal.trap(:INT, oldtrap) if oldtrap
     end
-  end
+  end if Process.respond_to?(:kill)
 
   def test_kill_immediately_before_termination
-    return unless have_fork?	# skip this test
-
-    r, w = IO.pipe
-    pid = Process.fork do
-      r.close
-      Signal.trap(:USR1) { w.syswrite("foo") }
+    assert_in_out_err(["-e", <<-'end;'], "", %w"foo")
+      Signal.trap(:USR1) { STDOUT.syswrite("foo") }
       Process.kill :USR1, $$
-    end
-    w.close
-    assert_equal(r.read, "foo")
-  ensure
-    Process.wait(pid) if pid
-  end
+    end;
+  end if Process.respond_to?(:kill)
 
   def test_signal_requiring
     t = Tempfile.new(%w"require_ensure_test .rb")
@@ -226,7 +202,7 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L202
     end
     t.close!
     assert_nil(error)
-  end
+  end if Process.respond_to?(:kill)
 
   def test_reserved_signal
     assert_raise(ArgumentError) {
@@ -247,8 +223,6 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L223
   end
 
   def test_signame
-    return unless Process.respond_to?(:kill)
-
     10.times do
       IO.popen([EnvUtil.rubybin, "-e", <<EOS, :err => File::NULL]) do |child|
         Signal.trap("INT") do |signo|
@@ -265,7 +239,7 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L239
         assert_equal(signame, "INT")
       end
     end
-  end
+  end if Process.respond_to?(:kill)
 
   def test_trap_puts
     assert_in_out_err([], <<-INPUT, ["a"*10000], [])
@@ -278,11 +252,9 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L252
       Process.kill :INT, $$
       sleep 0.1
     INPUT
-  end
+  end if Process.respond_to?(:kill)
 
   def test_hup_me
-    return unless Signal.list.has_key?('HUP')
-
     # [Bug #7951] [ruby-core:52864]
     # This is MRI specific spec. ruby has no guarantee
     # that signal will be deliverd synchronously.
@@ -297,5 +269,5 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L269
         Process.kill(0, Process.pid)
       }
     }
-  end
+  end if Process.respond_to?(:kill) and Signal.list.key?('HUP')
 end

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

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