Skip to content

Commit 282cbf6

Browse files
hsbtk0kubun
authored andcommitted
Merge io-console 0.8.1
1 parent cfdc246 commit 282cbf6

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

ext/io/console/console.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
static const char *const
7-
IO_CONSOLE_VERSION = "0.8.0";
7+
IO_CONSOLE_VERSION = "0.8.1";
88

99
#include "ruby.h"
1010
#include "ruby/io.h"

ext/io/console/extconf.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
abort
1111

1212
have_func("rb_interned_str_cstr")
13-
have_func("rb_io_path")
14-
have_func("rb_io_descriptor")
15-
have_func("rb_io_get_write_io")
16-
have_func("rb_io_closed_p")
17-
have_func("rb_io_open_descriptor")
13+
have_func("rb_io_path", "ruby/io.h")
14+
have_func("rb_io_descriptor", "ruby/io.h")
15+
have_func("rb_io_get_write_io", "ruby/io.h")
16+
have_func("rb_io_closed_p", "ruby/io.h")
17+
have_func("rb_io_open_descriptor", "ruby/io.h")
1818
have_func("rb_ractor_local_storage_value_newkey")
1919

2020
is_wasi = /wasi/ =~ MakeMakefile::RbConfig::CONFIG["platform"]

test/io/console/test_io_console.rb

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
end
88

99
class TestIO_Console < Test::Unit::TestCase
10+
HOST_OS = RbConfig::CONFIG['host_os']
11+
private def host_os?(os)
12+
HOST_OS =~ os
13+
end
14+
1015
begin
1116
PATHS = $LOADED_FEATURES.grep(%r"/io/console(?:\.#{RbConfig::CONFIG['DLEXT']}|\.rb|/\w+\.rb)\z") {$`}
1217
rescue Encoding::CompatibilityError
@@ -20,17 +25,13 @@ class TestIO_Console < Test::Unit::TestCase
2025
# FreeBSD seems to hang on TTOU when running parallel tests
2126
# tested on FreeBSD 11.x.
2227
#
23-
# Solaris gets stuck too, even in non-parallel mode.
24-
# It occurs only in chkbuild. It does not occur when running
25-
# `make test-all` in SSH terminal.
26-
#
2728
# I suspect that it occurs only when having no TTY.
2829
# (Parallel mode runs tests in child processes, so I guess
2930
# they has no TTY.)
3031
# But it does not occur in `make test-all > /dev/null`, so
3132
# there should be an additional factor, I guess.
3233
def set_winsize_setup
33-
@old_ttou = trap(:TTOU, 'IGNORE') if RUBY_PLATFORM =~ /freebsd|solaris/i
34+
@old_ttou = trap(:TTOU, 'IGNORE') if host_os?(/freebsd/)
3435
end
3536

3637
def set_winsize_teardown
@@ -371,6 +372,15 @@ def assert_ctrl(expect, cc, r, w)
371372
w.print cc
372373
w.flush
373374
result = EnvUtil.timeout(3) {r.gets}
375+
if result
376+
case cc.chr
377+
when "\C-A".."\C-_"
378+
cc = "^" + (cc.ord | 0x40).chr
379+
when "\C-?"
380+
cc = "^?"
381+
end
382+
result.sub!(cc, "")
383+
end
374384
assert_equal(expect, result.chomp)
375385
end
376386

@@ -382,7 +392,7 @@ def test_intr
382392
# TestIO_Console#test_intr [/usr/home/chkbuild/chkbuild/tmp/build/20220304T163001Z/ruby/test/io/console/test_io_console.rb:387]:
383393
# <"25"> expected but was
384394
# <"-e:12:in `p': \e[1mexecution expired (\e[1;4mTimeout::Error\e[m\e[1m)\e[m">.
385-
omit if /freebsd/ =~ RUBY_PLATFORM
395+
omit if host_os?(/freebsd/)
386396

387397
run_pty("#{<<~"begin;"}\n#{<<~'end;'}") do |r, w, _|
388398
begin;
@@ -408,7 +418,7 @@ def test_intr
408418
if cc = ctrl["intr"]
409419
assert_ctrl("#{cc.ord}", cc, r, w)
410420
assert_ctrl("#{cc.ord}", cc, r, w)
411-
assert_ctrl("Interrupt", cc, r, w) unless /linux|solaris/ =~ RUBY_PLATFORM
421+
assert_ctrl("Interrupt", cc, r, w) unless host_os?(/linux/)
412422
end
413423
if cc = ctrl["dsusp"]
414424
assert_ctrl("#{cc.ord}", cc, r, w)
@@ -444,7 +454,9 @@ def test_sync
444454

445455
def test_ttyname
446456
return unless IO.method_defined?(:ttyname)
447-
assert_equal(["true"], run_pty("p STDIN.ttyname == STDOUT.ttyname"))
457+
# [Bug #20682]
458+
# `sleep 0.1` is added to stabilize flaky failures on macOS.
459+
assert_equal(["true"], run_pty("p STDIN.ttyname == STDOUT.ttyname; sleep 0.1"))
448460
end
449461
end
450462

@@ -544,9 +556,7 @@ def test_ttyname
544556
File.open(ttyname) {|f| assert_predicate(f, :tty?)}
545557
end
546558
end
547-
end
548559

549-
defined?(IO.console) and TestIO_Console.class_eval do
550560
case
551561
when Process.respond_to?(:daemon)
552562
noctty = [EnvUtil.rubybin, "-e", "Process.daemon(true)"]

test/io/console/test_ractor.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ def test_ractor
88
path = $".find {|path| path.end_with?(ext)}
99
assert_in_out_err(%W[-r#{path}], "#{<<~"begin;"}\n#{<<~'end;'}", ["true"], [])
1010
begin;
11+
class Ractor
12+
alias value take
13+
end unless Ractor.method_defined? :value # compat with Ruby 3.4 and olders
14+
1115
$VERBOSE = nil
1216
r = Ractor.new do
1317
$stdout.console_mode
@@ -18,17 +22,21 @@ def test_ractor
1822
else
1923
true # should not success
2024
end
21-
puts r.take
25+
puts r.value
2226
end;
2327

2428
assert_in_out_err(%W[-r#{path}], "#{<<~"begin;"}\n#{<<~'end;'}", ["true"], [])
2529
begin;
30+
class Ractor
31+
alias value take
32+
end unless Ractor.method_defined? :value # compat with Ruby 3.4 and olders
33+
2634
console = IO.console
2735
$VERBOSE = nil
2836
r = Ractor.new do
2937
IO.console
3038
end
31-
puts console.class == r.take.class
39+
puts console.class == r.value.class
3240
end;
3341
end
3442
end if defined? Ractor

0 commit comments

Comments
 (0)