summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2007-08-17 00:06:40 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2007-08-17 00:06:40 -0500
commiteb7b05d914faa8d81a064c54bc910e4ff8616b83 (patch)
tree1721b846b539fad51890665d3e614547dcd094a5
parentffef15f0c4c80de0101c1d05b921011a37a080b8 (diff)
downloadio-pty-easy-eb7b05d914faa8d81a064c54bc910e4ff8616b83.tar.gz
io-pty-easy-eb7b05d914faa8d81a064c54bc910e4ff8616b83.zip
we have tests
-rw-r--r--t/000-load.t2
-rw-r--r--t/001-basic.t8
-rw-r--r--t/001-open-close.t9
-rw-r--r--t/002-spawn.t22
-rw-r--r--t/003-subprocess.t14
-rw-r--r--t/004-undefined-program.t13
-rw-r--r--t/010-read-write.t15
7 files changed, 74 insertions, 9 deletions
diff --git a/t/000-load.t b/t/000-load.t
index e7e67ca..982a1ef 100644
--- a/t/000-load.t
+++ b/t/000-load.t
@@ -1,4 +1,4 @@
-#!perl -T
+#!perl
use strict;
use warnings;
use Test::More tests => 1;
diff --git a/t/001-basic.t b/t/001-basic.t
deleted file mode 100644
index 2ac09a9..0000000
--- a/t/001-basic.t
+++ /dev/null
@@ -1,8 +0,0 @@
-#!perl -T
-use strict;
-use warnings;
-use Test::More tests => 1;
-use IO::Pty::Easy;
-
-ok(1);
-
diff --git a/t/001-open-close.t b/t/001-open-close.t
new file mode 100644
index 0000000..46ad7fc
--- /dev/null
+++ b/t/001-open-close.t
@@ -0,0 +1,9 @@
+#!perl
+use strict;
+use warnings;
+use Test::More tests => 1;
+use IO::Pty::Easy;
+
+my $pty = new IO::Pty::Easy;
+$pty->close;
+ok(!defined($pty->{pty}), "closing a pty before a spawn");
diff --git a/t/002-spawn.t b/t/002-spawn.t
new file mode 100644
index 0000000..9b61437
--- /dev/null
+++ b/t/002-spawn.t
@@ -0,0 +1,22 @@
+#!perl
+use strict;
+use warnings;
+use Test::More tests => 5;
+use IO::Pty::Easy;
+
+my $pty = new IO::Pty::Easy;
+$pty->spawn("$^X -ple ''");
+ok($pty->is_active, "spawning a subprocess");
+ok(kill(0 => $pty->{pid}), "subprocess actually exists");
+$pty->kill;
+TODO: {
+local $TODO = "kill() needs to block";
+ok(!$pty->is_active, "killing a subprocess");
+}
+$pty->spawn("$^X -ple ''");
+$pty->close;
+TODO: {
+local $TODO = "kill() needs to block";
+ok(!$pty->is_active, "auto-killing a pty with close()");
+}
+ok(!defined($pty->{pty}), "closing a pty after a spawn");
diff --git a/t/003-subprocess.t b/t/003-subprocess.t
new file mode 100644
index 0000000..edc9b09
--- /dev/null
+++ b/t/003-subprocess.t
@@ -0,0 +1,14 @@
+#!perl
+use strict;
+use warnings;
+use Test::More tests => 2;
+use IO::Pty::Easy;
+
+my $pty = new IO::Pty::Easy;
+my $script = "$^X -e '-t *STDIN && -t *STDOUT && print \"ok\";'";
+
+my $outside_of_pty = `$script`;
+unlike($outside_of_pty, qr/ok/, "running outside of PTY fails -t checks");
+
+$pty->spawn("$script");
+like($pty->read, qr/ok/, "runs subprocess in a PTY");
diff --git a/t/004-undefined-program.t b/t/004-undefined-program.t
new file mode 100644
index 0000000..6a50f3b
--- /dev/null
+++ b/t/004-undefined-program.t
@@ -0,0 +1,13 @@
+#!perl
+use strict;
+use warnings;
+use Test::More tests => 2;
+use IO::Pty::Easy;
+
+my $pty = new IO::Pty::Easy;
+eval { $pty->spawn("missing_program_io_pty_easy") };
+like($@, qr/Cannot exec\(missing_program_io_pty_easy\)/);
+TODO: {
+local $TODO = "spawn() needs to block on is_active until SIGCHLD is received if it fails";
+ok(!$pty->is_active, "pty isn't active if program doesn't exist");
+}
diff --git a/t/010-read-write.t b/t/010-read-write.t
new file mode 100644
index 0000000..d538fe8
--- /dev/null
+++ b/t/010-read-write.t
@@ -0,0 +1,15 @@
+#!perl
+use strict;
+use warnings;
+use Test::More tests => 1;
+use IO::Pty::Easy;
+
+my $pty = new IO::Pty::Easy;
+
+$pty->spawn("$^X -ple ''");
+$pty->write("testing\n");
+like($pty->read, qr/testing/, "basic read/write testing");
+# if the perl script ends with a subprocess still running, the test will exit
+# with the exit status of the signal that the subprocess dies with, so we have to wait for the subprocess to finish before exiting.
+$pty->kill;
+1 while $pty->is_active;