From: Brandon L Black Date: Thu, 9 Nov 2006 22:41:02 +0000 (+0000) Subject: a better set of 5 infloop tests, current fix only fixes two of them X-Git-Tag: 0.06~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=84514a722b8e128f137b56453fe185a3a472bd96;p=gitmo%2FAlgorithm-C3.git a better set of 5 infloop tests, current fix only fixes two of them --- diff --git a/t/011_infinite_loop.t b/t/011_infinite_loop.t index 05af588..7589981 100644 --- a/t/011_infinite_loop.t +++ b/t/011_infinite_loop.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 2; +use Test::More tests => 6; BEGIN { use_ok('Algorithm::C3'); @@ -11,48 +11,103 @@ BEGIN { =pod -This is like the 010_complex_merge_classless test, +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 -my $foo = { - k => [qw(j i)], - j => [qw(f)], - i => [qw(h f)], - h => [qw(g)], - g => [qw(d)], - f => [qw(e)], - e => [qw(f)], - d => [qw(a b c)], - c => [], - b => [], - a => [], -}; - -sub supers { - return @{ $foo->{ $_[0] } }; -} +my @loopies = ( + { #1 + k => [qw(j i)], + j => [qw(f)], + i => [qw(h f)], + h => [qw(g)], + g => [qw(d)], + f => [qw(e)], + e => [qw(f)], + d => [qw(a b c)], + c => [], + b => [], + a => [], + }, + { #2 + k => [qw(j i)], + j => [qw(f)], + i => [qw(h f)], + h => [qw(g)], + g => [qw(d)], + f => [qw(e)], + e => [qw(d)], + d => [qw(a b c)], + c => [qw(f)], + b => [], + a => [], + }, + { #3 + k => [qw(j i)], + j => [qw(f)], + i => [qw(h f)], + h => [qw(g)], + g => [qw(d)], + f => [qw(e)], + e => [qw(d)], + d => [qw(a b c)], + c => [], + b => [], + a => [qw(k)], + }, + { #4 + k => [qw(j i)], + j => [qw(f k)], + i => [qw(h f)], + h => [qw(g)], + g => [qw(d)], + f => [qw(e)], + e => [qw(d)], + d => [qw(a b c)], + c => [], + b => [], + a => [], + }, + { #5 + k => [qw(j i)], + j => [qw(f)], + i => [qw(h f)], + h => [qw(k g)], + g => [qw(d)], + f => [qw(e)], + e => [qw(d)], + d => [qw(a b c)], + c => [], + b => [], + a => [], + }, +); -eval { - local $SIG{ALRM} = sub { die "ALRMTimeout" }; - alarm(3); - Algorithm::C3::merge('k', \&supers); -}; +foreach my $loopy (@loopies) { + eval { + local $SIG{ALRM} = sub { die "ALRMTimeout" }; + alarm(3); + Algorithm::C3::merge('k', sub { + return @{ $loopy->{ $_[0] } }; + }); + }; -if(my $err = $@) { - if($err =~ /ALRMTimeout/) { - ok(0, "Loop terminated by SIGALRM"); - } - elsif($err =~ /Infinite loop detected/) { - ok(1, "Graceful exception thrown"); + if(my $err = $@) { + if($err =~ /ALRMTimeout/) { + ok(0, "Loop terminated by SIGALRM"); + } + elsif($err =~ /Infinite loop detected/) { + ok(1, "Graceful exception thrown"); + } + else { + ok(0, "Unrecognized exception: $err"); + } } else { - ok(0, "Unrecognized exception: $err"); + ok(0, "Infinite loop apparently succeeded???"); } -} -else { - ok(0, "Infinite loop apparently succeeded???"); + }