diff options
author | Nicholas Clark <nick@ccl4.org> | 2011-08-31 18:19:34 +0200 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2011-09-01 21:54:10 +0200 |
commit | 3fde54759f5a556ef1c7003832d36a1d8393eacb (patch) | |
tree | 39cb21600df3738cd27c9e51d4f98d6f90b5df59 | |
parent | b7fda7aac48a2f42869996b3969262c36a0bb96f (diff) | |
download | perl-3fde54759f5a556ef1c7003832d36a1d8393eacb.tar.gz |
Convert the POSIX waitpid tests to Test::More.
Explicitly test POSIX::exit(), POSIX::fork(), POSIX::sleep() and
POSIX::waitpid(). Use POSIX::_exit() in the child process.
-rw-r--r-- | ext/POSIX/t/waitpid.t | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/ext/POSIX/t/waitpid.t b/ext/POSIX/t/waitpid.t index 105b1be1b2..7e821fd825 100644 --- a/ext/POSIX/t/waitpid.t +++ b/ext/POSIX/t/waitpid.t @@ -21,7 +21,7 @@ use strict; $| = 1; -print "1..1\n"; +use Test::More tests => 3; sub NEG1_PROHIBITED () { 0x01 } sub NEG1_REQUIRED () { 0x02 } @@ -31,11 +31,12 @@ my $max_count = 9; my $state = NEG1_PROHIBITED; my $child_pid = fork(); +fail("fork failed") unless defined $child_pid; # Parent receives a nonzero child PID. if ($child_pid) { - my $ok = 1; + my @problems; while ($count++ < $max_count) { my $begin_time = time(); @@ -45,39 +46,39 @@ if ($child_pid) { printf( "# waitpid(-1,WNOHANG) returned %d after %.2f seconds\n", $ret, $elapsed_time ); if ($elapsed_time > 0.5) { - printf( "# %.2f seconds in non-blocking waitpid is too long!\n", - $elapsed_time ); - $ok = 0; + push @problems, + sprintf "%.2f seconds in non-blocking waitpid is too long!\n", + $elapsed_time; last; } if ($state & NEG1_PROHIBITED) { if ($ret == -1) { - print "# waitpid should not have returned -1 here!\n"; - $ok = 0; + push @problems, "waitpid should not have returned -1 here!\n"; last; } elsif ($ret == $child_pid) { $state = NEG1_REQUIRED; + is(WIFEXITED(${^CHILD_ERROR_NATIVE}), 1, 'child exited cleanly'); + is(WEXITSTATUS(${^CHILD_ERROR_NATIVE}), 0, + 'child exited with 0 (the retun value of its sleep(3) call)'); + } } elsif ($state & NEG1_REQUIRED) { unless ($ret == -1) { - print "# waitpid should have returned -1 here\n"; - $ok = 0; + push @problems, "waitpid should have returned -1 here!\n"; } last; } sleep(1); } - print $ok ? "ok 1\n" : "not ok 1\n"; - exit(0); # parent + is("@problems", "", 'no problems'); + POSIX::exit(0); # parent + fail("Should have exited"); } else { # Child receives a zero PID and can request parent's PID with # getppid(). - sleep(3); - exit(0); + POSIX::_exit(POSIX::sleep(3)); } - - |