From: Jesse Luehrs Date: Sun, 3 May 2009 06:26:29 +0000 (-0500) Subject: add some tests relating to destruction X-Git-Tag: 0.78~45 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9a7f2b2dbe436e6556451287b2b7b2c61275e1d7;p=gitmo%2FMoose.git add some tests relating to destruction --- diff --git a/t/010_basics/019-destruction.t b/t/010_basics/019-destruction.t new file mode 100644 index 0000000..fecdad8 --- /dev/null +++ b/t/010_basics/019-destruction.t @@ -0,0 +1,51 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 3; + +our @demolished; +package Foo; +use Moose; + +sub DEMOLISH { + my $self = shift; + push @::demolished, __PACKAGE__; +} + +package Foo::Sub; +use Moose; +extends 'Foo'; + +sub DEMOLISH { + my $self = shift; + push @::demolished, __PACKAGE__; +} + +package Foo::Sub::Sub; +use Moose; +extends 'Foo::Sub'; + +sub DEMOLISH { + my $self = shift; + push @::demolished, __PACKAGE__; +} + +package main; +{ + my $foo = Foo->new; +} +is_deeply(\@demolished, ['Foo'], "Foo demolished properly"); +@demolished = (); +{ + my $foo_sub = Foo::Sub->new; +} +is_deeply(\@demolished, ['Foo::Sub', 'Foo'], "Foo::Sub demolished properly"); +@demolished = (); +{ + my $foo_sub_sub = Foo::Sub::Sub->new; +} +is_deeply(\@demolished, ['Foo::Sub::Sub', 'Foo::Sub', 'Foo'], + "Foo::Sub::Sub demolished properly"); +@demolished = (); diff --git a/t/010_basics/020-global-destruction.t b/t/010_basics/020-global-destruction.t new file mode 100644 index 0000000..f4b6877 --- /dev/null +++ b/t/010_basics/020-global-destruction.t @@ -0,0 +1,34 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 2; + +our $expected_igd = 0; +package Foo; +use Moose; + +sub DEMOLISH { + my $self = shift; + my ($igd) = @_; + ::is($igd, $::expected_igd, + "in_global_destruction state is passed to DEMOLISH properly"); +} + +package main; +{ + my $foo = Foo->new; +} +$expected_igd = 1; +# Test::Builder checks for a valid plan at END time, which is before global +# destruction, so need to test that in a subprocess +unless (fork) { + our $foo = Foo->new; + exit; +} +wait; +# but stuff that happens in a subprocess doesn't update Test::Builder's state +# in this process, so do that manually here +my $builder = Test::More->builder; +$builder->current_test($builder->current_test + 1);