number squirrel.t
[gitmo/Mouse.git] / t / 014-build.t
CommitLineData
c3398f5b 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More tests => 12;
5
6my ($class_build, $child_build) = (0, 0);
7my ($class_buildall, $child_buildall) = (0, 0);
8
9do {
10 package Class;
11 use Mouse;
12
13 sub BUILD {
14 ++$class_build;
15 }
16
17 sub BUILDALL {
18 my $self = shift;
19 ++$class_buildall;
20 $self->SUPER::BUILDALL(@_);
21 }
22
23 package Child;
24 use Mouse;
25 extends 'Class';
26
27 sub BUILD {
28 ++$child_build;
29 }
30
31 sub BUILDALL {
32 my $self = shift;
33 ++$child_buildall;
34 $self->SUPER::BUILDALL(@_);
35 }
36
37
38};
39
40is($class_build, 0, "no calls to Class->BUILD");
41is($child_build, 0, "no calls to Child->BUILD");
42
43is($class_buildall, 0, "no calls to Class->BUILDALL");
44is($child_buildall, 0, "no calls to Child->BUILDALL");
45
46my $object = Class->new;
47
48is($class_build, 1, "Class->new calls Class->BUILD");
49is($child_build, 0, "Class->new does not call Child->BUILD");
50
51is($class_buildall, 1, "Class->new calls Class->BUILDALL");
52is($child_buildall, 0, "no calls to Child->BUILDALL");
53
54my $child = Child->new;
55
56is($child_build, 1, "Child->new calls Child->BUILD");
57is($class_build, 2, "Child->new also calls Class->BUILD");
58
59is($child_buildall, 1, "Child->new calls Child->BUILDALL");
60is($class_buildall, 2, "Child->BUILDALL calls Class->BUILDALL (but not Child->new)");
61