11 use Test::More tests => 15;
18 # use a version of sigtrap.pm somewhat too high
19 eval{ sigtrap->import(99999) };
20 like( $@, qr/version 99999 required,/, 'import excessive version number' );
22 # use an invalid signal name
23 eval{ sigtrap->import('abadsignal') };
24 like( $@, qr/^Unrecognized argument abadsignal/, 'send bad signame to import' );
26 eval{ sigtrap->import('handler') };
27 like( $@, qr/^No argument specified/, 'send handler without subref' );
29 sigtrap->import('AFAKE');
30 is( $SIG{AFAKE}, \&sigtrap::handler_traceback, 'install normal handler' );
32 sigtrap->import('die', 'AFAKE', 'stack-trace', 'FAKE2');
33 is( $SIG{AFAKE}, \&sigtrap::handler_die, 'install the die handler' );
34 is( $SIG{FAKE2}, \&sigtrap::handler_traceback, 'install traceback handler' );
36 my @normal = qw( HUP INT PIPE TERM );
37 @SIG{@normal} = 1 x @normal;
38 sigtrap->import('normal-signals');
39 is( (grep { ref $_ } @SIG{@normal}), @normal, 'check normal-signals set' );
41 my @error = qw( ABRT BUS EMT FPE ILL QUIT SEGV SYS TRAP );
42 @SIG{@error} = 1 x @error;
43 sigtrap->import('error-signals');
44 is( (grep { ref $_ } @SIG{@error}), @error, 'check error-signals set' );
46 my @old = qw( ABRT BUS EMT FPE ILL PIPE QUIT SEGV SYS TERM TRAP );
47 @SIG{@old} = 1 x @old;
48 sigtrap->import('old-interface-signals');
49 is( (grep { ref $_ } @SIG{@old}), @old, 'check old-interface-signals set' );
52 sigtrap->import(handler => $handler, 'FAKE3');
53 is( $SIG{FAKE3}, $handler, 'install custom handler' );
55 $SIG{FAKE} = 'IGNORE';
56 sigtrap->import('untrapped', 'FAKE');
57 is( $SIG{FAKE}, 'IGNORE', 'respect existing handler set to IGNORE' );
59 my $out = tie *STDOUT, 'TieOut';
60 $SIG{FAKE} = 'DEFAULT';
61 $sigtrap::Verbose = 1;
62 sigtrap->import('any', 'FAKE');
63 is( $SIG{FAKE}, \&sigtrap::handler_traceback, 'should set default handler' );
64 like( $out->read, qr/^Installing handler/, 'does it talk with $Verbose set?' );
66 # handler_die croaks with first argument
67 eval { sigtrap::handler_die('FAKE') };
68 like( $@, qr/^Caught a SIGFAKE/, 'does handler_die() croak?' );
73 bless(\(my $scalar), $_[0]);
78 $$self .= join '', @_;
82 my ($self, $msg, $length) = @_;
88 substr($$self, 0, length($$self), '');