aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-12-13 12:14:10 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-12-17 13:55:04 +0900
commitec89a0f8033215817d9c6f9300d9513178e785b7 (patch)
tree5b3ceedc19f229e5d29f3acea30733aacf67ec44
parenta9d17af242748c160cb79909fd881e06141fe428 (diff)
downloadruby-ec89a0f8033215817d9c6f9300d9513178e785b7.tar.gz
[ruby/io-console] Added the test for intr option
https://github.com/ruby/io-console/commit/4f01db102d
-rw-r--r--test/io/console/test_io_console.rb36
1 files changed, 36 insertions, 0 deletions
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"))