From: Brandon L Black Date: Thu, 9 Nov 2006 22:28:27 +0000 (+0000) Subject: cleaned up infinite loop test X-Git-Tag: 0.06~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cadd8759e3d0de5dbe611fc983637a6b092b1cec;p=gitmo%2FAlgorithm-C3.git cleaned up infinite loop test --- diff --git a/t/011_infinite_loop.t b/t/011_infinite_loop.t index b466d9b..24f4e76 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 => 12; +use Test::More tests => 1; BEGIN { use_ok('Algorithm::C3'); @@ -11,45 +11,10 @@ BEGIN { =pod -This example is taken from: http://rt.cpan.org/Public/Bug/Display.html?id=20879 - - --- --- --- -Level 5 8 | A | 9 | B | A | C | (More General) - --- --- --- V - \ | / | - \ | / | - \ | / | - \ | / | - --- | -Level 4 7 | D | | - --- | - / \ | - / \ | - --- --- | -Level 3 4 | G | 6 | E | | - --- --- | - | | | - | | | - --- --- | -Level 2 3 | H | 5 | F | | - --- --- | - \ / | | - \ / | | - \ | | - / \ | | - / \ | | - --- --- | -Level 1 1 | J | 2 | I | | - --- --- | - \ / | - \ / | - --- v -Level 0 0 | K | (More Specialized) - --- - - -0123456789A -KJIHGFEDABC +This is 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 @@ -71,57 +36,23 @@ sub supers { return @{ $foo->{ $_[0] } }; } -is_deeply( - [ Algorithm::C3::merge('a', \&supers) ], - [ qw(a) ], - '... got the right C3 merge order for a'); - -is_deeply( - [ Algorithm::C3::merge('b', \&supers) ], - [ qw(b) ], - '... got the right C3 merge order for b'); - -is_deeply( - [ Algorithm::C3::merge('c', \&supers) ], - [ qw(c) ], - '... got the right C3 merge order for c'); - -is_deeply( - [ Algorithm::C3::merge('d', \&supers) ], - [ qw(d a b c) ], - '... got the right C3 merge order for d'); - -is_deeply( - [ Algorithm::C3::merge('e', \&supers) ], - [ qw(e d a b c) ], - '... got the right C3 merge order for e'); - -is_deeply( - [ Algorithm::C3::merge('f', \&supers) ], - [ qw(f e d a b c) ], - '... got the right C3 merge order for f'); - -is_deeply( - [ Algorithm::C3::merge('g', \&supers) ], - [ qw(g d a b c) ], - '... got the right C3 merge order for g'); - -is_deeply( - [ Algorithm::C3::merge('h', \&supers) ], - [ qw(h g d a b c) ], - '... got the right C3 merge order for h'); - -is_deeply( - [ Algorithm::C3::merge('i', \&supers) ], - [ qw(i h g f e d a b c) ], - '... got the right C3 merge order for i'); - -is_deeply( - [ Algorithm::C3::merge('j', \&supers) ], - [ qw(j f e d a b c) ], - '... got the right C3 merge order for j'); +eval { + local $SIG{ALRM} = sub { die "ALRMTimeout" }; + alarm(3); + Algorithm::C3::merge('k', \&supers); +}; -is_deeply( - [ Algorithm::C3::merge('k', \&supers) ], - [ qw(k j i h g f e d a b c) ], - '... got the right C3 merge order for k'); +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, "Infinite loop apparently succeeded???"); +}