aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_io.rb
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-05 20:10:50 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-05 20:10:50 +0000
commit1c4e6066bede05c7c437b7690ce67ef9e51439c0 (patch)
treeec39d2ff9253336c78b0fce0c5699d4858062263 /test/ruby/test_io.rb
parentc8d6b6e8fa5b3309d5ac1c879ebb69da814e1d1f (diff)
downloadruby-1c4e6066bede05c7c437b7690ce67ef9e51439c0.tar.gz
Split one big test to seven tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_io.rb')
-rw-r--r--test/ruby/test_io.rb117
1 files changed, 75 insertions, 42 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index be5a3331f0..8dd1f10480 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -534,10 +534,8 @@ class TestIO < Test::Unit::TestCase
end
end
- def test_copy_stream_socket
- return unless defined? UNIXSocket
+ def test_copy_stream_socket1
mkcdtmpdir {
-
content = "foobar"
File.open("src", "w") {|f| f << content }
@@ -547,7 +545,11 @@ class TestIO < Test::Unit::TestCase
s1.close
assert_equal(content, s2.read)
}
+ }
+ end if defined? UNIXSocket
+ def test_copy_stream_socket2
+ mkcdtmpdir {
bigcontent = "abc" * 123456
File.open("bigsrc", "w") {|f| f << bigcontent }
@@ -559,6 +561,13 @@ class TestIO < Test::Unit::TestCase
result = t.value
assert_equal(bigcontent, result)
}
+ }
+ end if defined? UNIXSocket
+
+ def test_copy_stream_socket3
+ mkcdtmpdir {
+ bigcontent = "abc" * 123456
+ File.open("bigsrc", "w") {|f| f << bigcontent }
with_socketpair {|s1, s2|
t = Thread.new { s2.read }
@@ -568,6 +577,13 @@ class TestIO < Test::Unit::TestCase
result = t.value
assert_equal(bigcontent[0,10000], result)
}
+ }
+ end if defined? UNIXSocket
+
+ def test_copy_stream_socket4
+ mkcdtmpdir {
+ bigcontent = "abc" * 123456
+ File.open("bigsrc", "w") {|f| f << bigcontent }
File.open("bigsrc") {|f|
assert_equal(0, f.pos)
@@ -581,6 +597,13 @@ class TestIO < Test::Unit::TestCase
assert_equal(bigcontent[100..-1], result)
}
}
+ }
+ end if defined? UNIXSocket
+
+ def test_copy_stream_socket5
+ mkcdtmpdir {
+ bigcontent = "abc" * 123456
+ File.open("bigsrc", "w") {|f| f << bigcontent }
File.open("bigsrc") {|f|
assert_equal(bigcontent[0,100], f.read(100))
@@ -595,54 +618,64 @@ class TestIO < Test::Unit::TestCase
assert_equal(bigcontent[100..-1], result)
}
}
+ }
+ end if defined? UNIXSocket
+ def test_copy_stream_socket6
+ mkcdtmpdir {
megacontent = "abc" * 1234567
File.open("megasrc", "w") {|f| f << megacontent }
- if have_nonblock?
- with_socketpair {|s1, s2|
- begin
- s1.nonblock = true
- rescue Errno::EBADF
- skip "nonblocking IO for pipe is not implemented"
- end
- t = Thread.new { s2.read }
- ret = IO.copy_stream("megasrc", s1)
- assert_equal(megacontent.bytesize, ret)
- s1.close
- result = t.value
- assert_equal(megacontent, result)
- }
- with_socketpair {|s1, s2|
+ with_socketpair {|s1, s2|
+ begin
+ s1.nonblock = true
+ rescue Errno::EBADF
+ skip "nonblocking IO for pipe is not implemented"
+ end
+ t = Thread.new { s2.read }
+ ret = IO.copy_stream("megasrc", s1)
+ assert_equal(megacontent.bytesize, ret)
+ s1.close
+ result = t.value
+ assert_equal(megacontent, result)
+ }
+ }
+ end if defined? UNIXSocket
+
+ def test_copy_stream_socket7
+ mkcdtmpdir {
+ megacontent = "abc" * 1234567
+ File.open("megasrc", "w") {|f| f << megacontent }
+
+ with_socketpair {|s1, s2|
+ begin
+ s1.nonblock = true
+ rescue Errno::EBADF
+ skip "nonblocking IO for pipe is not implemented"
+ end
+ trapping_usr1 do
+ nr = 30
begin
- s1.nonblock = true
- rescue Errno::EBADF
- skip "nonblocking IO for pipe is not implemented"
- end
- trapping_usr1 do
- nr = 30
- begin
- pid = fork do
- s1.close
- IO.select([s2])
- Process.kill(:USR1, Process.ppid)
- s2.read
- end
- s2.close
- nr.times do
- assert_equal megacontent.bytesize, IO.copy_stream("megasrc", s1)
- end
- assert_equal(1, @usr1_rcvd)
- ensure
+ pid = fork do
s1.close
- _, status = Process.waitpid2(pid) if pid
+ IO.select([s2])
+ Process.kill(:USR1, Process.ppid)
+ s2.read
end
- assert status.success?, status.inspect
+ s2.close
+ nr.times do
+ assert_equal megacontent.bytesize, IO.copy_stream("megasrc", s1)
+ end
+ assert_equal(1, @usr1_rcvd)
+ ensure
+ s1.close
+ _, status = Process.waitpid2(pid) if pid
end
- }
- end
+ assert status.success?, status.inspect
+ end
+ }
}
- end
+ end if defined? UNIXSocket and IO.method_defined?("nonblock=")
def test_copy_stream_strio
src = StringIO.new("abcd")