This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove undeclared $Is_VMS from DynaLoader_pm.PL
[perl5.git] / ext / XS-APItest / t / gv_autoload4.t
CommitLineData
5fba3c91
BF
1#!perl
2
3use strict;
4use warnings;
5
c8416c26 6use Test::More tests => 31;
5fba3c91
BF
7
8use_ok('XS::APItest');
9
10my $method = 0;
0fe84f7c 11my @types = map { 'gv_autoload' . $_ } qw( 4 _sv _pv _pvn );
5fba3c91
BF
12
13sub AUTOLOAD {
14 our $AUTOLOAD;
15 my ($subname, $message) = @_;
16 is $subname, $AUTOLOAD, $message;
17}
18
19my $sub = "nothing";
20
0eeb01b9 21ok my $glob = XS::APItest::gv_autoload_type(\%::, $sub, 1, $method);
5fba3c91
BF
22*{$glob}{CODE}->( __PACKAGE__ . "::" . $sub, '$AUTOLOAD set correctly' );
23
24$sub = "some_sub";
25for my $type ( 0..3 ) {
0eeb01b9 26 is $glob = XS::APItest::gv_autoload_type(\%::, $sub, $type, $method), "*main::AUTOLOAD", "*main::AUTOLOAD if autoload is true in $types[$type].";
5fba3c91
BF
27 *{$glob}{CODE}->( __PACKAGE__ . "::" . $sub, '$AUTOLOAD set correctly' );
28}
29
30$sub = "method\0not quite!";
31
0eeb01b9 32ok $glob = XS::APItest::gv_autoload_type(\%::, $sub, 0, $method);
5fba3c91
BF
33*{$glob}{CODE}->( __PACKAGE__ . "::" . $sub, "gv_autoload4() is nul-clean");
34
0eeb01b9 35ok $glob = XS::APItest::gv_autoload_type(\%::, $sub, 1, $method);
0fe84f7c 36*{$glob}{CODE}->( __PACKAGE__ . "::" . $sub, "gv_autoload_sv() is nul-clean");
5fba3c91 37
0eeb01b9 38ok $glob = XS::APItest::gv_autoload_type(\%::, $sub, 2, $method);
0fe84f7c 39*{$glob}{CODE}->( __PACKAGE__ . "::" . ($sub =~ s/\0.*//r), "gv_autoload_pv() is not nul-clean");
5fba3c91 40
0eeb01b9 41ok $glob = XS::APItest::gv_autoload_type(\%::, $sub, 3, $method);
0fe84f7c 42*{$glob}{CODE}->( __PACKAGE__ . "::" . $sub, "gv_autoload_pvn() is nul-clean");
5fba3c91 43
5fba3c91
BF
44{
45 use utf8;
46 use open qw( :utf8 :std );
47
48 package main;
49
50 sub AUTOLOAD {
51 our $AUTOLOAD;
52 my ($subname, $message) = @_;
53 ::is $subname, $AUTOLOAD, $message;
54 }
55
56 for my $type ( 1..3 ) {
0eeb01b9 57 ::ok $glob = XS::APItest::gv_autoload_type(\%main::, $sub = "method", $type, $method);
5fba3c91 58 *{$glob}{CODE}->( "main::" . $sub, "$types[$type]() is UTF8-clean when both the stash and the sub are in UTF-8");
0eeb01b9 59 ::ok $glob = XS::APItest::gv_autoload_type(\%main::, $sub = "method", $type, $method);
5fba3c91
BF
60 *{$glob}{CODE}->( "main::" . $sub, "$types[$type]() is UTF8-clean when only the stash is in UTF-8");
61 }
62}