diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-11 09:01:31 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-11 09:01:31 +0000 |
commit | 435ac5e58dccad2cfc104583ac658bb2b2920a7e (patch) | |
tree | bd75f0089aa07ba62064c3ef1a0224107dab47e7 /test | |
parent | 121ae83741eac7c823681736851e6d20dd3279c4 (diff) | |
download | ruby-435ac5e58dccad2cfc104583ac658bb2b2920a7e.tar.gz |
* test/ruby/test_process.rb (TestProcess#with_stdin): defined.
(TestProcess#test_argv0_noarg): don't use redirect_fds.
[ruby-dev:34647]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16358 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_process.rb | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index caa5c0f349..183bf10b83 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -799,27 +799,43 @@ class TestProcess < Test::Unit::TestCase } 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 |