From ec89a0f8033215817d9c6f9300d9513178e785b7 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 13 Dec 2019 12:14:10 +0900 Subject: [ruby/io-console] Added the test for intr option https://github.com/ruby/io-console/commit/4f01db102d --- test/io/console/test_io_console.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test') diff --git a/test/io/console/test_io_console.rb b/test/io/console/test_io_console.rb index 165012d0d7..eab0fb6c6d 100644 --- a/test/io/console/test_io_console.rb +++ b/test/io/console/test_io_console.rb @@ -319,6 +319,42 @@ defined?(PTY) and defined?(IO.console) and TestIO_Console.class_eval do end end + def assert_ctrl(expect, cc, r, w) + sleep 0.1 + w.print cc + w.flush + result = EnvUtil.timeout(3) {r.gets} + assert_equal(expect, result.chomp) + end + + def test_intr + run_pty("#{<<~"begin;"}\n#{<<~'end;'}") do |r, w, _| + begin; + STDOUT.puts `stty -a`.scan(/\b\w+ *= *\^.;/), "" + STDOUT.flush + while c = STDIN.getch + p c.ord + p STDIN.getch(intr: false).ord + begin + p STDIN.getch(intr: true).ord + rescue Interrupt => e + p e + end + end + end; + ctrl = {} + r.each do |l| + break unless /^(\w+) *= *\^(\\?.)/ =~ l + ctrl[$1] = eval("?\\C-#$2") + end + if cc = ctrl["intr"] + assert_ctrl("#{cc.ord}", cc, r, w) + assert_ctrl("#{cc.ord}", cc, r, w) + assert_ctrl("Interrupt", cc, r, w) + end + end + end + unless IO.console def test_close assert_equal(["true"], run_pty("IO.console.close; p IO.console.fileno >= 0")) -- cgit v1.2.3