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

ruby-changes:4865

From: ko1@a...
Date: Sun, 11 May 2008 18:01:47 +0900 (JST)
Subject: [ruby-changes:4865] akr - Ruby:r16358 (trunk): * test/ruby/test_process.rb (TestProcess#with_stdin): defined.

akr	2008-05-11 18:01:31 +0900 (Sun, 11 May 2008)

  New Revision: 16358

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

  Log:
    * test/ruby/test_process.rb (TestProcess#with_stdin): defined.
      (TestProcess#test_argv0_noarg): don't use redirect_fds.
      [ruby-dev:34647]


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_process.rb?r1=16358&r2=16357&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16358&r2=16357&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 16357)
+++ ChangeLog	(revision 16358)
@@ -1,3 +1,9 @@
+Sun May 11 17:58:45 2008  Tanaka Akira  <akr@f...>
+
+	* test/ruby/test_process.rb (TestProcess#with_stdin): defined.
+	  (TestProcess#test_argv0_noarg): don't use redirect_fds.
+	  [ruby-dev:34647]
+
 Sun May 11 17:57:36 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in (MINIRUBY): should not include extension library path.
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 16357)
+++ test/ruby/test_process.rb	(revision 16358)
@@ -799,27 +799,43 @@
     }
   end
 
+  def with_stdin(filename)
+    open(filename) {|f|
+      begin
+        old = STDIN.dup
+        begin
+          STDIN.reopen(filename)
+          yield
+        ensure
+          STDIN.reopen(old)
+        end
+      ensure
+        old.close
+      end
+    }
+  end
+
   def test_argv0_noarg
     with_tmpchdir {|d|
       open("t", "w") {|f| f.print "exit true" }
       open("f", "w") {|f| f.print "exit false" }
 
-      assert_equal(true, system([RUBY, "qaz"], STDIN=>"t"))
-      assert_equal(false, system([RUBY, "wsx"], STDIN=>"f"))
+      with_stdin("t") { assert_equal(true, system([RUBY, "qaz"])) }
+      with_stdin("f") { assert_equal(false, system([RUBY, "wsx"])) }
 
-      Process.wait spawn([RUBY, "edc"], STDIN=>"t")
+      with_stdin("t") { Process.wait spawn([RUBY, "edc"]) }
       assert($?.success?)
-      Process.wait spawn([RUBY, "rfv"], STDIN=>"f")
+      with_stdin("f") { Process.wait spawn([RUBY, "rfv"]) }
       assert(!$?.success?)
 
-      IO.popen([[RUBY, "tgb"], STDIN=>"t"]) {|io| assert_equal("", io.read) }
+      with_stdin("t") { IO.popen([[RUBY, "tgb"]]) {|io| assert_equal("", io.read) } }
       assert($?.success?)
-      IO.popen([[RUBY, "yhn"], STDIN=>"f"]) {|io| assert_equal("", io.read) }
+      with_stdin("f") { IO.popen([[RUBY, "yhn"]]) {|io| assert_equal("", io.read) } }
       assert(!$?.success?)
 
-      status = run_in_child "exec([#{RUBY.dump}, 'ujm'], STDIN=>'t')"
+      status = run_in_child "STDIN.reopen('t'); exec([#{RUBY.dump}, 'ujm'])"
       assert(status.success?)
-      status = run_in_child "exec([#{RUBY.dump}, 'ik,'], STDIN=>'f')"
+      status = run_in_child "STDIN.reopen('f'); exec([#{RUBY.dump}, 'ik,'])"
       assert(!status.success?)
     }
   end

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

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