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