1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
use strict;
use warnings;
BEGIN {
$ENV{DEVEL_CONFESS_OPTIONS} = '';
}
use Test::More tests => 14;
use lib 't/lib';
use Capture;
# preload to make sure we only test the effect of our own import
use base ();
use Exporter ();
use Exporter::Heavy ();
use Carp ();
use Carp::Heavy ();
use Symbol ();
my $pre_die;
BEGIN { $pre_die = $SIG{__DIE__} }
use Devel::Confess ();
is $SIG{__DIE__}, $pre_die, 'not activated without import';
my $called;
sub CALLED { $called++ };
$SIG{__DIE__} = \&CALLED;
Devel::Confess->import;
isnt $SIG{__DIE__}, \&CALLED, 'import overwrites existing __DIE__ handler';
$called = 0;
eval { die };
is 0+$called, 1, 'calls outer __DIE__ handler';
Devel::Confess->unimport;
is $SIG{__DIE__}, \&CALLED, 'unimport restores __DIE__ handler';
$SIG{__DIE__} = '';
Devel::Confess->import;
Devel::Confess->unimport;
ok !$SIG{__DIE__}, 'unimport restores nonexistent __DIE__ handler';
sub IGNORE { $called++ }
sub DEFAULT { $called++ }
sub other::sub { $called++ }
$SIG{__DIE__} = 'IGNORE';
Devel::Confess->import;
$called = 0;
eval { die };
is 0+$called, 0, 'no dispatching to IGNORE';
Devel::Confess->unimport;
$SIG{__DIE__} = 'DEFAULT';
Devel::Confess->import;
$called = 0;
eval { die };
is 0+$called, 0, 'no dispatching to DEFAULT';
Devel::Confess->unimport;
$SIG{__DIE__} = 'CALLED';
Devel::Confess->import;
$called = 0;
eval { die };
is 0+$called, 1, 'dispatches by name';
Devel::Confess->unimport;
$SIG{__DIE__} = 'other::sub';
Devel::Confess->import;
$called = 0;
eval { die };
is 0+$called, 1, 'dispatches by name to package sub';
Devel::Confess->unimport;
is capture <<'END_CODE',
BEGIN { $SIG{__DIE__} = sub { 1 } }
use Devel::Confess;
package A;
sub f {
#line 1 test-block.pl
die "Beware!";
}
sub g {
#line 2 test-block.pl
f();
}
package main;
#line 3 test-block.pl
A::g();
END_CODE
<<"END_OUTPUT",
Beware! at test-block.pl line 1.
\tA::f() called at test-block.pl line 2
\tA::g() called at test-block.pl line 3
END_OUTPUT
'trace still added when outer __DIE__ exists';
is capture <<'END_CODE', '',
BEGIN { $SIG{__WARN__} = sub { } }
use Devel::Confess;
package A;
sub f {
#line 1 test-block.pl
warn "Beware!";
}
sub g {
#line 2 test-block.pl
f();
}
package main;
#line 3 test-block.pl
A::g();
END_CODE
'outer __WARN__ can silence warnings';
is capture <<'END_CODE',
BEGIN { $SIG{__WARN__} = sub { warn $_[0] } }
use Devel::Confess;
package A;
sub f {
#line 1 test-block.pl
warn "Beware!";
}
sub g {
#line 2 test-block.pl
f();
}
package main;
#line 3 test-block.pl
A::g();
END_CODE
<<"END_OUTPUT",
Beware! at test-block.pl line 1.
\tA::f() called at test-block.pl line 2
\tA::g() called at test-block.pl line 3
END_OUTPUT
'outer __WARN__ gets full location';
is capture <<'END_CODE',
use strict;
use warnings 'FATAL' => 'all';
use Devel::Confess;
BEGIN {
my $warn = $SIG{__WARN__} || die;
$SIG{__WARN__} = sub { $warn->(@_) };
}
use Devel::Confess;
package A;
sub f {
#line 1 test-block.pl
warn "Beware!";
}
sub g {
#line 2 test-block.pl
f();
}
package main;
#line 3 test-block.pl
A::g();
END_CODE
<<"END_OUTPUT",
Beware! at test-block.pl line 1.
\tA::f() called at test-block.pl line 2
\tA::g() called at test-block.pl line 3
END_OUTPUT
'no infinite loop with mutually recursing __WARN__';
is capture <<'END_CODE',
use strict;
use warnings 'FATAL' => 'all';
use Devel::Confess;
BEGIN {
my $die = $SIG{__DIE__} or die;
$SIG{__DIE__} = sub { $die->(\@_) };
}
use Devel::Confess;
package A;
sub f {
#line 1 test-block.pl
die "Beware!";
}
sub g {
#line 2 test-block.pl
f();
}
package main;
#line 3 test-block.pl
A::g();
END_CODE
<<"END_OUTPUT",
Beware! at test-block.pl line 1.
\tA::f() called at test-block.pl line 2
\tA::g() called at test-block.pl line 3
END_OUTPUT
'no infinite loop with mutually recursing __DIE__';
|