mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
6779f24eb5
* test/test_curses.rb (TestCurses#run_curses): add sentinel to get rid of read pty output after the child process terminated, which causes EIO on Linux. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
62 lines
1.3 KiB
Ruby
62 lines
1.3 KiB
Ruby
require 'test/unit'
|
|
require_relative 'ruby/envutil'
|
|
|
|
begin
|
|
require 'curses'
|
|
require 'pty'
|
|
rescue LoadError
|
|
end
|
|
|
|
class TestCurses < Test::Unit::TestCase
|
|
def test_version
|
|
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")
|
|
print "\\0"
|
|
end
|
|
src
|
|
if input
|
|
w.print(input)
|
|
w.flush
|
|
end
|
|
res = r.gets("\0")
|
|
return unless res
|
|
res.chomp!("\0")
|
|
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
|
|
def test_getch_crmode
|
|
assert_equal("a", run_curses("crmode; getch", "a"))
|
|
end
|
|
def test_getch_nocrmode
|
|
assert_raise(Timeout::Error) {run_curses("nocrmode; getch", "a")}
|
|
end
|
|
end if defined? TestCurses and defined? PTY
|