From 529ad093d42bd6ab802449747bf08a400563e12d Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 14 Dec 2008 03:52:13 +0000 Subject: new file. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/test_pty.rb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/test_pty.rb diff --git a/test/test_pty.rb b/test/test_pty.rb new file mode 100644 index 0000000000..6787da4d21 --- /dev/null +++ b/test/test_pty.rb @@ -0,0 +1,46 @@ +require 'test/unit' +require_relative 'ruby/envutil' +require 'shellwords' + +begin + require 'pty' +rescue LoadError +end + +class TestPTY < Test::Unit::TestCase + RUBY = EnvUtil.rubybin + + def test_spawn_without_block + r, w, pid = PTY.spawn(RUBY, '-e', 'puts "a"') + assert_equal("a\r\n", r.gets) + assert_raise(Errno::EIO) { r.gets } + ensure + Process.wait pid if pid + end + + def test_spawn_with_block + PTY.spawn(RUBY, '-e', 'puts "b"') {|r,w,pid| + assert_equal("b\r\n", r.gets) + Process.wait(pid) + assert_raise(Errno::EIO) { r.gets } + } + end + + def test_commandline + commandline = Shellwords.join([RUBY, '-e', 'puts "foo"']) + PTY.spawn(commandline) {|r,w,pid| + assert_equal("foo\r\n", r.gets) + Process.wait(pid) + assert_raise(Errno::EIO) { r.gets } + } + end + + def test_argv0 + PTY.spawn([RUBY, "argv0"], '-e', 'puts "bar"') {|r,w,pid| + assert_equal("bar\r\n", r.gets) + Process.wait(pid) + assert_raise(Errno::EIO) { r.gets } + } + end +end if defined? PTY + -- cgit v1.2.3