From: Shawn M Moore Date: Tue, 10 Jun 2008 19:10:28 +0000 (+0000) Subject: Improve BUILD/DEMOLISH tests to cover ordering X-Git-Tag: 0.04~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9acd019a9a908540601be5d4896eacc32c435de1;p=gitmo%2FMouse.git Improve BUILD/DEMOLISH tests to cover ordering --- diff --git a/t/014-build.t b/t/014-build.t index 0950acc..6c10857 100644 --- a/t/014-build.t +++ b/t/014-build.t @@ -1,61 +1,45 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 12; +use Test::More tests => 3; -my ($class_build, $child_build) = (0, 0); -my ($class_buildall, $child_buildall) = (0, 0); +my @called; do { package Class; - use Mouse; + use Moose; sub BUILD { - ++$class_build; + push @called, 'Class::BUILD'; } sub BUILDALL { my $self = shift; - ++$class_buildall; + push @called, 'Class::BUILDALL'; $self->SUPER::BUILDALL(@_); } package Child; - use Mouse; + use Moose; extends 'Class'; sub BUILD { - ++$child_build; + push @called, 'Child::BUILD'; } sub BUILDALL { my $self = shift; - ++$child_buildall; + push @called, 'Child::BUILDALL'; $self->SUPER::BUILDALL(@_); } - - }; -is($class_build, 0, "no calls to Class->BUILD"); -is($child_build, 0, "no calls to Child->BUILD"); - -is($class_buildall, 0, "no calls to Class->BUILDALL"); -is($child_buildall, 0, "no calls to Child->BUILDALL"); +is_deeply([splice @called], [], "no BUILD calls yet"); my $object = Class->new; -is($class_build, 1, "Class->new calls Class->BUILD"); -is($child_build, 0, "Class->new does not call Child->BUILD"); - -is($class_buildall, 1, "Class->new calls Class->BUILDALL"); -is($child_buildall, 0, "no calls to Child->BUILDALL"); +is_deeply([splice @called], ["Class::BUILDALL", "Class::BUILD"]); my $child = Child->new; -is($child_build, 1, "Child->new calls Child->BUILD"); -is($class_build, 2, "Child->new also calls Class->BUILD"); - -is($child_buildall, 1, "Child->new calls Child->BUILDALL"); -is($class_buildall, 2, "Child->BUILDALL calls Class->BUILDALL (but not Child->new)"); - +is_deeply([splice @called], ["Child::BUILDALL", "Class::BUILDALL", "Class::BUILD", "Child::BUILD"]); diff --git a/t/015-demolish.t b/t/015-demolish.t index a534c8b..123c2d2 100644 --- a/t/015-demolish.t +++ b/t/015-demolish.t @@ -1,22 +1,21 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 20; +use Test::More tests => 5; -my ($class_demolish, $child_demolish) = (0, 0); -my ($class_demolishall, $child_demolishall) = (0, 0); +my @called; do { package Class; use Mouse; sub DEMOLISH { - ++$class_demolish; + push @called, 'Class::DEMOLISH'; } sub DEMOLISHALL { my $self = shift; - ++$class_demolishall; + push @called, 'Class::DEMOLISHALL'; $self->SUPER::DEMOLISHALL(@_); } @@ -25,51 +24,30 @@ do { extends 'Class'; sub DEMOLISH { - ++$child_demolish; + push @called, 'Child::DEMOLISH'; } sub DEMOLISHALL { my $self = shift; - ++$child_demolishall; + push @called, 'Child::DEMOLISHALL'; $self->SUPER::DEMOLISHALL(@_); } }; -is($class_demolish, 0, "no calls to Class->DEMOLISH"); -is($child_demolish, 0, "no calls to Child->DEMOLISH"); - -is($class_demolishall, 0, "no calls to Class->DEMOLISHALL"); -is($child_demolishall, 0, "no calls to Child->DEMOLISHALL"); +is_deeply([splice @called], [], "no DEMOLISH calls yet"); do { my $object = Class->new; - is($class_demolish, 0, "Class->new does not call Class->DEMOLISH"); - is($child_demolish, 0, "Class->new does not call Child->DEMOLISH"); - - is($class_demolishall, 0, "Class->new does not call Class->DEMOLISHALL"); - is($child_demolishall, 0, "Class->new does not call Child->DEMOLISHALL"); + is_deeply([splice @called], [], "no DEMOLISH calls yet"); }; -is($class_demolish, 1, "Class->DESTROY calls Class->DEMOLISH"); -is($child_demolish, 0, "Class->DESTROY does not call Child->DEMOLISH"); - -is($class_demolishall, 1, "Class->DESTROY calls Class->DEMOLISHALL"); -is($child_demolishall, 0, "no calls to Child->DEMOLISHALL"); +is_deeply([splice @called], ['Class::DEMOLISHALL', 'Class::DEMOLISH']); do { my $child = Child->new; + is_deeply([splice @called], [], "no DEMOLISH calls yet"); - is($class_demolish, 1, "Child->new does not call Class->DEMOLISH"); - is($child_demolish, 0, "Child->new does not call Child->DEMOLISH"); - - is($class_demolishall, 1, "Child->DEMOLISHALL does not call Class->DEMOLISHALL (but not Child->new)"); - is($child_demolishall, 0, "Child->new does not call Child->DEMOLISHALL"); }; -is($child_demolish, 1, "Child->DESTROY calls Child->DEMOLISH"); -is($class_demolish, 2, "Child->DESTROY also calls Class->DEMOLISH"); - -is($child_demolishall, 1, "Child->DESTROY calls Child->DEMOLISHALL"); -is($class_demolishall, 2, "Child->DEMOLISHALL calls Class->DEMOLISHALL (but not Child->DESTROY)"); - +is_deeply([splice @called], ['Child::DEMOLISHALL', 'Class::DEMOLISHALL', 'Child::DEMOLISH', 'Class::DEMOLISH']);