This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix NAME of perl5125delta.pod
[perl5.git] / t / mro / recursion_dfs_utf8.t
1 #!./perl
2
3 use strict;
4 use warnings;
5 BEGIN {
6     unless (-d 'blib') {
7         chdir 't' if -d 't';
8         @INC = '../lib';
9     }
10 }
11 use utf8;
12 use open qw( :utf8 :std );
13
14 require './test.pl';
15
16 plan(skip_all => "Your system has no SIGALRM") if !exists $SIG{ALRM};
17 plan(tests => 8);
18
19 =pod
20
21 These are like the 010_complex_merge_classless test,
22 but an infinite loop has been made in the heirarchy,
23 to test that we can fail cleanly instead of going
24 into an infinite loop
25
26 =cut
27
28 # initial setup, everything sane
29 {
30     package ƙ;
31     our @ISA = qw/ᶨ ィ/;
32     package ᶨ;
33     our @ISA = qw/f/;
34     package ィ;
35     our @ISA = qw/ʰ f/;
36     package ʰ;
37     our @ISA = qw/ᶢ/;
38     package ᶢ;
39     our @ISA = qw/ᛞ/;
40     package f;
41     our @ISA = qw/ǝ/;
42     package ǝ;
43     our @ISA = qw/ᛞ/;
44     package ᛞ;
45     our @ISA = qw/Ạ B ʗ/;
46     package ʗ;
47     our @ISA = qw//;
48     package B;
49     our @ISA = qw//;
50     package Ạ;
51     our @ISA = qw//;
52 }
53
54 # A series of 8 aberations that would cause infinite loops,
55 #  each one undoing the work of the previous
56 my @loopies = (
57     sub { @ǝ::ISA = qw/f/ },
58     sub { @ǝ::ISA = qw/ᛞ/; @ʗ::ISA = qw/f/ },
59     sub { @ʗ::ISA = qw//; @Ạ::ISA = qw/ƙ/ },
60     sub { @Ạ::ISA = qw//; @ᶨ::ISA = qw/f ƙ/ },
61     sub { @ᶨ::ISA = qw/f/; @ʰ::ISA = qw/ƙ ᶢ/ },
62     sub { @ʰ::ISA = qw/ᶢ/; @B::ISA = qw/B/ },
63     sub { @B::ISA = qw//; @ƙ::ISA = qw/ƙ ᶨ ィ/ },
64     sub { @ƙ::ISA = qw/ᶨ ィ/; @ᛞ::ISA = qw/Ạ ʰ B ʗ/ },
65 );
66
67 foreach my $loopy (@loopies) {
68     eval {
69         local $SIG{ALRM} = sub { die "ALRMTimeout" };
70         alarm(3);
71         $loopy->();
72         mro::get_linear_isa('ƙ', 'dfs');
73     };
74
75     if(my $err = $@) {
76         if($err =~ /ALRMTimeout/) {
77             ok(0, "Loop terminated by SIGALRM");
78         }
79         elsif($err =~ /Recursive inheritance detected/) {
80             ok(1, "Graceful exception thrown");
81         }
82         else {
83             ok(0, "Unrecognized exception: $err");
84         }
85     }
86     else {
87         ok(0, "Infinite loop apparently succeeded???");
88     }
89 }