fix deep recursion when calling isa check within isa check
[gitmo/Moo.git] / t / buildall-subconstructor.t
CommitLineData
9aa500f6 1use strictures 1;
2use Test::More;
3
4my @ran;
5
6{
7 package Foo; use Moo; sub BUILD { push @ran, 'Foo' }
8 package Bar; use Moo; extends 'Foo'; sub BUILD { push @ran, 'Bar' }
9 package Baz; use Moo; extends 'Bar';
10 package Quux; use Moo; extends 'Baz'; sub BUILD { push @ran, 'Quux' }
11}
12
13{
14 package Fleem;
15 use Moo;
16 extends 'Quux';
17 has 'foo' => (is => 'ro');
18 sub BUILD { push @ran, $_[0]->foo, $_[1]->{bar} }
19}
20
21{
22 package Odd1;
23 use Moo;
24 has 'odd1' => (is => 'ro');
25 sub BUILD { push @ran, 'Odd1' }
26 package Odd2;
27 use Moo;
28 extends 'Odd1';
29 package Odd3;
30 use Moo;
31 extends 'Odd2';
32 has 'odd3' => (is => 'ro');
33 sub BUILD { push @ran, 'Odd3' }
34}
35
36{
37 package Sub1;
38 use Moo;
39 has 'foo' => (is => 'ro');
40 package Sub2;
41 use Moo;
42 extends 'Sub1';
43 sub BUILD { push @ran, "sub2" }
44}
45
46my @tests = (
47 'Foo' => {
48 ran => [qw( Foo )],
49 },
50 'Bar' => {
51 ran => [qw( Foo Bar )],
52 },
53 'Baz' => {
54 ran => [qw( Foo Bar )],
55 },
56 'Quux' => {
57 ran => [qw( Foo Bar Quux )],
58 },
59 'Fleem' => {
60 ran => [qw( Foo Bar Quux Fleem1 Fleem2 )],
61 args => [ foo => 'Fleem1', bar => 'Fleem2' ],
62 },
63 'Odd1' => {
64 ran => [qw( Odd1 )],
65 },
66 'Odd2' => {
67 ran => [qw( Odd1 )],
68 },
69 'Odd3' => {
70 ran => [qw( Odd1 Odd3 )],
71 args => [ odd1 => 1, odd3 => 3 ],
72 },
73 'Sub1' => {
74 ran => [],
75 },
76 'Sub2' => {
77 ran => [qw( sub2 )],
78 },
79);
80
81while ( my ($class, $conf) = splice(@tests,0,2) ) {
82 my $o = $class->new( @{ $conf->{args} || [] } );
83 isa_ok($o, $class);
84 is_deeply(\@ran, $conf->{ran}, 'BUILDs ran in order');
85 @ran = ();
86}
87
88done_testing;