summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-14 03:52:13 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-14 03:52:13 +0000
commitc1f15cf03ff76949bc199a9e0b8cac9115551a72 (patch)
treeffc3614f8cb6665342c2dd8a08f8abf78ce0d0d6 /test
parent528a7044b9e3b6a99d68fe92a1b383a60cdabb7e (diff)
downloadruby-c1f15cf03ff76949bc199a9e0b8cac9115551a72.tar.gz
ruby-c1f15cf03ff76949bc199a9e0b8cac9115551a72.tar.xz
ruby-c1f15cf03ff76949bc199a9e0b8cac9115551a72.zip
new file.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@20732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/test_pty.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/test_pty.rb b/test/test_pty.rb
new file mode 100644
index 000000000..6787da4d2
--- /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
+