This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Updates to modules-related pod
[perl5.git] / lib / Carp.t
CommitLineData
0e25c5fd
JH
1BEGIN {
2 chdir 't' if -d 't';
3 @INC = '../lib';
4}
5
6use Carp qw(carp cluck croak confess);
7
b5777b26 8print "1..9\n";
0e25c5fd
JH
9
10print "ok 1\n";
11
1115139d
JH
12$SIG{__WARN__} = sub {
13 print "ok $1\n"
59b0a8b7 14 if $_[0] =~ m!ok (\d+)\n at .+\b(?i:carp\.t) line \d+$! };
0e25c5fd 15
1115139d
JH
16carp "ok 2\n";
17
18$SIG{__WARN__} = sub {
19 print "ok $1\n"
20 if $_[0] =~ m!(\d+) at .+\b(?i:carp\.t) line \d+$! };
0e25c5fd
JH
21
22carp 3;
23
24sub sub_4 {
25
1115139d
JH
26$SIG{__WARN__} = sub {
27 print "ok $1\n"
28 if $_[0] =~ m!^(\d+) at .+\b(?i:carp\.t) line \d+\n\tmain::sub_4\(\) called at .+\b(?i:carp\.t) line \d+$! };
0e25c5fd
JH
29
30cluck 4;
31
32}
33
34sub_4;
35
1115139d
JH
36$SIG{__DIE__} = sub {
37 print "ok $1\n"
38 if $_[0] =~ m!^(\d+) at .+\b(?i:carp\.t) line \d+\n\teval \Q{...}\E called at .+\b(?i:carp\.t) line \d+$! };
0e25c5fd
JH
39
40eval { croak 5 };
41
42sub sub_6 {
1115139d
JH
43 $SIG{__DIE__} = sub {
44 print "ok $1\n"
45 if $_[0] =~ m!^(\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+$! };
0e25c5fd
JH
46
47 eval { confess 6 };
48}
49
50sub_6;
51
52print "ok 7\n";
53
976ea96e
RS
54# test for caller_info API
55my $eval = "use Carp::Heavy; return Carp::caller_info(0);";
56my %info = eval($eval);
57print "not " if ($info{sub_name} ne "eval '$eval'");
58print "ok 8\n";
b5777b26
RB
59
60# test for '...::CARP_NOT used only once' warning from Carp::Heavy
61my $warning;
62eval {
63 BEGIN {
64 $^W = 1;
65 $SIG{__WARN__} =
66 sub { if( defined $^S ){ warn $_[0] } else { $warning = $_[0] } }
67 }
68 package Z;
69 BEGIN { eval { Carp::croak() } }
70};
71print $warning ? "not ok 9\n#$warning" : "ok 9\n";