summaryrefslogtreecommitdiff
path: root/ext/XS-APItest/t/gv_autoload4.t
blob: b16a373a1637d6168c784700ad36fa095ac3561a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!perl

use strict;
use warnings;

use Test::More tests => 31;

use_ok('XS::APItest');

my $method = 0;
my @types  = map { 'gv_autoload' . $_ } qw( 4 _sv _pv _pvn );

sub AUTOLOAD {
    our $AUTOLOAD;
    my ($subname, $message) = @_;
    is $subname, $AUTOLOAD, $message;
}

my $sub = "nothing";

ok my $glob = XS::APItest::gv_autoload_type(\%::, $sub, 1, $method);
*{$glob}{CODE}->( __PACKAGE__ . "::" . $sub, '$AUTOLOAD set correctly' );

$sub = "some_sub";
for my $type ( 0..3 ) {
    is $glob = XS::APItest::gv_autoload_type(\%::, $sub, $type, $method), "*main::AUTOLOAD", "*main::AUTOLOAD if autoload is true in $types[$type].";
    *{$glob}{CODE}->( __PACKAGE__ . "::" . $sub, '$AUTOLOAD set correctly' );
}

$sub = "method\0not quite!";

ok $glob = XS::APItest::gv_autoload_type(\%::, $sub, 0, $method);
*{$glob}{CODE}->( __PACKAGE__ . "::" . $sub, "gv_autoload4() is nul-clean");

ok $glob = XS::APItest::gv_autoload_type(\%::, $sub, 1, $method);
*{$glob}{CODE}->( __PACKAGE__ . "::" . $sub, "gv_autoload_sv() is nul-clean");

ok $glob = XS::APItest::gv_autoload_type(\%::, $sub, 2, $method);
*{$glob}{CODE}->( __PACKAGE__ . "::" . ($sub =~ s/\0.*//r), "gv_autoload_pv() is not nul-clean");

ok $glob = XS::APItest::gv_autoload_type(\%::, $sub, 3, $method);
*{$glob}{CODE}->( __PACKAGE__ . "::" . $sub, "gv_autoload_pvn() is nul-clean");

{
    use utf8;
    use open qw( :utf8 :std );

    package main;

    sub AUTOLOAD {
        our $AUTOLOAD;
        my ($subname, $message) = @_;
        ::is $subname, $AUTOLOAD, $message;
    }

    for my $type ( 1..3 ) {
        ::ok $glob = XS::APItest::gv_autoload_type(\%main::, $sub = "method", $type, $method);
        *{$glob}{CODE}->( "main::" . $sub, "$types[$type]() is UTF8-clean when both the stash and the sub are in UTF-8");
        ::ok $glob = XS::APItest::gv_autoload_type(\%main::, $sub = "method", $type, $method);
        *{$glob}{CODE}->( "main::" . $sub, "$types[$type]() is UTF8-clean when only the stash is in UTF-8");
    }
}