summaryrefslogtreecommitdiff
path: root/t/mro/recursion_c3.t
diff options
context:
space:
mode:
authorBrandon Black <blblack@gmail.com>2007-04-17 08:14:36 -0500
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2007-04-19 14:48:20 +0000
commite1a479c5e0c08fb10925261f03573261c69ca0dc (patch)
tree09088fd1ef489ff5660300a532f799144ff7ae6a /t/mro/recursion_c3.t
parent0a311364e00e9bf5b4fcb140ade49b02e46833dd (diff)
downloadperl-e1a479c5e0c08fb10925261f03573261c69ca0dc.tar.gz
Re: new C3 MRO patch
From: "Brandon Black" <blblack@gmail.com> Message-ID: <84621a60704171114k29b0460el5b08ce5185d55ed5@mail.gmail.com> p4raw-id: //depot/perl@30980
Diffstat (limited to 't/mro/recursion_c3.t')
-rw-r--r--t/mro/recursion_c3.t88
1 files changed, 88 insertions, 0 deletions
diff --git a/t/mro/recursion_c3.t b/t/mro/recursion_c3.t
new file mode 100644
index 0000000000..60b174b1d2
--- /dev/null
+++ b/t/mro/recursion_c3.t
@@ -0,0 +1,88 @@
+#!./perl
+
+use strict;
+use warnings;
+BEGIN {
+ unless (-d 'blib') {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+ }
+}
+
+use Test::More;
+use mro;
+
+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 K;
+ our @ISA = qw/J I/;
+ package J;
+ our @ISA = qw/F/;
+ package I;
+ our @ISA = qw/H F/;
+ package H;
+ our @ISA = qw/G/;
+ package G;
+ our @ISA = qw/D/;
+ package F;
+ our @ISA = qw/E/;
+ package E;
+ our @ISA = qw/D/;
+ package D;
+ our @ISA = qw/A B C/;
+ package C;
+ our @ISA = qw//;
+ package B;
+ our @ISA = qw//;
+ package A;
+ our @ISA = qw//;
+}
+
+# A series of 8 abberations that would cause infinite loops,
+# each one undoing the work of the previous
+my @loopies = (
+ sub { @E::ISA = qw/F/ },
+ sub { @E::ISA = qw/D/; @C::ISA = qw/F/ },
+ sub { @C::ISA = qw//; @A::ISA = qw/K/ },
+ sub { @A::ISA = qw//; @J::ISA = qw/F K/ },
+ sub { @J::ISA = qw/F/; @H::ISA = qw/K G/ },
+ sub { @H::ISA = qw/G/; @B::ISA = qw/B/ },
+ sub { @B::ISA = qw//; @K::ISA = qw/K J I/ },
+ sub { @K::ISA = qw/J I/; @D::ISA = qw/A H B C/ },
+);
+
+foreach my $loopy (@loopies) {
+ eval {
+ local $SIG{ALRM} = sub { die "ALRMTimeout" };
+ alarm(3);
+ $loopy->();
+ mro::get_linear_isa('K', 'c3');
+ };
+
+ 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???");
+ }
+}