summaryrefslogtreecommitdiff
path: root/test/io/console
diff options
context:
space:
mode:
Diffstat (limited to 'test/io/console')
-rw-r--r--test/io/console/test_io_console.rb26
-rw-r--r--test/io/console/test_ractor.rb12
2 files changed, 27 insertions, 11 deletions
diff --git a/test/io/console/test_io_console.rb b/test/io/console/test_io_console.rb
index 709ea53a88..c3f9c91c7d 100644
--- a/test/io/console/test_io_console.rb
+++ b/test/io/console/test_io_console.rb
@@ -7,6 +7,11 @@ rescue LoadError
end
class TestIO_Console < Test::Unit::TestCase
+ HOST_OS = RbConfig::CONFIG['host_os']
+ private def host_os?(os)
+ HOST_OS =~ os
+ end
+
begin
PATHS = $LOADED_FEATURES.grep(%r"/io/console(?:\.#{RbConfig::CONFIG['DLEXT']}|\.rb|/\w+\.rb)\z") {$`}
rescue Encoding::CompatibilityError
@@ -20,17 +25,13 @@ class TestIO_Console < Test::Unit::TestCase
# FreeBSD seems to hang on TTOU when running parallel tests
# tested on FreeBSD 11.x.
#
- # Solaris gets stuck too, even in non-parallel mode.
- # It occurs only in chkbuild. It does not occur when running
- # `make test-all` in SSH terminal.
- #
# I suspect that it occurs only when having no TTY.
# (Parallel mode runs tests in child processes, so I guess
# they has no TTY.)
# But it does not occur in `make test-all > /dev/null`, so
# there should be an additional factor, I guess.
def set_winsize_setup
- @old_ttou = trap(:TTOU, 'IGNORE') if RUBY_PLATFORM =~ /freebsd|solaris/i
+ @old_ttou = trap(:TTOU, 'IGNORE') if host_os?(/freebsd/)
end
def set_winsize_teardown
@@ -371,6 +372,15 @@ defined?(PTY) and defined?(IO.console) and TestIO_Console.class_eval do
w.print cc
w.flush
result = EnvUtil.timeout(3) {r.gets}
+ if result
+ case cc.chr
+ when "\C-A".."\C-_"
+ cc = "^" + (cc.ord | 0x40).chr
+ when "\C-?"
+ cc = "^?"
+ end
+ result.sub!(cc, "")
+ end
assert_equal(expect, result.chomp)
end
@@ -382,7 +392,7 @@ defined?(PTY) and defined?(IO.console) and TestIO_Console.class_eval do
# 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
+ omit if host_os?(/freebsd/)
run_pty("#{<<~"begin;"}\n#{<<~'end;'}") do |r, w, _|
begin;
@@ -408,7 +418,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|solaris/ =~ RUBY_PLATFORM
+ assert_ctrl("Interrupt", cc, r, w) unless host_os?(/linux/)
end
if cc = ctrl["dsusp"]
assert_ctrl("#{cc.ord}", cc, r, w)
@@ -546,9 +556,7 @@ defined?(IO.console) and TestIO_Console.class_eval do
File.open(ttyname) {|f| assert_predicate(f, :tty?)}
end
end
-end
-defined?(IO.console) and TestIO_Console.class_eval do
case
when Process.respond_to?(:daemon)
noctty = [EnvUtil.rubybin, "-e", "Process.daemon(true)"]
diff --git a/test/io/console/test_ractor.rb b/test/io/console/test_ractor.rb
index b30988f47e..dff0c67eab 100644
--- a/test/io/console/test_ractor.rb
+++ b/test/io/console/test_ractor.rb
@@ -8,6 +8,10 @@ class TestIOConsoleInRactor < Test::Unit::TestCase
path = $".find {|path| path.end_with?(ext)}
assert_in_out_err(%W[-r#{path}], "#{<<~"begin;"}\n#{<<~'end;'}", ["true"], [])
begin;
+ class Ractor
+ alias value take
+ end unless Ractor.method_defined? :value # compat with Ruby 3.4 and olders
+
$VERBOSE = nil
r = Ractor.new do
$stdout.console_mode
@@ -18,17 +22,21 @@ class TestIOConsoleInRactor < Test::Unit::TestCase
else
true # should not success
end
- puts r.take
+ puts r.value
end;
assert_in_out_err(%W[-r#{path}], "#{<<~"begin;"}\n#{<<~'end;'}", ["true"], [])
begin;
+ class Ractor
+ alias value take
+ end unless Ractor.method_defined? :value # compat with Ruby 3.4 and olders
+
console = IO.console
$VERBOSE = nil
r = Ractor.new do
IO.console
end
- puts console.class == r.take.class
+ puts console.class == r.value.class
end;
end
end if defined? Ractor