3 # This script tests the inlining and prototype of CORE:: subs. Any generic
4 # tests that are not specific to &foo-style calls should go in this
11 skip_all_without_dynamic_extension('B');
16 my $bd = new B::Deparse '-p';
18 my %unsupported = map +($_=>1), qw (CORE and cmp dump eq ge gt le
21 dbmopen => '%1,$2,$3',
25 use File::Spec::Functions;
26 my $keywords_file = catfile(updir,'regen','keywords.pl');
27 open my $kh, $keywords_file
28 or die "$0 cannot open $keywords_file: $!";
30 if (m?__END__?..${\0} and /^[+-]/) {
32 if($& eq '+' || $unsupported{$word}) {
34 ok !defined &{"CORE::$word"}, "no CORE::$word";
39 ok defined &{"CORE::$word"}, "defined &{'CORE::$word'}";
41 my $proto = prototype "CORE::$word";
42 *{"my$word"} = \&{"CORE::$word"};
43 is prototype \&{"my$word"}, $proto, "prototype of &CORE::$word";
45 CORE::state $protochar = qr/([^\\]|\\(?:[^[]|\[[^]]+\]))/;
47 () = $proto =~ s/;.*//r =~ /\G$protochar/g;
49 "#line 1 This-line-makes-__FILE__-easier-to-test.
51 . ($args_for{$word} || join ",", map "\$$_", 1..$numargs)
53 my $core = $bd->coderef2text(eval $code =~ s/my/CORE::/r or die);
54 my $my = $bd->coderef2text(eval $code or die);
55 is $my, $core, "inlinability of CORE::$word with parens";
58 "#line 1 This-line-makes-__FILE__-easier-to-test.
60 . ($args_for{$word} || join ",", map "\$$_", 1..$numargs)
62 $core = $bd->coderef2text(eval $code =~ s/my/CORE::/r or die);
63 $my = $bd->coderef2text(eval $code or die);
64 is $my, $core, "inlinability of CORE::$word without parens";
66 # High-precedence tests
68 if (!$proto && defined $proto) { # nullary
69 $hpcode = "sub { () = my$word + 1 }";
71 elsif ($proto =~ /^;?$protochar\z/) { # unary
72 $hpcode = "sub { () = my$word "
73 . ($args_for{$word}||'$a') . ' > $b'
78 $core = $bd->coderef2text(eval $hpcode =~ s/my/CORE::/r or die);
79 $my = $bd->coderef2text(eval $hpcode or die);
80 is $my, $core, "precedence of CORE::$word without parens";
83 next if ($proto =~ /\@/);
84 # These ops currently accept any number of args, despite their
85 # prototypes, if they have any:
86 next if $word =~ /^(?:chom?p|exec|keys|each|not|read(?:lin|pip)e
87 |reset|system|values|l?stat)|evalbytes/x;
91 "sub { () = (my$word("
94 ? $args_for{$word}.',$7'
95 : join ",", map "\$$_", 1..$numargs+5+(
97 ? () = $' =~ /\G$protochar/g
103 like $@, qr/^Too many arguments for $word/,
104 "inlined CORE::$word with too many args"
112 # This subroutine is outside the warnings scope:
113 sub foo { goto &CORE::abs }
115 $SIG{__WARN__} = sub { like shift, qr\^Use of uninitialized\ };
119 is runperl(prog => 'print CORE->lc, qq-\n-'), "core\n",
120 'methods calls autovivify coresubs';
121 is runperl(prog => '@ISA=CORE; print main->uc, qq-\n-'), "MAIN\n",
122 'inherted method calls autovivify coresubs';
124 is curr_test, $tests+1, 'right number of tests';