From 282cbf68f0d4dcb75aeeefea1fac4ffd9e7a319b Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 15 Jul 2025 17:33:40 +0900 Subject: Merge io-console 0.8.1 --- ext/io/console/console.c | 2 +- ext/io/console/extconf.rb | 10 +++++----- test/io/console/test_io_console.rb | 30 ++++++++++++++++++++---------- test/io/console/test_ractor.rb | 12 ++++++++++-- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/ext/io/console/console.c b/ext/io/console/console.c index 80c1cddd5a..3c8bb82083 100644 --- a/ext/io/console/console.c +++ b/ext/io/console/console.c @@ -4,7 +4,7 @@ */ static const char *const -IO_CONSOLE_VERSION = "0.8.0"; +IO_CONSOLE_VERSION = "0.8.1"; #include "ruby.h" #include "ruby/io.h" diff --git a/ext/io/console/extconf.rb b/ext/io/console/extconf.rb index 4ad7ed6996..dd3d221ae5 100644 --- a/ext/io/console/extconf.rb +++ b/ext/io/console/extconf.rb @@ -10,11 +10,11 @@ have_func("rb_syserr_new_str(0, Qnil)") or abort have_func("rb_interned_str_cstr") -have_func("rb_io_path") -have_func("rb_io_descriptor") -have_func("rb_io_get_write_io") -have_func("rb_io_closed_p") -have_func("rb_io_open_descriptor") +have_func("rb_io_path", "ruby/io.h") +have_func("rb_io_descriptor", "ruby/io.h") +have_func("rb_io_get_write_io", "ruby/io.h") +have_func("rb_io_closed_p", "ruby/io.h") +have_func("rb_io_open_descriptor", "ruby/io.h") have_func("rb_ractor_local_storage_value_newkey") is_wasi = /wasi/ =~ MakeMakefile::RbConfig::CONFIG["platform"] diff --git a/test/io/console/test_io_console.rb b/test/io/console/test_io_console.rb index 2bf3df6439..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) @@ -444,7 +454,9 @@ defined?(PTY) and defined?(IO.console) and TestIO_Console.class_eval do def test_ttyname return unless IO.method_defined?(:ttyname) - assert_equal(["true"], run_pty("p STDIN.ttyname == STDOUT.ttyname")) + # [Bug #20682] + # `sleep 0.1` is added to stabilize flaky failures on macOS. + assert_equal(["true"], run_pty("p STDIN.ttyname == STDOUT.ttyname; sleep 0.1")) end end @@ -544,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 -- cgit v1.2.3