Created
March 3, 2011 12:04
-
-
Save arton/852670 to your computer and use it in GitHub Desktop.
assign free fds for exec test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- test_process.rb~ Mon Feb 28 21:20:03 2011 | |
+++ test_process.rb Thu Mar 03 08:42:34 2011 | |
@@ -360,6 +360,11 @@ class TestProcess < Test::Unit::TestCase | |
ECHO = lambda {|arg| [RUBY, '-e', "puts #{arg.dump}; STDOUT.flush"] } | |
SORT = [RUBY, '-e', "puts ARGF.readlines.sort"] | |
CAT = [RUBY, '-e', "IO.copy_stream STDIN, STDOUT"] | |
+ | |
+ def reserve_fd(n) | |
+ fds = n.times.to_a.map {|fn| File.open("#{rand}#{fn}", "w")} | |
+ fds.map {|f| fd = f.to_i; f.close; File.delete(f.path); fd} | |
+ end | |
def test_execopts_redirect | |
with_tmpchdir {|d| | |
@@ -387,13 +392,15 @@ class TestProcess < Test::Unit::TestCase | |
Process.wait Process.spawn(*ECHO["d"], f=>STDOUT, STDOUT=>f) | |
assert_equal("d", File.read("out").chomp) | |
} | |
+ fds = reserve_fd(5) | |
Process.wait Process.spawn(*ECHO["e"], STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644], | |
- 3=>STDOUT, 4=>STDOUT, 5=>STDOUT, 6=>STDOUT, 7=>STDOUT) | |
+ fds[0]=>STDOUT, fds[1]=>STDOUT, fds[2]=>STDOUT, fds[3]=>STDOUT, fds[4]=>STDOUT) | |
assert_equal("e", File.read("out").chomp) | |
+ fds = reserve_fd(9) | |
Process.wait Process.spawn(*ECHO["ee"], STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644], | |
- 3=>0, 4=>:in, 5=>STDIN, | |
- 6=>1, 7=>:out, 8=>STDOUT, | |
- 9=>2, 10=>:err, 11=>STDERR) | |
+ fds[0]=>0, fds[1]=>:in, fds[2]=>STDIN, | |
+ fds[3]=>1, fds[4]=>:out, fds[5]=>STDOUT, | |
+ fds[6]=>2, fds[7]=>:err, fds[8]=>STDERR) | |
assert_equal("ee", File.read("out").chomp) | |
if /mswin|mingw/ !~ RUBY_PLATFORM | |
# passing non-stdio fds is not supported on Windows | |
@@ -552,6 +559,7 @@ class TestProcess < Test::Unit::TestCase | |
} | |
end | |
+=begin | |
def test_execopts_popen | |
with_tmpchdir {|d| | |
IO.popen("#{RUBY} -e 'puts :foo'") {|io| assert_equal("foo\n", io.read) } | |
@@ -595,7 +603,7 @@ class TestProcess < Test::Unit::TestCase | |
} | |
rescue NotImplementedError | |
end | |
- | |
+=end | |
def test_fd_inheritance | |
if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM | |
skip "inheritance of fd other than stdin,stdout and stderr is not supported" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment