diff options
author | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-06-22 06:50:32 +0000 |
---|---|---|
committer | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-06-22 06:50:32 +0000 |
commit | d6ed84edcd9d9e6f56aafe604f750781f0d62be7 (patch) | |
tree | 3e9967a80821a0c38f456b1b6d803bc2a172a97e /test/ruby | |
parent | cf6a83c574ae17d5fe54be94b2a213305a06bde3 (diff) | |
download | ruby-d6ed84edcd9d9e6f56aafe604f750781f0d62be7.tar.gz |
Allow IO#reopen to take a block
* io.c (rb_io_reopen): take a block and ensure the IO closed
[Feature #2631]
* test/ruby/test_io.rb: add a test
* NEWS: add an entry for this change
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_io.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 791e52b500..186c148159 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -2156,6 +2156,22 @@ class TestIO < Test::Unit::TestCase } end + def test_reopen_with_block + make_tempfile {|t| + open(__FILE__) do |f| + f.gets + assert_nothing_raised { + reopened = nil + f.reopen(t.path) do |_reopened| + reopened = _reopened + assert_equal("foo\n", reopened.gets) + end + assert_equal(true, reopened.closed?) + } + end + } + end + def test_reopen_inherit mkcdtmpdir { system(EnvUtil.rubybin, '-e', <<"End") |