diff options
-rw-r--r-- | test/helper.rb | 9 | ||||
-rw-r--r-- | test/test_epoll.rb | 6 | ||||
-rw-r--r-- | test/test_eventfd.rb | 6 | ||||
-rw-r--r-- | test/test_inotify.rb | 6 | ||||
-rw-r--r-- | test/test_timerfd.rb | 6 |
5 files changed, 13 insertions, 20 deletions
diff --git a/test/helper.rb b/test/helper.rb index 13f79b7..8261168 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -6,3 +6,12 @@ Testcase = begin rescue NameError Minitest::Unit::TestCase # minitest 4 end + +def check_cloexec(io) + pipe = IO.pipe + rbimp = Fcntl::FD_CLOEXEC & pipe[0].fcntl(Fcntl::F_GETFD) + ours = Fcntl::FD_CLOEXEC & io.fcntl(Fcntl::F_GETFD) + assert_equal rbimp, ours, "CLOEXEC default does not match Ruby implementation" +ensure + pipe.each { |io| io.close } +end diff --git a/test/test_epoll.rb b/test/test_epoll.rb index 88d0b6c..61b6e8c 100644 --- a/test/test_epoll.rb +++ b/test/test_epoll.rb @@ -348,11 +348,7 @@ class TestEpoll < Testcase def test_new @ep.close io = Epoll.new.to_io - if RUBY_VERSION.to_f >= 2.0 - assert_equal 1, io.fcntl(Fcntl::F_GETFD) - else - assert_equal 0, io.fcntl(Fcntl::F_GETFD) - end + check_cloexec(io) end def test_delete diff --git a/test/test_eventfd.rb b/test/test_eventfd.rb index 731a6cb..a6b3016 100644 --- a/test/test_eventfd.rb +++ b/test/test_eventfd.rb @@ -20,11 +20,7 @@ class TestEventFD < Testcase def test_new efd = EventFD.new 0 assert_kind_of(IO, efd) - if RUBY_VERSION.to_f >= 2.0 - assert_equal 1, efd.fcntl(Fcntl::F_GETFD) - else - assert_equal 0, efd.fcntl(Fcntl::F_GETFD) - end + check_cloexec(efd) end def test_new_nonblock diff --git a/test/test_inotify.rb b/test/test_inotify.rb index c91d6e4..5cf5839 100644 --- a/test/test_inotify.rb +++ b/test/test_inotify.rb @@ -17,11 +17,7 @@ class TestInotify < Testcase def test_new @ino = Inotify.new assert_kind_of(IO, ino) - if RUBY_VERSION.to_f >= 2.0 - assert_equal 1, ino.fcntl(Fcntl::F_GETFD) - else - assert_equal 0, ino.fcntl(Fcntl::F_GETFD) - end + check_cloexec(ino) end def test_constants diff --git a/test/test_timerfd.rb b/test/test_timerfd.rb index 23940a1..6189168 100644 --- a/test/test_timerfd.rb +++ b/test/test_timerfd.rb @@ -15,11 +15,7 @@ class TestTimerFD < Testcase def test_create tfd = TimerFD.new assert_kind_of(IO, tfd) - if RUBY_VERSION.to_f >= 2.0 - assert_equal 1, tfd.fcntl(Fcntl::F_GETFD) - else - assert_equal 0, tfd.fcntl(Fcntl::F_GETFD) - end + check_cloexec(tfd) end def test_create_nonblock |