perl/t/uni/caller.t
Nicolas R c5583fc738 t/uni/caller.t should declare its plan at run time
Unit test should declare their test plan after
compilation when possible.
2018-09-21 10:18:48 -05:00

77 lines
2.1 KiB
Perl
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!./perl
# Tests for caller()
BEGIN {
chdir 't' if -d 't';
require './test.pl';
set_up_inc('../lib');
}
use utf8;
use open qw( :utf8 :std );
plan( tests => 18 );
package ;
{
local $@;
eval 'ok(1);';
::like $@, qr/Undefined subroutine &::ok called at/u;
}
my @c;
sub { @c = caller(0) } -> ();
::is( $c[3], "::__ANON__", "anonymous subroutine name" );
::ok( $c[4], "hasargs true with anon sub" );
# Bug 20020517.003 (#9367), used to dump core
sub { @c = caller(0) }
# The subroutine only gets anonymised if it is relying on a real GV
# for its name.
() = *{""}; # with quotes so that the op tree doesnt reference the GV
my $fooref = delete $::{};
$fooref -> ();
::is( $c[3], "::__ANON__", "deleted subroutine name" );
::ok( $c[4], "hasargs true with deleted sub" );
print "# Tests with caller(1)\n";
sub { @c = caller(1) }
sub { (); }
();
::is( $c[3], "::", "subroutine name" );
::ok( $c[4], "hasargs true with ()" );
&;
::ok( !$c[4], "hasargs false with &" );
eval { () };
::is( $c[3], "(eval)", "subroutine name in an eval {}" );
::ok( !$c[4], "hasargs false in an eval {}" );
eval q{ () };
::is( $c[3], "(eval)", "subroutine name in an eval ''" );
::ok( !$c[4], "hasargs false in an eval ''" );
sub { () } -> ();
::is( $c[3], "::__ANON__", "anonymous subroutine name" );
::ok( $c[4], "hasargs true with anon sub" );
sub 2 { () }
() = *{"2"}; # see notes above
my $fooref2 = delete $::{2};
$fooref2 -> ();
::is( $c[3], "::__ANON__", "deleted subroutine name" );
::ok( $c[4], "hasargs true with deleted sub" );
sub { return (caller(0))[3] }
::is( eval '()', '::', "actually return the right function name" );
my $saved_perldb = $^P;
$^P = 16;
$^P = $saved_perldb;
::is( eval '()', '::', 'actually return the right function name even if $^P had been on at some point' );