Workaround a Test::Builder2 (2.00_06)'s threading issue.
[gitmo/Mouse.git] / t / 001_mouse / 014-build.t
CommitLineData
c3398f5b 1#!/usr/bin/env perl
2use strict;
3use warnings;
b5956f03 4use Test::More;
289e5430 5use Test::Mouse;
c3398f5b 6
9acd019a 7my @called;
c3398f5b 8
9do {
10 package Class;
043a69fb 11 use Mouse;
c3398f5b 12
13 sub BUILD {
9acd019a 14 push @called, 'Class::BUILD';
c3398f5b 15 }
16
224bfdd8 17# sub BUILDALL {
18# my $self = shift;
19# push @called, 'Class::BUILDALL';
20# $self->SUPER::BUILDALL(@_);
21# }
c3398f5b 22
23 package Child;
043a69fb 24 use Mouse;
c3398f5b 25 extends 'Class';
26
27 sub BUILD {
9acd019a 28 push @called, 'Child::BUILD';
c3398f5b 29 }
30
224bfdd8 31# sub BUILDALL {
32# my $self = shift;
33# push @called, 'Child::BUILDALL';
34# $self->SUPER::BUILDALL(@_);
35# }
c3398f5b 36};
37
9acd019a 38is_deeply([splice @called], [], "no BUILD calls yet");
c3398f5b 39
029463f4 40with_immutable sub {
289e5430 41 my $object = Class->new;
c3398f5b 42
289e5430 43 ok defined($object), $object->meta->is_immutable() ? 'mutable' : 'immutable';
c3398f5b 44
289e5430 45 is_deeply([splice @called], ["Class::BUILD"]);
c3398f5b 46
289e5430 47 my $child = Child->new;
224bfdd8 48
289e5430 49 is_deeply([splice @called], ["Class::BUILD", "Child::BUILD"]);
224bfdd8 50
289e5430 51 $child->BUILDALL({});
224bfdd8 52
289e5430 53 is_deeply([splice @called], ["Class::BUILD", "Child::BUILD"], 'BUILDALL');
b5956f03 54
55 $child = Child->meta->new_object();
56 is_deeply([splice @called], ["Class::BUILD", "Child::BUILD"], 'new_object calls BUILDALL');
029463f4 57}, qw(Class Child);
224bfdd8 58
b5956f03 59done_testing;