summaryrefslogtreecommitdiff
path: root/test/io/wait/test_io_wait.rb
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-04-30 16:02:11 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-04-30 16:02:11 +0000
commite140be695630daf179cd6ef1180a12409d9fc2e9 (patch)
tree6d4830feed64eed0dded8777aa29b510d7e5d693 /test/io/wait/test_io_wait.rb
parent04202dc83dde72db03d72227841c6dddbd41a925 (diff)
fix commit mistake of r31389.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31398 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/io/wait/test_io_wait.rb')
-rw-r--r--test/io/wait/test_io_wait.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/io/wait/test_io_wait.rb b/test/io/wait/test_io_wait.rb
new file mode 100644
index 00000000000..4aad7cd1063
--- /dev/null
+++ b/test/io/wait/test_io_wait.rb
@@ -0,0 +1,64 @@
+require 'test/unit'
+require 'timeout'
+begin
+ require 'io/wait'
+rescue LoadError
+end
+
+class TestIOWait < Test::Unit::TestCase
+
+ def setup
+ @r, @w = IO.pipe
+ end
+
+ def teardown
+ @r.close unless @r.closed?
+ @w.close unless @w.closed?
+ end
+
+ def test_nread
+ assert_equal 0, @r.nread
+ @w.syswrite "."
+ assert_equal 1, @r.nread
+ end
+
+ def test_nread_buffered
+ @w.syswrite ".\n!"
+ assert_equal ".\n", @r.read(2)
+ assert_equal 1, @r.nread
+ end
+
+ def test_ready?
+ refute @r.ready?
+ @w.syswrite "."
+ assert @r.ready?
+ end
+
+ def test_buffered_ready?
+ @w.syswrite ".\n!"
+ assert_equal ".\n", @r.gets
+ assert @r.ready?
+ end
+
+ def test_wait
+ assert_nil @r.wait(0)
+ @w.syswrite "."
+ assert_equal @r, @r.wait(0)
+ end
+
+ def test_wait_buffered
+ @w.syswrite ".\n!"
+ assert_equal ".\n", @r.gets
+ assert_equal true, @r.wait(0)
+ end
+
+ def test_wait_forever
+ Thread.new { sleep 0.01; @w.syswrite "." }
+ assert_equal @r, @r.wait
+ end
+
+ def test_wait_eof
+ Thread.new { sleep 0.01; @w.close }
+ assert_nil @r.wait
+ end
+end if IO.method_defined?(:wait)