summaryrefslogtreecommitdiff
path: root/test/ruby/test_io.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_io.rb')
-rw-r--r--test/ruby/test_io.rb59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 5cda6c9e5a..4f002e8b3d 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -1205,6 +1205,16 @@ class TestIO < Test::Unit::TestCase
}
end
+ def test_write_nonblock_simple_no_exceptions
+ skip "IO#write_nonblock is not supported on file/pipe." if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
+ pipe(proc do |w|
+ w.write_nonblock('1', exception: false)
+ w.close
+ end, proc do |r|
+ assert_equal("1", r.read)
+ end)
+ end
+
def test_read_nonblock_error
return if !have_nonblock?
skip "IO#read_nonblock is not supported on file/pipe." if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
@@ -1215,6 +1225,41 @@ class TestIO < Test::Unit::TestCase
assert_kind_of(IO::WaitReadable, $!)
end
}
+
+ with_pipe {|r, w|
+ begin
+ r.read_nonblock 4096, ""
+ rescue Errno::EWOULDBLOCK
+ assert_kind_of(IO::WaitReadable, $!)
+ end
+ }
+ end
+
+ def test_read_nonblock_no_exceptions
+ return if !have_nonblock?
+ skip "IO#read_nonblock is not supported on file/pipe." if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
+ with_pipe {|r, w|
+ assert_equal :wait_readable, r.read_nonblock(4096, exception: false)
+ w.puts "HI!"
+ assert_equal "HI!\n", r.read_nonblock(4096, exception: false)
+ w.close
+ assert_equal nil, r.read_nonblock(4096, exception: false)
+ }
+ end
+
+ def test_read_nonblock_with_buffer_no_exceptions
+ return if !have_nonblock?
+ skip "IO#read_nonblock is not supported on file/pipe." if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
+ with_pipe {|r, w|
+ assert_equal :wait_readable, r.read_nonblock(4096, "", exception: false)
+ w.puts "HI!"
+ buf = "buf"
+ value = r.read_nonblock(4096, buf, exception: false)
+ assert_equal value, "HI!\n"
+ assert buf.equal?(value)
+ w.close
+ assert_equal nil, r.read_nonblock(4096, "", exception: false)
+ }
end
def test_write_nonblock_error
@@ -1231,6 +1276,20 @@ class TestIO < Test::Unit::TestCase
}
end
+ def test_write_nonblock_no_exceptions
+ return if !have_nonblock?
+ skip "IO#write_nonblock is not supported on file/pipe." if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
+ with_pipe {|r, w|
+ loop {
+ ret = w.write_nonblock("a"*100000, exception: false)
+ if ret.is_a?(Symbol)
+ assert_equal :wait_writable, ret
+ break
+ end
+ }
+ }
+ end
+
def test_gets
pipe(proc do |w|
w.write "foobarbaz"