summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2002-05-17 20:07:21 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2002-05-17 20:07:21 +0000
commit72699b0f2772b6d9c4affdf9e0a3a501db463332 (patch)
treec34dbc6736ad692409055cbd544c719b73e7c21b
parentfa07f620619b7e6ff96ee2044fadd2ca7cc948ff (diff)
downloadperl-72699b0f2772b6d9c4affdf9e0a3a501db463332.tar.gz
More regression tests for caller() and fix one bug of #16658.
p4raw-id: //depot/perl@16662
-rw-r--r--pp_ctl.c2
-rw-r--r--t/op/caller.t37
2 files changed, 29 insertions, 10 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index 8432a15871..2fb4b17bcd 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1460,7 +1460,7 @@ PP(pp_caller)
}
else {
PUSHs(sv_2mortal(newSVpvn("(unknown)",9)));
- PUSHs(sv_2mortal(newSViv(0)));
+ PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
}
}
else {
diff --git a/t/op/caller.t b/t/op/caller.t
index 1b08d93002..751a161de2 100644
--- a/t/op/caller.t
+++ b/t/op/caller.t
@@ -7,40 +7,59 @@ BEGIN {
require './test.pl';
}
-plan( tests => 9 );
+plan( tests => 20 );
my @c;
+print "# Tests with caller(0)\n";
+
@c = caller(0);
ok( (!@c), "caller(0) in main program" );
eval { @c = caller(0) };
-is( $c[3], "(eval)", "caller(0) - subroutine name in an eval {}" );
+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)", "caller(0) - subroutine name in an eval ''" );
+is( $c[3], "(eval)", "subroutine name in an eval ''" );
+ok( !$c[4], "hasargs false in an eval ''" );
sub { @c = caller(0) } -> ();
-is( $c[3], "main::__ANON__", "caller(0) - anonymous subroutine name" );
+is( $c[3], "main::__ANON__", "anonymous subroutine name" );
+ok( $c[4], "hasargs true with anon sub" );
# Bug 20020517.003, used to dump core
sub foo { @c = caller(0) }
my $fooref = delete $::{foo};
$fooref -> ();
-is( $c[3], "(unknown)", "caller(0) - unknown subroutine name" );
+is( $c[3], "(unknown)", "unknown subroutine name" );
+ok( $c[4], "hasargs true with unknown sub" );
+
+print "# Tests with caller(1)\n";
sub f { @c = caller(1) }
+sub callf { f(); }
+callf();
+is( $c[3], "main::callf", "subroutine name" );
+ok( $c[4], "hasargs true with callf()" );
+&callf;
+ok( !$c[4], "hasargs false with &callf" );
+
eval { f() };
-is( $c[3], "(eval)", "caller(1) - subroutine name in an eval {}" );
+is( $c[3], "(eval)", "subroutine name in an eval {}" );
+ok( !$c[4], "hasargs false in an eval {}" );
eval q{ f() };
-is( $c[3], "(eval)", "caller(1) - subroutine name in an eval ''" );
+is( $c[3], "(eval)", "subroutine name in an eval ''" );
+ok( !$c[4], "hasargs false in an eval ''" );
sub { f() } -> ();
-is( $c[3], "main::__ANON__", "caller(1) - anonymous subroutine name" );
+is( $c[3], "main::__ANON__", "anonymous subroutine name" );
+ok( $c[4], "hasargs true with anon sub" );
sub foo2 { f() }
my $fooref2 = delete $::{foo2};
$fooref2 -> ();
-is( $c[3], "(unknown)", "caller(1) - unknown subroutine name" );
+is( $c[3], "(unknown)", "unknown subroutine name" );
+ok( $c[4], "hasargs true with unknown sub" );