From eb7b05d914faa8d81a064c54bc910e4ff8616b83 Mon Sep 17 00:00:00 2001 From: jluehrs2 Date: Fri, 17 Aug 2007 00:06:40 -0500 Subject: we have tests --- t/000-load.t | 2 +- t/001-basic.t | 8 -------- t/001-open-close.t | 9 +++++++++ t/002-spawn.t | 22 ++++++++++++++++++++++ t/003-subprocess.t | 14 ++++++++++++++ t/004-undefined-program.t | 13 +++++++++++++ t/010-read-write.t | 15 +++++++++++++++ 7 files changed, 74 insertions(+), 9 deletions(-) delete mode 100644 t/001-basic.t create mode 100644 t/001-open-close.t create mode 100644 t/002-spawn.t create mode 100644 t/003-subprocess.t create mode 100644 t/004-undefined-program.t create mode 100644 t/010-read-write.t 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; -- cgit v1.2.3-54-g00ecf