summaryrefslogtreecommitdiff
path: root/test/io
diff options
context:
space:
mode:
Diffstat (limited to 'test/io')
-rw-r--r--test/io/console/test_io_console.rb66
-rw-r--r--test/io/nonblock/test_flush.rb2
-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
5 files changed, 93 insertions, 24 deletions
diff --git a/test/io/console/test_io_console.rb b/test/io/console/test_io_console.rb
index 3d12b1f463..0a113ebd2f 100644
--- a/test/io/console/test_io_console.rb
+++ b/test/io/console/test_io_console.rb
@@ -7,8 +7,15 @@ rescue LoadError
end
class TestIO_Console < Test::Unit::TestCase
- PATHS = $LOADED_FEATURES.grep(%r"/io/console(?:\.#{RbConfig::CONFIG['DLEXT']}|\.rb|/\w+\.rb)\z") {$`}
+ begin
+ PATHS = $LOADED_FEATURES.grep(%r"/io/console(?:\.#{RbConfig::CONFIG['DLEXT']}|\.rb|/\w+\.rb)\z") {$`}
+ rescue Encoding::CompatibilityError
+ $stderr.puts "test_io_console.rb debug"
+ $LOADED_FEATURES.each{|path| $stderr.puts [path, path.encoding].inspect}
+ raise
+ end
PATHS.uniq!
+ INCLUDE_OPTS = "-I#{PATHS.join(File::PATH_SEPARATOR)}"
# FreeBSD seems to hang on TTOU when running parallel tests
# tested on FreeBSD 11.x.
@@ -30,18 +37,27 @@ class TestIO_Console < Test::Unit::TestCase
trap(:TTOU, @old_ttou) if defined?(@old_ttou) and @old_ttou
end
+ exceptions = %w[ENODEV ENOTTY EBADF ENXIO].map {|e|
+ Errno.const_get(e) if Errno.const_defined?(e)
+ }
+ exceptions.compact!
+ FailedPathExceptions = (exceptions unless exceptions.empty?)
+
def test_failed_path
- exceptions = %w[ENODEV ENOTTY EBADF ENXIO].map {|e|
- Errno.const_get(e) if Errno.const_defined?(e)
- }
- exceptions.compact!
- omit if exceptions.empty?
File.open(IO::NULL) do |f|
- e = assert_raise(*exceptions) do
+ e = assert_raise(*FailedPathExceptions) do
f.echo?
end
assert_include(e.message, IO::NULL)
end
+ end if FailedPathExceptions
+
+ def test_bad_keyword
+ assert_raise_with_message(ArgumentError, /unknown keyword:.*bad/) do
+ File.open(IO::NULL) do |f|
+ f.raw(bad: 0)
+ end
+ end
end
end
@@ -226,7 +242,6 @@ defined?(PTY) and defined?(IO.console) and TestIO_Console.class_eval do
end
def test_getpass
- omit unless IO.method_defined?("getpass")
run_pty("p IO.console.getpass('> ')") do |r, w|
assert_equal("> ", r.readpartial(10))
sleep 0.1
@@ -244,6 +259,15 @@ defined?(PTY) and defined?(IO.console) and TestIO_Console.class_eval do
assert_equal("\r\n", r.gets)
assert_equal("\"asdf\"", r.gets.chomp)
end
+
+ run_pty("$VERBOSE, $/ = nil, '.'; p IO.console.getpass('> ')") do |r, w|
+ assert_equal("> ", r.readpartial(10))
+ sleep 0.1
+ w.print "asdf\n"
+ sleep 0.1
+ assert_equal("\r\n", r.gets)
+ assert_equal("\"asdf\"", r.gets.chomp)
+ end
end
def test_iflush
@@ -351,6 +375,15 @@ defined?(PTY) and defined?(IO.console) and TestIO_Console.class_eval do
end
def test_intr
+ # This test fails randomly on FreeBSD 13
+ # http://rubyci.s3.amazonaws.com/freebsd13/ruby-master/log/20220304T163001Z.fail.html.gz
+ #
+ # 1) Failure:
+ # TestIO_Console#test_intr [/usr/home/chkbuild/chkbuild/tmp/build/20220304T163001Z/ruby/test/io/console/test_io_console.rb:387]:
+ # <"25"> expected but was
+ # <"-e:12:in `p': \e[1mexecution expired (\e[1;4mTimeout::Error\e[m\e[1m)\e[m">.
+ omit if /freebsd/ =~ RUBY_PLATFORM
+
run_pty("#{<<~"begin;"}\n#{<<~'end;'}") do |r, w, _|
begin;
require 'timeout'
@@ -375,7 +408,7 @@ defined?(PTY) and defined?(IO.console) and TestIO_Console.class_eval do
if cc = ctrl["intr"]
assert_ctrl("#{cc.ord}", cc, r, w)
assert_ctrl("#{cc.ord}", cc, r, w)
- assert_ctrl("Interrupt", cc, r, w) unless /linux/ =~ RUBY_PLATFORM
+ assert_ctrl("Interrupt", cc, r, w) unless /linux|solaris/ =~ RUBY_PLATFORM
end
if cc = ctrl["dsusp"]
assert_ctrl("#{cc.ord}", cc, r, w)
@@ -401,6 +434,10 @@ defined?(PTY) and defined?(IO.console) and TestIO_Console.class_eval do
assert_equal(["true"], run_pty("IO.console(:close); p IO.console(:tty?)"))
end
+ def test_console_kw
+ assert_equal(["File"], run_pty("IO.console.close; p IO.console(:clone, freeze: true).class"))
+ end
+
def test_sync
assert_equal(["true"], run_pty("p IO.console.sync"))
end
@@ -421,7 +458,9 @@ defined?(PTY) and defined?(IO.console) and TestIO_Console.class_eval do
def run_pty(src, n = 1)
pend("PTY.spawn cannot control terminal on JRuby") if RUBY_ENGINE == 'jruby'
- r, w, pid = PTY.spawn(EnvUtil.rubybin, "-I#{TestIO_Console::PATHS.join(File::PATH_SEPARATOR)}", "-rio/console", "-e", src)
+ args = [TestIO_Console::INCLUDE_OPTS, "-rio/console", "-e", src]
+ args.shift if args.first == "-I" # statically linked
+ r, w, pid = PTY.spawn(EnvUtil.rubybin, *args)
rescue RuntimeError
omit $!
else
@@ -477,6 +516,12 @@ defined?(IO.console) and TestIO_Console.class_eval do
IO.console(:close)
end
+ def test_console_kw
+ io = IO.console(:clone, freeze: true)
+ io.close
+ assert_kind_of(IO, io)
+ end
+
def test_sync
assert(IO.console.sync, "console should be unbuffered")
ensure
@@ -507,6 +552,7 @@ defined?(IO.console) and TestIO_Console.class_eval do
t2 = Tempfile.new("noctty_run")
t2.close
cmd = [*NOCTTY[1..-1],
+ TestIO_Console::INCLUDE_OPTS,
'-e', 'open(ARGV[0], "w") {|f|',
'-e', 'STDOUT.reopen(f)',
'-e', 'STDERR.reopen(f)',
diff --git a/test/io/nonblock/test_flush.rb b/test/io/nonblock/test_flush.rb
index 08d129de3f..447d761f18 100644
--- a/test/io/nonblock/test_flush.rb
+++ b/test/io/nonblock/test_flush.rb
@@ -15,7 +15,7 @@ class TestIONonblock < Test::Unit::TestCase
Socket.pair(:INET, :STREAM) {|s1, s2|
return if flush_test(s1, s2)
}
- skip "nonblocking IO did not work"
+ omit "nonblocking IO did not work"
end
def flush_test(r, w)
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