7 my $Is_VMS = $^O eq 'VMS';
9 use Carp qw(carp cluck croak confess);
15 { local $SIG{__WARN__} = sub {
16 like $_[0], qr/ok (\d+)\n at.+\b(?i:carp\.t) line \d+$/, 'ok 2\n' };
22 { local $SIG{__WARN__} = sub {
23 like $_[0], qr/(\d+) at.+\b(?i:carp\.t) line \d+$/, 'carp 3' };
31 local $SIG{__WARN__} = sub {
32 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' };
40 { local $SIG{__DIE__} = sub {
41 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' };
47 local $SIG{__DIE__} = sub {
48 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' };
57 # test for caller_info API
58 my $eval = "use Carp::Heavy; return Carp::caller_info(0);";
59 my %info = eval($eval);
60 is($info{sub_name}, "eval '$eval'", 'caller_info API');
62 # test for '...::CARP_NOT used only once' warning from Carp::Heavy
67 local $SIG{__WARN__} =
68 sub { if( defined $^S ){ warn $_[0] } else { $warning = $_[0] } }
71 BEGIN { eval { Carp::croak() } }
73 ok !$warning, q/'...::CARP_NOT used only once' warning from Carp::Heavy/;
76 # tests for global variables
82 qr/t at \S*(?i:carp.t) line \d+/,
83 qr/t at \S*(?i:carp.t) line \d+\n\s*main::x\('t'\) called at \S*(?i:carp.t) line \d+/
88 local $Carp::Verbose = $i++;
89 local $SIG{__WARN__} = sub {
90 like $_[0], $re, 'Verbose';
100 my $txt = "Carp::cluck($test_num)";
101 local $Carp::MaxEvalLen = $_;
102 local $SIG{__WARN__} = sub {
103 "@_"=~/'(.+?)(?:\n|')/s;
104 is length($1), length($_?substr($txt,0,$_):substr($txt,0)), 'MaxEvalLen';
106 eval "$txt"; $test_num++;
113 my $arg = 'testtest';
114 local $Carp::MaxArgLen = $_;
115 local $SIG{__WARN__} = sub {
117 is length($1), length($_?substr($arg,0,$_):substr($arg,0)), 'MaxArgLen';
128 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+/,
129 qr/1234 at \S*(?i:carp.t) line \d+\n\s*main::w\(1, 2, \.\.\.\) called at \S*(?i:carp.t) line \d+/,
133 local $Carp::MaxArgNums = $i++;
134 local $SIG{__WARN__} = sub {
135 like "@_", $_, 'MaxArgNums';
146 qr/1 at \S*(?i:carp.t) line \d+\n\s*main::w\(1\) called at \S*(?i:carp.t) line \d+/,
147 qr/1 at \S*(?i:carp.t) line \d+$/,
151 local $Carp::CarpLevel = $i++;
152 local $SIG{__WARN__} = sub {
153 like "@_", $_, 'CarpLevel';
163 local $TODO = "VMS exit status semantics don't work this way" if $Is_VMS;
165 # Check that croak() and confess() don't clobber $!
166 runperl(prog => 'use Carp; $@=q{Phooey}; $!=42; croak(q{Dead})',
169 is($?>>8, 42, 'croak() doesn\'t clobber $!');
171 runperl(prog => 'use Carp; $@=q{Phooey}; $!=42; confess(q{Dead})',
174 is($?>>8, 42, 'confess() doesn\'t clobber $!');