ruby-changes:28065
From: nobu <ko1@a...>
Date: Fri, 5 Apr 2013 13:23:12 +0900 (JST)
Subject: [ruby-changes:28065] nobu:r40117 (trunk): * test/test_curses.rb: tests for getch.
nobu 2013-04-05 13:23:02 +0900 (Fri, 05 Apr 2013) New Revision: 40117 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40117 Log: * test/test_curses.rb: tests for getch. Modified files: trunk/test/test_curses.rb Index: test/test_curses.rb =================================================================== --- test/test_curses.rb (revision 40116) +++ test/test_curses.rb (revision 40117) @@ -1,7 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/test/test_curses.rb#L1 require 'test/unit' +require_relative 'ruby/envutil' begin require 'curses' + require 'pty' rescue LoadError end @@ -10,3 +12,43 @@ class TestCurses < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_curses.rb#L12 assert_instance_of(String, Curses::VERSION) end end if defined? Curses + +class TestCurses + def run_curses(src, input = nil, timeout: 1) + PTY.spawn(EnvUtil.rubybin, "-e", <<-"src") {|r, w, pid| +require 'timeout' +require 'curses' +include Curses +init_screen +begin + result = Timeout.timeout(#{timeout}) do + #{src} + end +rescue Exception => e +ensure + close_screen + puts "", [Marshal.dump([result, e])].pack('m').delete("\n") +end +src + if input + w.print(input) + w.flush + end + res = r.read + return unless res + res, error = Marshal.load(res[/(.*)\Z/, 1].unpack('m')[0]) + raise error if error + return res + } + end + + def test_getch + assert_equal("a", run_curses("getch", "a")) + end + def test_getch_cbreak + assert_equal("a", run_curses("cbreak; getch", "a")) + end + def test_getch_nocbreak + assert_raise(Timeout::Error) {run_curses("nocbreak; getch", "a")} + end +end if defined? TestCurses and defined? PTY -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/