This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
gv.c:gv_autoload_pvn: Avoid warning due to temp flag
[perl5.git] / ext / XS-APItest / t / autoload.t
CommitLineData
6911735f
FC
1#!perl
2
8fa6a409
FC
3# This script tests not only the interface for XS AUTOLOAD routines to find
4# out the sub name, but also that that interface does not interfere with
5# prototypes, the way it did before 5.15.4.
6
6911735f
FC
7use strict;
8use warnings;
9
8fa6a409 10use Test::More tests => 14;
6911735f
FC
11
12use XS::APItest;
13
14is XS::APItest::AutoLoader::frob(), 'frob', 'name passed to XS AUTOLOAD';
15is "XS::APItest::AutoLoader::fr\0b"->(), "fr\0b",
16 'name with embedded null passed to XS AUTOLOAD';
17is "XS::APItest::AutoLoader::fr\x{1ed9}b"->(), "fr\x{1ed9}b",
18 'Unicode name passed to XS AUTOLOAD';
8fa6a409
FC
19
20*AUTOLOAD = *XS::APItest::AutoLoader::AUTOLOADp;
21
22is frob(), 'frob', 'name passed to XS AUTOLOAD with proto';
23is prototype \&AUTOLOAD, '*$', 'prototype is unchanged';
24is "fr\0b"->(), "fr\0b",
25 'name with embedded null passed to XS AUTOLOAD with proto';
26is prototype \&AUTOLOAD, '*$', 'proto unchanged after embedded-null call';
27is "fr\x{1ed9}b"->(), "fr\x{1ed9}b",
28 'Unicode name passed to XS AUTOLOAD with proto';
29is prototype \&AUTOLOAD, '*$', 'prototype is unchanged after Unicode call';
30
31# Test that the prototype was preserved from the parser’s point of view
32
33ok !eval "sub { ::AUTOLOAD(1) }",
34 'parse failure due to AUTOLOAD prototype';
35ok eval "sub { ::AUTOLOAD(1,2) }", 'successful parse respecting prototype'
36 or diag $@;
37
38package fribble { sub a { return 7 } }
39no warnings 'once';
40*a = \&AUTOLOAD;
41'$'->();
42# &a('fribble') will return '$'
43# But if intuit_method does not see the (*...) proto, this compiles as
44# fribble->a
45no strict;
46is eval 'a fribble, 3', '$', 'intuit_method sees * in AUTOLOAD proto'
47 or diag $@;
48
49# precedence check
50# *$ should parse as a list operator, but right now the AUTOLOAD
51# sub name is $
52is join(" ", eval 'a "b", "c"'), '$',
53 'precedence determination respects prototype of AUTOLOAD sub';
54
55{
56 my $w;
57 local $SIG{__WARN__} = sub { $w .= shift };
58 eval 'sub a($){}';
59 like $w, qr/^Prototype mismatch: sub main::a \(\*\$\) vs \(\$\)/m,
60 'proto warnings respect AUTOLOAD prototypes';
61}