diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-21 10:52:31 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-21 10:52:31 +0000 |
commit | ed2dd5e3f497448356205e5f965d55850e32bae6 (patch) | |
tree | b86b3a31332d1271f9af519e334bf2f4a788ecab /test/ruby | |
parent | daa739876f1bbd14b043a6361e9d434d324afff5 (diff) | |
download | ruby-ed2dd5e3f497448356205e5f965d55850e32bae6.tar.gz |
* io.c (rb_io_initialize): add autoclose argument to control close
at finalization. [ruby-core:26222]
* io.c (rb_io_autoclose_p, rb_io_set_autoclose): new methods.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26999 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_io.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 2da2ae95e6..98b1d7b074 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1266,6 +1266,49 @@ class TestIO < Test::Unit::TestCase f.close end + def try_fdopen(fd, autoclose = true, level = 100) + if level > 0 + try_fdopen(fd, autoclose, level - 1) + GC.start + level + else + IO.for_fd(fd, autoclose: autoclose) + nil + end + end + + def test_autoclose + feature2250 = '[ruby-core:26222]' + pre = 'ft2250' + + Tempfile.new(pre) do |t| + f = IO.for_fd(t.fileno) + assert_equal(true, f.autoclose?) + f.autoclose = false + assert_equal(false, f.autoclose?) + f.close + assert_nothing_raised(Errno::EBADF) {t.close} + + t.open + f = IO.for_fd(t.fileno, autoclose: false) + assert_equal(false, f.autoclose?) + f.autoclose = true + assert_equal(true, f.autoclose?) + f.close + assert_raise(Errno::EBADF) {t.close} + end + + Tempfile.new(pre) do |t| + try_fdopen(t.fileno) + assert_raise(Errno::EBADF) {t.close} + end + + Tempfile.new(pre) do |t| + try_fdopen(f.fileno, false) + assert_nothing_raised(Errno::EBADF) {t.close} + end + end + def test_open_redirect o = Object.new def o.to_open; self; end |