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/;
75 # Test the location of error messages.
76 like(A::short(), qr/^Error at C/, "Short messages skip carped package");
80 like(A::short(), qr/^Error at B/, "Short messages skip inheritance");
85 like(A::short(), qr/^Error at B/, "Short messages skip inheritance");
91 like(A::short(), qr/^Error at A/, "Inheritance is transitive");
97 like(A::short(), qr/^Error at A/, "Inheritance is transitive");
101 local @C::CARP_NOT = "D";
102 like(A::short(), qr/^Error at B/, "Short messages see \@CARP_NOT");
106 local @D::CARP_NOT = "C";
107 like(A::short(), qr/^Error at B/, "Short messages see \@CARP_NOT");
111 local @D::CARP_NOT = "B";
112 local @B::CARP_NOT = "C";
113 like(A::short(), qr/^Error at A/, "\@CARP_NOT is transitive");
117 local @B::CARP_NOT = "D";
118 local @C::CARP_NOT = "B";
119 like(A::short(), qr/^Error at A/, "\@CARP_NOT is transitive");
124 local @D::CARP_NOT = "B";
125 like(A::short(), qr/^Error at C/, "\@CARP_NOT overrides inheritance");
130 local @D::CARP_NOT = "C";
131 like(A::short(), qr/^Error at B/, "\@CARP_NOT overrides inheritance");
136 local $Carp::Internal{C} = 1;
137 like(A::short(), qr/^Error at B/, "Short doesn't report Internal");
141 local $Carp::Internal{D} = 1;
142 like(A::long(), qr/^Error at C/, "Long doesn't report Internal");
145 # %Carp::CarpInternal
147 local $Carp::CarpInternal{D} = 1;
148 like(A::short(), qr/^Error at B/
149 , "Short doesn't report calls to CarpInternal");
153 local $Carp::CarpInternal{D} = 1;
154 like(A::long(), qr/^Error at C/, "Long doesn't report CarpInternal");
157 # tests for global variables
163 qr/t at \S*(?i:carp.t) line \d+/,
164 qr/t at \S*(?i:carp.t) line \d+\n\s*main::x\('t'\) called at \S*(?i:carp.t) line \d+/
168 for my $re (@$aref) {
169 local $Carp::Verbose = $i++;
170 local $SIG{__WARN__} = sub {
171 like $_[0], $re, 'Verbose';
181 my $txt = "Carp::cluck($test_num)";
182 local $Carp::MaxEvalLen = $_;
183 local $SIG{__WARN__} = sub {
184 "@_"=~/'(.+?)(?:\n|')/s;
185 is length($1), length($_?substr($txt,0,$_):substr($txt,0)), 'MaxEvalLen';
187 eval "$txt"; $test_num++;
194 my $arg = 'testtest';
195 local $Carp::MaxArgLen = $_;
196 local $SIG{__WARN__} = sub {
198 is length($1), length($_?substr($arg,0,$_):substr($arg,0)), 'MaxArgLen';
209 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+/,
210 qr/1234 at \S*(?i:carp.t) line \d+\n\s*main::w\(1, 2, \.\.\.\) called at \S*(?i:carp.t) line \d+/,
214 local $Carp::MaxArgNums = $i++;
215 local $SIG{__WARN__} = sub {
216 like "@_", $_, 'MaxArgNums';
227 qr/1 at \S*(?i:carp.t) line \d+\n\s*main::w\(1\) called at \S*(?i:carp.t) line \d+/,
228 qr/1 at \S*(?i:carp.t) line \d+$/,
232 local $Carp::CarpLevel = $i++;
233 local $SIG{__WARN__} = sub {
234 like "@_", $_, 'CarpLevel';
243 local $TODO = "VMS exit status semantics don't work this way" if $Is_VMS;
245 # Check that croak() and confess() don't clobber $!
246 runperl(prog => 'use Carp; $@=q{Phooey}; $!=42; croak(q{Dead})',
249 is($?>>8, 42, 'croak() doesn\'t clobber $!');
251 runperl(prog => 'use Carp; $@=q{Phooey}; $!=42; confess(q{Dead})',
254 is($?>>8, 42, 'confess() doesn\'t clobber $!');
290 eval{ Carp::croak("Error") };
295 eval{ Carp::confess("Error") };