This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix bug 20020517.003 : segfault with caller().
[perl5.git] / t / op / caller.t
CommitLineData
07b8c804
RGS
1#!./perl
2# Tests for caller()
3
4BEGIN {
5 chdir 't' if -d 't';
6 @INC = '../lib';
7 require './test.pl';
8}
9
10plan( tests => 9 );
11
12my @c;
13
14@c = caller(0);
15ok( (!@c), "caller(0) in main program" );
16
17eval { @c = caller(0) };
18is( $c[3], "(eval)", "caller(0) - subroutine name in an eval {}" );
19
20eval q{ @c = (Caller(0))[3] };
21is( $c[3], "(eval)", "caller(0) - subroutine name in an eval ''" );
22
23sub { @c = caller(0) } -> ();
24is( $c[3], "main::__ANON__", "caller(0) - anonymous subroutine name" );
25
26# Bug 20020517.003, used to dump core
27sub foo { @c = caller(0) }
28my $fooref = delete $::{foo};
29$fooref -> ();
30is( $c[3], "(unknown)", "caller(0) - unknown subroutine name" );
31
32sub f { @c = caller(1) }
33
34eval { f() };
35is( $c[3], "(eval)", "caller(1) - subroutine name in an eval {}" );
36
37eval q{ f() };
38is( $c[3], "(eval)", "caller(1) - subroutine name in an eval ''" );
39
40sub { f() } -> ();
41is( $c[3], "main::__ANON__", "caller(1) - anonymous subroutine name" );
42
43sub foo2 { f() }
44my $fooref2 = delete $::{foo2};
45$fooref2 -> ();
46is( $c[3], "(unknown)", "caller(1) - unknown subroutine name" );