| 1 |
#!/usr/bin/perl -w |
| 2 |
use strict; |
| 3 |
use Test::More; |
| 4 |
use autodie; |
| 5 |
|
| 6 |
use constant SYSINIT => 1; |
| 7 |
|
| 8 |
if ($^O eq 'MSWin32') { |
| 9 |
plan skip_all => "Can't send signals to own process on recent versions of Windows."; |
| 10 |
} |
| 11 |
|
| 12 |
if (not CORE::kill(0,$$)) { |
| 13 |
plan skip_all => "Can't send signals to own process on this system."; |
| 14 |
} |
| 15 |
|
| 16 |
if (CORE::kill(0, SYSINIT)) { |
| 17 |
plan skip_all => "Can unexpectedly signal process 1. Won't run as root."; |
| 18 |
} |
| 19 |
|
| 20 |
$SIG{HUP} = sub { }; # Ignore SIGHUP |
| 21 |
|
| 22 |
plan tests => 6; |
| 23 |
|
| 24 |
eval { my $rv = kill(0, $$); }; |
| 25 |
is($@, '', "Signalling self is fine"); |
| 26 |
|
| 27 |
eval { kill('HUP', $$); }; |
| 28 |
is($@, '', "Kill with non-zero signal, in void context is ok"); |
| 29 |
|
| 30 |
eval { kill(0, SYSINIT) }; |
| 31 |
isa_ok($@, 'autodie::exception', "kill 0 should die if called in void context"); |
| 32 |
|
| 33 |
eval { my $rv = kill(0, SYSINIT) }; |
| 34 |
is($@, '', "kill 0 should never die if called in scalar context"); |
| 35 |
|
| 36 |
eval { my $rv = kill('HUP', $$, SYSINIT) }; |
| 37 |
isa_ok($@, 'autodie::exception', 'kill exception on single failure.'); |
| 38 |
is($@->return, 1, "kill fails correctly on a 'true' failure."); |