7 use Carp qw(carp cluck croak confess);
13 { local $SIG{__WARN__} = sub {
14 like $_[0], qr/ok (\d+)\n at.+\b(?i:carp\.t) line \d+$/, 'ok 2\n' };
20 { local $SIG{__WARN__} = sub {
21 like $_[0], qr/(\d+) at.+\b(?i:carp\.t) line \d+$/, 'carp 3' };
29 local $SIG{__WARN__} = sub {
30 like $_[0], qr/^(\d+) at.+\b(?i:carp\.t) line \d+\n\tmain::sub_4\(\) called at.+\b(?i:carp\.t) line \d+$/, 'cluck 4' };
38 { local $SIG{__DIE__} = sub {
39 like $_[0], qr/^(\d+) at.+\b(?i:carp\.t) line \d+\n\teval \Q{...}\E called at.+\b(?i:carp\.t) line \d+$/, 'croak 5' };
45 local $SIG{__DIE__} = sub {
46 like $_[0], qr/^(\d+) at.+\b(?i:carp\.t) line \d+\n\teval \Q{...}\E called at.+\b(?i:carp\.t) line \d+\n\tmain::sub_6\(\) called at.+\b(?i:carp\.t) line \d+$/, 'confess 6' };
55 # test for caller_info API
56 my $eval = "use Carp::Heavy; return Carp::caller_info(0);";
57 my %info = eval($eval);
58 is($info{sub_name}, "eval '$eval'", 'caller_info API');
60 # test for '...::CARP_NOT used only once' warning from Carp::Heavy
65 local $SIG{__WARN__} =
66 sub { if( defined $^S ){ warn $_[0] } else { $warning = $_[0] } }
69 BEGIN { eval { Carp::croak() } }
71 ok !$warning, q/'...::CARP_NOT used only once' warning from Carp::Heavy/;
74 # tests for global variables
80 qr/t at \S*(?i:carp.t) line \d+/,
81 qr/t at \S*(?i:carp.t) line \d+\n\s*main::x\('t'\) called at \S*(?i:carp.t) line \d+/
86 local $Carp::Verbose = $i++;
87 local $SIG{__WARN__} = sub {
88 like $_[0], $re, 'Verbose';
98 my $txt = "Carp::cluck($test_num)";
99 local $Carp::MaxEvalLen = $_;
100 local $SIG{__WARN__} = sub {
101 "@_"=~/'(.+?)(?:\n|')/s;
102 is length($1), length($_?substr($txt,0,$_):substr($txt,0)), 'MaxEvalLen';
104 eval "$txt"; $test_num++;
111 my $arg = 'testtest';
112 local $Carp::MaxArgLen = $_;
113 local $SIG{__WARN__} = sub {
115 is length($1), length($_?substr($arg,0,$_):substr($arg,0)), 'MaxArgLen';
126 qr/1234 at \S*(?i:carp.t) line \d+\n\s*main::w\(1, 2, 3, 4\) called at \S*(?i:carp.t) line \d+/,
127 qr/1234 at \S*(?i:carp.t) line \d+\n\s*main::w\(1, 2, \.\.\.\) called at \S*(?i:carp.t) line \d+/,
131 local $Carp::MaxArgNums = $i++;
132 local $SIG{__WARN__} = sub {
133 like "@_", $_, 'MaxArgNums';
144 qr/1 at \S*(?i:carp.t) line \d+\n\s*main::w\(1\) called at \S*(?i:carp.t) line \d+/,
145 qr/1 at \S*(?i:carp.t) line \d+$/,
149 local $Carp::CarpLevel = $i++;
150 local $SIG{__WARN__} = sub {
151 like "@_", $_, 'CarpLevel';