13 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], "(unknown)", "unknown subroutine name" );
35 ok( $c[4], "hasargs true with unknown sub" );
37 print "# Tests with caller(1)\n";
39 sub f { @c = caller(1) }
43 is( $c[3], "main::callf", "subroutine name" );
44 ok( $c[4], "hasargs true with callf()" );
46 ok( !$c[4], "hasargs false with &callf" );
49 is( $c[3], "(eval)", "subroutine name in an eval {}" );
50 ok( !$c[4], "hasargs false in an eval {}" );
53 is( $c[3], "(eval)", "subroutine name in an eval ''" );
54 ok( !$c[4], "hasargs false in an eval ''" );
57 is( $c[3], "main::__ANON__", "anonymous subroutine name" );
58 ok( $c[4], "hasargs true with anon sub" );
61 my $fooref2 = delete $::{foo2};
63 is( $c[3], "(unknown)", "unknown subroutine name" );
64 ok( $c[4], "hasargs true with unknown sub" );
66 # See if caller() returns the correct warning mask
70 is( (caller(0))[9], $w, "warnings");
73 # NB : extend the warning mask values below when new warnings are added
76 BEGIN { is( ${^WARNING_BITS}, "\0" x 12, 'warning bits' ) }
79 BEGIN { is( ${^WARNING_BITS}, "U" x 12, 'warning bits' ) }
80 BEGIN { testwarn("U" x 12); }
82 # the warning mask has been extended by warnings::register
83 testwarn("UUUUUUUUUUUU\001");
84 use warnings::register;
85 BEGIN { is( ${^WARNING_BITS}, "UUUUUUUUUUUU\001", 'warning bits' ) }
86 testwarn("UUUUUUUUUUUU\001");