summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/t/mro/recursion_dfs_utf8.t
blob: 4ad427e64f57834e67f71c7fa1c3fc494bf070d0 (plain) (blame)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!./perl

use strict;
use warnings;
BEGIN {
    unless (-d 'blib') {
        chdir 't' if -d 't';
    }
    require './test.pl';
    set_up_inc('../lib');
}
use utf8;
use open qw( :utf8 :std );

plan(skip_all => "Your system has no SIGALRM") if !exists $SIG{ALRM};
plan(tests => 8);

=pod

These are like the 010_complex_merge_classless test,
but an infinite loop has been made in the heirarchy,
to test that we can fail cleanly instead of going
into an infinite loop

=cut

# initial setup, everything sane
{
    package ƙ;
    our @ISA = qw/ᶨ ィ/;
    package ;
    our @ISA = qw/f/;
    package ;
    our @ISA = qw/ʰ f/;
    package ʰ;
    our @ISA = qw/ᶢ/;
    package ;
    our @ISA = qw/ᛞ/;
    package ;
    our @ISA = qw/ǝ/;
    package ǝ;
    our @ISA = qw/ᛞ/;
    package ;
    our @ISA = qw/Ạ B ʗ/;
    package ʗ;
    our @ISA = qw//;
    package ;
    our @ISA = qw//;
    package ;
    our @ISA = qw//;
}

# A series of 8 aberations that would cause infinite loops,
#  each one undoing the work of the previous
my @loopies = (
    sub { @ǝ::ISA = qw/f/ },
    sub { @ǝ::ISA = qw/ᛞ/; @ʗ::ISA = qw/f/ },
    sub { @ʗ::ISA = qw//; @Ạ::ISA = qw/ƙ/ },
    sub { @Ạ::ISA = qw//; @ᶨ::ISA = qw/f ƙ/ },
    sub { @ᶨ::ISA = qw/f/; @ʰ::ISA = qw/ƙ ᶢ/ },
    sub { @ʰ::ISA = qw/ᶢ/; @B::ISA = qw/B/ },
    sub { @B::ISA = qw//; @ƙ::ISA = qw/ƙ ᶨ ィ/ },
    sub { @ƙ::ISA = qw/ᶨ ィ/; @ᛞ::ISA = qw/Ạ ʰ B ʗ/ },
);

foreach my $loopy (@loopies) {
    eval {
        local $SIG{ALRM} = sub { die "ALRMTimeout" };
        alarm(3);
        $loopy->();
        mro::get_linear_isa('ƙ', 'dfs');
    };

    if(my $err = $@) {
        if($err =~ /ALRMTimeout/) {
            ok(0, "Loop terminated by SIGALRM");
        }
        elsif($err =~ /Recursive inheritance detected/) {
            ok(1, "Graceful exception thrown");
        }
        else {
            ok(0, "Unrecognized exception: $err");
        }
    }
    else {
        ok(0, "Infinite loop apparently succeeded???");
    }
}