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