File 0018-tests-add-a-few-more-tests-for-select.patch of Package ruby2.5

From 82bc3bcafc15648a1e1bb262b00486d6f883a4a0 Mon Sep 17 00:00:00 2001
From: Michal Suchanek <msuchanek@suse.de>
Date: Sat, 7 Mar 2020 02:26:55 +0100
Subject: [PATCH 18/19] tests: add a few more tests for select.

 - test select throws BADFD exception and select_with_poll does not
 - test result of selecting pipes to a running and exited process

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
 test/ruby/test_io.rb | 60 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 178e3c3d7e31..6762ff1f95ff 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -23,6 +23,10 @@ def have_close_on_exec?
     def have_nonblock?
       IO.method_defined?("nonblock=")
     end
+
+    def have_poll?
+      IO.respond_to? :select_with_poll
+    end
   end
 
   include Feature
@@ -3772,4 +3776,60 @@ def test_select_leak
       end
     end;
   end
+
+  def test_select_raise
+    require 'fcntl'
+
+    fd = STDERR.fcntl(Fcntl::F_DUPFD)
+    io = IO.for_fd(fd, mode: 'w')
+    io2 = IO.for_fd(fd, mode: 'w')
+
+    io2.close
+
+    assert_raise(Errno::EBADF) {select [io], [io], [io]}
+  end
+
+  def test_poll_no_raise
+    require 'fcntl'
+
+    fd = STDERR.fcntl(Fcntl::F_DUPFD)
+    io = IO.for_fd(fd, mode: 'w')
+    io2 = IO.for_fd(fd, mode: 'w')
+
+    io2.close
+
+    assert_equal [[],[],[],[io]], (IO.select_with_poll [io], [io], [io], [io])
+  end if have_poll?
+
+  def startcmd *cmd
+    spawn_in, pipe_in = IO.pipe
+    pipe_out, spawn_out = IO.pipe
+    pipe_err, spawn_err = IO.pipe
+    pid = spawn(*cmd, :err=>spawn_err, :out=>spawn_out, :in=>spawn_in, :close_others=>true)
+    [spawn_in, spawn_out, spawn_err].each{|fd| fd.close}
+    [[pipe_in, pipe_out, pipe_err],pid]
+  end
+
+  def endcmd stuff
+    fds, pid = stuff
+    fds.each{|fd| fd.close rescue nil}
+    Process.waitpid pid
+  end
+
+  def test_select_cat
+    stuff = startcmd *%w(cat)
+    fds = stuff[0]
+    assert_equal [[],[fds[0]],[]], (IO.select fds, fds, fds, 0)
+    assert_equal [[],[fds[0]],[],[]], (IO.select_with_poll fds, fds, fds, fds, 0) if have_poll?
+    endcmd stuff
+  end
+
+  def test_select_uname
+    stuff = startcmd *%w(uname -a)
+    fds = stuff[0]
+    sleep 0.1
+    assert_equal [[fds[0],fds[1],fds[2]],[fds[0]],[]], (IO.select fds, fds, fds, 0)
+    assert_equal [[fds[1]],[fds[0]],[],[fds[0],fds[1],fds[2]]], (IO.select_with_poll fds, fds, fds, fds, 0) if have_poll?
+    endcmd stuff
+  end
 end
-- 
2.26.2

openSUSE Build Service is sponsored by