Commit | Line | Data |
e1a479c5 |
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 | |
5f5ae4a7 |
12 | require './test.pl'; |
e1a479c5 |
13 | |
5f5ae4a7 |
14 | plan(skip_all => "Your system has no SIGALRM") if !exists $SIG{ALRM}; |
15 | plan(tests => 8); |
e1a479c5 |
16 | |
b2685f0c |
17 | require mro; |
18 | |
e1a479c5 |
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 K; |
1dcae283 |
31 | use mro 'c3'; |
e1a479c5 |
32 | our @ISA = qw/J I/; |
33 | package J; |
1dcae283 |
34 | use mro 'c3'; |
e1a479c5 |
35 | our @ISA = qw/F/; |
36 | package I; |
1dcae283 |
37 | use mro 'c3'; |
e1a479c5 |
38 | our @ISA = qw/H F/; |
39 | package H; |
1dcae283 |
40 | use mro 'c3'; |
e1a479c5 |
41 | our @ISA = qw/G/; |
42 | package G; |
1dcae283 |
43 | use mro 'c3'; |
e1a479c5 |
44 | our @ISA = qw/D/; |
45 | package F; |
1dcae283 |
46 | use mro 'c3'; |
e1a479c5 |
47 | our @ISA = qw/E/; |
48 | package E; |
1dcae283 |
49 | use mro 'c3'; |
e1a479c5 |
50 | our @ISA = qw/D/; |
51 | package D; |
1dcae283 |
52 | use mro 'c3'; |
e1a479c5 |
53 | our @ISA = qw/A B C/; |
54 | package C; |
1dcae283 |
55 | use mro 'c3'; |
e1a479c5 |
56 | our @ISA = qw//; |
57 | package B; |
1dcae283 |
58 | use mro 'c3'; |
e1a479c5 |
59 | our @ISA = qw//; |
60 | package A; |
1dcae283 |
61 | use mro 'c3'; |
e1a479c5 |
62 | our @ISA = qw//; |
63 | } |
64 | |
65 | # A series of 8 abberations that would cause infinite loops, |
66 | # each one undoing the work of the previous |
67 | my @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 | |
78 | foreach 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 | } |