#!./perl
# Tests for caller()
chdir 't' if -d 't';
}
my @c;
print "# Tests with caller(0)\n";
ok( (!@c), "caller(0) in main program" );
is( $c[3], "(eval)", "subroutine name in an eval {}" ); ok( !$c[4], "hasargs false in an eval {}" );
eval q{ @c = (Caller(0))[3] }; is( $c[3], "(eval)", "subroutine name in an eval ''" ); ok( !$c[4], "hasargs false in an eval ''" );
is( $c[3], "main::__ANON__", "anonymous subroutine name" ); ok( $c[4], "hasargs true with anon sub" );
# Bug 20020517.003, used to dump core
is( $c[3], "(unknown)", "unknown subroutine name" ); ok( $c[4], "hasargs true with unknown sub" );
print "# Tests with caller(1)\n";
is( $c[3], "main::callf", "subroutine name" ); ok( $c[4], "hasargs true with callf()" ); ok( !$c[4], "hasargs false with &callf" );
eval { f() };
is( $c[3], "(eval)", "subroutine name in an eval {}" ); ok( !$c[4], "hasargs false in an eval {}" );
eval q{ f() };
is( $c[3], "(eval)", "subroutine name in an eval ''" ); ok( !$c[4], "hasargs false in an eval ''" );
sub { f() } -> ();
is( $c[3], "main::__ANON__", "anonymous subroutine name" ); ok( $c[4], "hasargs true with anon sub" );
is( $c[3], "(unknown)", "unknown subroutine name" ); ok( $c[4], "hasargs true with unknown sub" );