diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-17 18:02:53 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-17 18:02:53 +0000 |
commit | d4454d0123214c95b4fb6f3c7846e2858ad3fd99 (patch) | |
tree | fcab5233ebdc658fda03cbf45d9d2817c3ccd6bc /test | |
parent | ab742d9d2ee6f56d987b17ebd1795d5922c47172 (diff) | |
download | ruby-d4454d0123214c95b4fb6f3c7846e2858ad3fd99.tar.gz |
io.c (argf_read_nonblock): support `exception: false'
This is a preparation for [ruby-core:69892]
("io.c: avoid kwarg parsing in C API")
since I noticed ARGF.read_nonblock did not properly catch up to
the `exception: false' change.
* io.c (argf_read_nonblock): support `exception: false'
(io_nonblock_eof): new function
(io_read_nonblock): use io_nonblock_eof
(argf_getpartial): accept kwargs hash for `exception: false'
* test/ruby/test_argf.rb (test_read_nonblock): new test
[ruby-core:70000] [Feature #11358]
* NEWS: add item for ARGF.read_nonblock
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_argf.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb index 6975b83a28..a9ba9f64e2 100644 --- a/test/ruby/test_argf.rb +++ b/test/ruby/test_argf.rb @@ -856,4 +856,47 @@ class TestArgf < Test::Unit::TestCase assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read)) end end + + def test_read_nonblock + ruby('-e', <<-SRC) do |f| + $stdout.sync = true + :wait_readable == ARGF.read_nonblock(1, "", exception: false) or + abort "did not return :wait_readable" + + begin + ARGF.read_nonblock(1) + abort 'fail to raise IO::WaitReadable' + rescue IO::WaitReadable + end + puts 'starting select' + + IO.select([ARGF]) == [[ARGF], [], []] or + abort 'did not awaken for readability (before byte)' + + buf = '' + buf.object_id == ARGF.read_nonblock(1, buf).object_id or + abort "read destination buffer failed" + print buf + + IO.select([ARGF]) == [[ARGF], [], []] or + abort 'did not awaken for readability (before EOF)' + + ARGF.read_nonblock(1, buf, exception: false) == nil or + abort "EOF should return nil if exception: false" + + begin + ARGF.read_nonblock(1, buf) + abort 'fail to raise IO::WaitReadable' + rescue EOFError + puts 'done with eof' + end + SRC + f.sync = true + assert_equal "starting select\n", f.gets + f.write('.') # wake up from IO.select + assert_equal '.', f.read(1) + f.close_write + assert_equal "done with eof\n", f.gets + end + end end |