xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/Carp.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gateBEGIN {
2*0Sstevel@tonic-gate	chdir 't' if -d 't';
3*0Sstevel@tonic-gate	@INC = '../lib';
4*0Sstevel@tonic-gate}
5*0Sstevel@tonic-gate
6*0Sstevel@tonic-gateuse Carp qw(carp cluck croak confess);
7*0Sstevel@tonic-gate
8*0Sstevel@tonic-gateprint "1..9\n";
9*0Sstevel@tonic-gate
10*0Sstevel@tonic-gateprint "ok 1\n";
11*0Sstevel@tonic-gate
12*0Sstevel@tonic-gate$SIG{__WARN__} = sub {
13*0Sstevel@tonic-gate    print "ok $1\n"
14*0Sstevel@tonic-gate	if $_[0] =~ m!ok (\d+)$! };
15*0Sstevel@tonic-gate
16*0Sstevel@tonic-gatecarp  "ok 2\n";
17*0Sstevel@tonic-gate
18*0Sstevel@tonic-gate$SIG{__WARN__} = sub {
19*0Sstevel@tonic-gate    print "ok $1\n"
20*0Sstevel@tonic-gate	if $_[0] =~ m!(\d+) at .+\b(?i:carp\.t) line \d+$! };
21*0Sstevel@tonic-gate
22*0Sstevel@tonic-gatecarp 3;
23*0Sstevel@tonic-gate
24*0Sstevel@tonic-gatesub sub_4 {
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate$SIG{__WARN__} = sub {
27*0Sstevel@tonic-gate    print "ok $1\n"
28*0Sstevel@tonic-gate	if $_[0] =~ m!^(\d+) at .+\b(?i:carp\.t) line \d+\n\tmain::sub_4\(\) called at .+\b(?i:carp\.t) line \d+$! };
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gatecluck 4;
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gate}
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gatesub_4;
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gate$SIG{__DIE__} = sub {
37*0Sstevel@tonic-gate    print "ok $1\n"
38*0Sstevel@tonic-gate	if $_[0] =~ m!^(\d+) at .+\b(?i:carp\.t) line \d+\n\teval \Q{...}\E called at .+\b(?i:carp\.t) line \d+$! };
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gateeval { croak 5 };
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gatesub sub_6 {
43*0Sstevel@tonic-gate    $SIG{__DIE__} = sub {
44*0Sstevel@tonic-gate	print "ok $1\n"
45*0Sstevel@tonic-gate	    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+$! };
46*0Sstevel@tonic-gate
47*0Sstevel@tonic-gate    eval { confess 6 };
48*0Sstevel@tonic-gate}
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gatesub_6;
51*0Sstevel@tonic-gate
52*0Sstevel@tonic-gateprint "ok 7\n";
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gate# test for caller_info API
55*0Sstevel@tonic-gatemy $eval = "use Carp::Heavy; return Carp::caller_info(0);";
56*0Sstevel@tonic-gatemy %info = eval($eval);
57*0Sstevel@tonic-gateprint "not " if ($info{sub_name} ne "eval '$eval'");
58*0Sstevel@tonic-gateprint "ok 8\n";
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate# test for '...::CARP_NOT used only once' warning from Carp::Heavy
61*0Sstevel@tonic-gatemy $warning;
62*0Sstevel@tonic-gateeval {
63*0Sstevel@tonic-gate    BEGIN {
64*0Sstevel@tonic-gate	$^W = 1;
65*0Sstevel@tonic-gate	$SIG{__WARN__} =
66*0Sstevel@tonic-gate	    sub { if( defined $^S ){ warn $_[0] } else { $warning = $_[0] } }
67*0Sstevel@tonic-gate    }
68*0Sstevel@tonic-gate    package Z;
69*0Sstevel@tonic-gate    BEGIN { eval { Carp::croak() } }
70*0Sstevel@tonic-gate};
71*0Sstevel@tonic-gateprint $warning ? "not ok 9\n#$warning" : "ok 9\n";
72