13 BEGIN { print "# Tests with caller(0)\n"; }
16 ok( (!@c), "caller(0) in main program" );
18 eval { @c = caller(0) };
19 is( $c[3], "(eval)", "subroutine name in an eval {}" );
20 ok( !$c[4], "hasargs false in an eval {}" );
22 eval q{ @c = (Caller(0))[3] };
23 is( $c[3], "(eval)", "subroutine name in an eval ''" );
24 ok( !$c[4], "hasargs false in an eval ''" );
26 sub { @c = caller(0) } -> ();
27 is( $c[3], "main::__ANON__", "anonymous subroutine name" );
28 ok( $c[4], "hasargs true with anon sub" );
30 # Bug 20020517.003, used to dump core
31 sub foo { @c = caller(0) }
32 my $fooref = delete $::{foo};
34 is( $c[3], "main::__ANON__", "deleted subroutine name" );
35 ok( $c[4], "hasargs true with deleted sub" );
39 is +(caller 0)[1], __FILE__,
40 "[perl #68712] filenames after require in a BEGIN block"
43 print "# Tests with caller(1)\n";
45 sub f { @c = caller(1) }
49 is( $c[3], "main::callf", "subroutine name" );
50 ok( $c[4], "hasargs true with callf()" );
52 ok( !$c[4], "hasargs false with &callf" );
55 is( $c[3], "(eval)", "subroutine name in an eval {}" );
56 ok( !$c[4], "hasargs false in an eval {}" );
59 is( $c[3], "(eval)", "subroutine name in an eval ''" );
60 ok( !$c[4], "hasargs false in an eval ''" );
63 is( $c[3], "main::__ANON__", "anonymous subroutine name" );
64 ok( $c[4], "hasargs true with anon sub" );
67 my $fooref2 = delete $::{foo2};
69 is( $c[3], "main::__ANON__", "deleted subroutine name" );
70 ok( $c[4], "hasargs true with deleted sub" );
72 # See if caller() returns the correct warning mask
78 foreach (unpack('W*', $in)) {
79 $out .= sprintf('\x%02x', $_);
86 local $Level = $Level + 2;
87 my ($got, $exp, $desc) = @_;
88 if (! ok($got eq $exp, $desc)) {
89 diag(' got: ' . show_bits($got));
90 diag('expected: ' . show_bits($exp));
97 check_bits( (caller(0))[9], $w, "warnings match caller ($id)");
102 # Build the warnings mask dynamically
103 my ($default, $registered);
105 for my $i (0..$warnings::LAST_BIT/2 - 1) {
106 vec($default, $i, 2) = 1;
108 $registered = $default;
109 vec($registered, $warnings::LAST_BIT/2, 2) = 1;
112 # The repetition number must be set to the value of $BYTES in
114 BEGIN { check_bits( ${^WARNING_BITS}, "\0" x 13, 'all bits off via "no warnings"' ) }
115 testwarn("\0" x 13, 'no bits');
118 BEGIN { check_bits( ${^WARNING_BITS}, $default,
119 'default bits on via "use warnings"' ); }
120 BEGIN { testwarn($default, 'all'); }
122 # the warning mask has been extended by warnings::register
123 testwarn($registered, 'ahead of w::r');
125 use warnings::register;
126 BEGIN { check_bits( ${^WARNING_BITS}, $registered,
127 'warning bits on via "use warnings::register"' ) }
128 testwarn($registered, 'following w::r');
132 # The next two cases test for a bug where caller ignored evals if
133 # the DB::sub glob existed but &DB::sub did not (for example, if
134 # $^P had been set but no debugger has been loaded). The tests
135 # thus assume that there is no &DB::sub: if there is one, they
136 # should both pass no matter whether or not this bug has been
139 my $debugger_test = q<
140 my @stackinfo = caller(0);
141 return scalar @stackinfo;
144 sub pb { return (caller(0))[3] }
146 my $i = eval $debugger_test;
147 is( $i, 11, "do not skip over eval (and caller returns 10 elements)" );
149 is( eval 'pb()', 'main::pb', "actually return the right function name" );
151 my $saved_perldb = $^P;
155 $i = eval $debugger_test;
156 is( $i, 11, 'do not skip over eval even if $^P had been on at some point' );
157 is( eval 'pb()', 'main::pb', 'actually return the right function name even if $^P had been on at some point' );
159 print "# caller can now return the compile time state of %^H\n";
164 my @results = caller($level||0);
165 exists $results[10]->{$key};
171 my @results = caller($level||0);
172 $results[10]->{$key};
176 my $tmpfile = tempfile();
178 open my $fh, '>', $tmpfile or die "open $tmpfile: $!";
191 @DB::args = bless [], 'KAZASH';
194 print scalar @DB::args;
200 @DB::args = (); # At this point, the object should be freed.
203 print scalar @DB::args;
210 my $got = runperl(progfile => $tmpfile, args => [$_]);
212 like($got, qr/\s*0 1 DESTROY 0 0\s*/,
213 "\@DB::args doesn't leak with \$^P = $_");
217 $::testing_caller = 1;
219 do './op/caller.pl' or die $@;