mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test_process.rb: split
* test/ruby/test_process.rb (test_execopts_redirect): split large test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7307c32f1f
commit
3977132bbb
1 changed files with 69 additions and 63 deletions
|
@ -461,7 +461,7 @@ class TestProcess < Test::Unit::TestCase
|
||||||
SORT = [RUBY, '-e', "puts ARGF.readlines.sort"]
|
SORT = [RUBY, '-e', "puts ARGF.readlines.sort"]
|
||||||
CAT = [RUBY, '-e', "IO.copy_stream STDIN, STDOUT"]
|
CAT = [RUBY, '-e', "IO.copy_stream STDIN, STDOUT"]
|
||||||
|
|
||||||
def test_execopts_redirect
|
def test_execopts_redirect_fd
|
||||||
with_tmpchdir {|d|
|
with_tmpchdir {|d|
|
||||||
Process.wait Process.spawn(*ECHO["a"], STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644])
|
Process.wait Process.spawn(*ECHO["a"], STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644])
|
||||||
assert_equal("a", File.read("out").chomp)
|
assert_equal("a", File.read("out").chomp)
|
||||||
|
@ -533,76 +533,82 @@ class TestProcess < Test::Unit::TestCase
|
||||||
assert_equal("bb\naa\n", File.read("out"))
|
assert_equal("bb\naa\n", File.read("out"))
|
||||||
system(*SORT, STDIN=>["out"], STDOUT=>"out2")
|
system(*SORT, STDIN=>["out"], STDOUT=>"out2")
|
||||||
assert_equal("aa\nbb\n", File.read("out2"))
|
assert_equal("aa\nbb\n", File.read("out2"))
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
with_pipe {|r1, w1|
|
def test_execopts_redirect_pipe
|
||||||
with_pipe {|r2, w2|
|
with_pipe {|r1, w1|
|
||||||
opts = {STDIN=>r1, STDOUT=>w2}
|
with_pipe {|r2, w2|
|
||||||
opts.merge(w1=>:close, r2=>:close) unless windows?
|
opts = {STDIN=>r1, STDOUT=>w2}
|
||||||
pid = spawn(*SORT, opts)
|
opts.merge(w1=>:close, r2=>:close) unless windows?
|
||||||
r1.close
|
pid = spawn(*SORT, opts)
|
||||||
w2.close
|
r1.close
|
||||||
w1.puts "c"
|
w2.close
|
||||||
w1.puts "a"
|
w1.puts "c"
|
||||||
w1.puts "b"
|
w1.puts "a"
|
||||||
w1.close
|
w1.puts "b"
|
||||||
assert_equal("a\nb\nc\n", r2.read)
|
w1.close
|
||||||
r2.close
|
assert_equal("a\nb\nc\n", r2.read)
|
||||||
Process.wait(pid)
|
r2.close
|
||||||
|
Process.wait(pid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unless windows?
|
||||||
|
# passing non-stdio fds is not supported on Windows
|
||||||
|
with_pipes(5) {|pipes|
|
||||||
|
ios = pipes.flatten
|
||||||
|
h = {}
|
||||||
|
ios.length.times {|i| h[ios[i]] = ios[(i-1)%ios.length] }
|
||||||
|
h2 = h.invert
|
||||||
|
_rios = pipes.map {|r, w| r }
|
||||||
|
wios = pipes.map {|r, w| w }
|
||||||
|
child_wfds = wios.map {|w| h2[w].fileno }
|
||||||
|
pid = spawn(RUBY, "-e",
|
||||||
|
"[#{child_wfds.join(',')}].each {|fd| IO.new(fd, 'w').puts fd }", h)
|
||||||
|
pipes.each {|r, w|
|
||||||
|
assert_equal("#{h2[w].fileno}\n", r.gets)
|
||||||
}
|
}
|
||||||
|
Process.wait pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
unless windows?
|
with_pipes(5) {|pipes|
|
||||||
# passing non-stdio fds is not supported on Windows
|
ios = pipes.flatten
|
||||||
with_pipes(5) {|pipes|
|
h = {}
|
||||||
ios = pipes.flatten
|
ios.length.times {|i| h[ios[i]] = ios[(i+1)%ios.length] }
|
||||||
h = {}
|
h2 = h.invert
|
||||||
ios.length.times {|i| h[ios[i]] = ios[(i-1)%ios.length] }
|
_rios = pipes.map {|r, w| r }
|
||||||
h2 = h.invert
|
wios = pipes.map {|r, w| w }
|
||||||
_rios = pipes.map {|r, w| r }
|
child_wfds = wios.map {|w| h2[w].fileno }
|
||||||
wios = pipes.map {|r, w| w }
|
pid = spawn(RUBY, "-e",
|
||||||
child_wfds = wios.map {|w| h2[w].fileno }
|
"[#{child_wfds.join(',')}].each {|fd| IO.new(fd, 'w').puts fd }", h)
|
||||||
pid = spawn(RUBY, "-e",
|
pipes.each {|r, w|
|
||||||
"[#{child_wfds.join(',')}].each {|fd| IO.new(fd, 'w').puts fd }", h)
|
assert_equal("#{h2[w].fileno}\n", r.gets)
|
||||||
pipes.each {|r, w|
|
|
||||||
assert_equal("#{h2[w].fileno}\n", r.gets)
|
|
||||||
}
|
|
||||||
Process.wait pid;
|
|
||||||
}
|
}
|
||||||
|
Process.wait pid
|
||||||
|
}
|
||||||
|
|
||||||
with_pipes(5) {|pipes|
|
closed_fd = nil
|
||||||
ios = pipes.flatten
|
with_pipes(5) {|pipes|
|
||||||
h = {}
|
io = pipes.last.last
|
||||||
ios.length.times {|i| h[ios[i]] = ios[(i+1)%ios.length] }
|
closed_fd = io.fileno
|
||||||
h2 = h.invert
|
}
|
||||||
_rios = pipes.map {|r, w| r }
|
assert_raise(Errno::EBADF) { Process.wait spawn(*TRUECOMMAND, closed_fd=>closed_fd) }
|
||||||
wios = pipes.map {|r, w| w }
|
|
||||||
child_wfds = wios.map {|w| h2[w].fileno }
|
with_pipe {|r, w|
|
||||||
pid = spawn(RUBY, "-e",
|
if w.respond_to?(:"close_on_exec=")
|
||||||
"[#{child_wfds.join(',')}].each {|fd| IO.new(fd, 'w').puts fd }", h)
|
w.close_on_exec = true
|
||||||
pipes.each {|r, w|
|
pid = spawn(RUBY, "-e", "IO.new(#{w.fileno}, 'w').print 'a'", w=>w)
|
||||||
assert_equal("#{h2[w].fileno}\n", r.gets)
|
w.close
|
||||||
}
|
assert_equal("a", r.read)
|
||||||
Process.wait pid
|
Process.wait pid
|
||||||
}
|
end
|
||||||
|
}
|
||||||
closed_fd = nil
|
end
|
||||||
with_pipes(5) {|pipes|
|
end
|
||||||
io = pipes.last.last
|
|
||||||
closed_fd = io.fileno
|
|
||||||
}
|
|
||||||
assert_raise(Errno::EBADF) { Process.wait spawn(*TRUECOMMAND, closed_fd=>closed_fd) }
|
|
||||||
|
|
||||||
with_pipe {|r, w|
|
|
||||||
if w.respond_to?(:"close_on_exec=")
|
|
||||||
w.close_on_exec = true
|
|
||||||
pid = spawn(RUBY, "-e", "IO.new(#{w.fileno}, 'w').print 'a'", w=>w)
|
|
||||||
w.close
|
|
||||||
assert_equal("a", r.read)
|
|
||||||
Process.wait pid
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
|
def test_execopts_redirect_symbol
|
||||||
|
with_tmpchdir {|d|
|
||||||
system(*ECHO["funya"], :out=>"out")
|
system(*ECHO["funya"], :out=>"out")
|
||||||
assert_equal("funya\n", File.read("out"))
|
assert_equal("funya\n", File.read("out"))
|
||||||
system(RUBY, '-e', 'STDOUT.reopen(STDERR); puts "henya"', :err=>"out")
|
system(RUBY, '-e', 'STDOUT.reopen(STDERR); puts "henya"', :err=>"out")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue