From b104173c4c7ebee13ddd869d7285f601a0ef8722 Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 30 Apr 2008 12:38:47 +0000 Subject: add tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16243 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_process.rb | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'test/ruby/test_process.rb') diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index babf5788f3..caa5c0f349 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -19,6 +19,12 @@ class TestProcess < Test::Unit::TestCase } end + def run_in_child(str) # should be called in a temporary directory + write_file("test-script", str) + Process.wait spawn(RUBY, "test-script") + $? + end + def test_rlimit_availability begin Process.getrlimit(nil) @@ -540,6 +546,24 @@ class TestProcess < Test::Unit::TestCase } end + def test_execopts_redirect_self + with_pipe {|r, w| + w << "haha\n" + w.close + r.close_on_exec = true + IO.popen([RUBY, "-e", "print IO.new(#{r.fileno}).read", r.fileno=>r.fileno, :close_others=>false]) {|io| + assert_equal("haha\n", io.read) + } + } + end + + def test_execopts_duplex_io + IO.popen("#{RUBY} -e ''", "r+") {|duplex| + assert_raise(ArgumentError) { system("#{RUBY} -e ''", duplex=>STDOUT) } + assert_raise(ArgumentError) { system("#{RUBY} -e ''", STDOUT=>duplex) } + } + end + def test_execopts_modification h = {} Process.wait spawn(*TRUECOMMAND, h) @@ -756,4 +780,48 @@ class TestProcess < Test::Unit::TestCase } end + def test_argv0 + with_tmpchdir {|d| + assert_equal(false, system([RUBY, "asdfg"], "-e", "exit false")) + assert_equal(true, system([RUBY, "zxcvb"], "-e", "exit true")) + + Process.wait spawn([RUBY, "poiu"], "-e", "exit 4") + assert_equal(4, $?.exitstatus) + + assert_equal("1", IO.popen([[RUBY, "qwerty"], "-e", "print 1"]).read) + + write_file("s", <<-"End") + exec([#{RUBY.dump}, "lkjh"], "-e", "exit 5") + End + pid = spawn RUBY, "s" + Process.wait pid + assert_equal(5, $?.exitstatus) + } + 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")) + + Process.wait spawn([RUBY, "edc"], STDIN=>"t") + assert($?.success?) + Process.wait spawn([RUBY, "rfv"], STDIN=>"f") + assert(!$?.success?) + + IO.popen([[RUBY, "tgb"], STDIN=>"t"]) {|io| assert_equal("", io.read) } + assert($?.success?) + IO.popen([[RUBY, "yhn"], STDIN=>"f"]) {|io| assert_equal("", io.read) } + assert(!$?.success?) + + status = run_in_child "exec([#{RUBY.dump}, 'ujm'], STDIN=>'t')" + assert(status.success?) + status = run_in_child "exec([#{RUBY.dump}, 'ik,'], STDIN=>'f')" + assert(!status.success?) + } + end + end -- cgit v1.2.3