summaryrefslogtreecommitdiff
path: root/test/io/wait
diff options
context:
space:
mode:
Diffstat (limited to 'test/io/wait')
-rw-r--r--test/io/wait/test_io_wait.rb37
-rw-r--r--test/io/wait/test_io_wait_uncommon.rb5
-rw-r--r--test/io/wait/test_ractor.rb7
3 files changed, 36 insertions, 13 deletions
diff --git a/test/io/wait/test_io_wait.rb b/test/io/wait/test_io_wait.rb
index 6b4722e1be..cbc01f9622 100644
--- a/test/io/wait/test_io_wait.rb
+++ b/test/io/wait/test_io_wait.rb
@@ -3,10 +3,9 @@
require 'test/unit'
require 'timeout'
require 'socket'
-begin
- require 'io/wait'
-rescue LoadError
-end
+
+# For `IO#ready?` and `IO#nread`:
+require 'io/wait'
class TestIOWait < Test::Unit::TestCase
@@ -37,6 +36,7 @@ class TestIOWait < Test::Unit::TestCase
end
def test_ready?
+ omit 'unstable on MinGW' if /mingw/ =~ RUBY_PLATFORM
assert_not_predicate @r, :ready?, "shouldn't ready, but ready"
@w.syswrite "."
sleep 0.1
@@ -50,6 +50,7 @@ class TestIOWait < Test::Unit::TestCase
end
def test_wait
+ omit 'unstable on MinGW' if /mingw/ =~ RUBY_PLATFORM
assert_nil @r.wait(0)
@w.syswrite "."
sleep 0.1
@@ -161,6 +162,34 @@ class TestIOWait < Test::Unit::TestCase
assert_equal @w, @w.wait(0.01, :read_write)
end
+ def test_wait_mask_writable
+ omit("Missing IO::WRITABLE!") unless IO.const_defined?(:WRITABLE)
+ assert_equal IO::WRITABLE, @w.wait(IO::WRITABLE, 0)
+ end
+
+ def test_wait_mask_readable
+ omit("Missing IO::READABLE!") unless IO.const_defined?(:READABLE)
+ @w.write("Hello World\n" * 3)
+ assert_equal IO::READABLE, @r.wait(IO::READABLE, 0)
+
+ @r.gets
+ assert_equal IO::READABLE, @r.wait(IO::READABLE, 0)
+ end
+
+ def test_wait_mask_zero
+ omit("Missing IO::WRITABLE!") unless IO.const_defined?(:WRITABLE)
+ assert_raise(ArgumentError) do
+ @w.wait(0, 0)
+ end
+ end
+
+ def test_wait_mask_negative
+ omit("Missing IO::WRITABLE!") unless IO.const_defined?(:WRITABLE)
+ assert_raise(ArgumentError) do
+ @w.wait(-6, 0)
+ end
+ end
+
private
def fill_pipe
diff --git a/test/io/wait/test_io_wait_uncommon.rb b/test/io/wait/test_io_wait_uncommon.rb
index b6f1c29bcd..0f922f4e24 100644
--- a/test/io/wait/test_io_wait_uncommon.rb
+++ b/test/io/wait/test_io_wait_uncommon.rb
@@ -1,6 +1,5 @@
# frozen_string_literal: true
require 'test/unit'
-require 'io/wait'
# test uncommon device types to check portability problems
# We may optimize IO#wait_*able for non-Linux kernels in the future
@@ -13,7 +12,7 @@ class TestIOWaitUncommon < Test::Unit::TestCase
end
def test_fifo_wait
- skip 'no mkfifo' unless File.respond_to?(:mkfifo) && IO.const_defined?(:NONBLOCK)
+ omit 'no mkfifo' unless File.respond_to?(:mkfifo) && IO.const_defined?(:NONBLOCK)
require 'tmpdir'
Dir.mktmpdir('rubytest-fifo') do |dir|
fifo = "#{dir}/fifo"
@@ -45,7 +44,7 @@ class TestIOWaitUncommon < Test::Unit::TestCase
rescue Errno::ENOENT
return # Ignore silently
rescue SystemCallError => e
- skip "#{dev} could not be opened #{e.message} (#{e.class})"
+ omit "#{dev} could not be opened #{e.message} (#{e.class})"
end
if block
yield fp
diff --git a/test/io/wait/test_ractor.rb b/test/io/wait/test_ractor.rb
index 3d286af77f..800216e610 100644
--- a/test/io/wait/test_ractor.rb
+++ b/test/io/wait/test_ractor.rb
@@ -1,13 +1,8 @@
# frozen_string_literal: true
require 'test/unit'
require 'rbconfig'
-require 'io/wait'
class TestIOWaitInRactor < Test::Unit::TestCase
- def setup
- omit unless defined? Ractor
- end
-
def test_ractor
ext = "/io/wait.#{RbConfig::CONFIG['DLEXT']}"
path = $".find {|path| path.end_with?(ext)}
@@ -19,4 +14,4 @@ class TestIOWaitInRactor < Test::Unit::TestCase
puts r.take
end;
end
-end
+end if defined? Ractor