X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F021-weak-ref.t;h=3f054c9610c17456e30ec0b1fc335741ba2df0d3;hb=c9313657717f78bd96f0325c6aa1c93d0b0d41a5;hp=cdafd3c2cd0da7a2e7d5c647d51ef96ce306cdaf;hpb=eab815459cfd4be951f1f44cd656e76169f7a1d6;p=gitmo%2FMouse.git diff --git a/t/021-weak-ref.t b/t/021-weak-ref.t index cdafd3c..3f054c9 100644 --- a/t/021-weak-ref.t +++ b/t/021-weak-ref.t @@ -2,16 +2,7 @@ use strict; use warnings; -use Test::More; -BEGIN { - if (eval "require Scalar::Util; 1") { - plan tests => 21; - } - else { - plan skip_all => "Scalar::Util required for this test"; - } -} - +use Test::More tests => 31; use Test::Exception; my %destroyed; @@ -35,7 +26,9 @@ do { $destroyed{ $self->type }++; } }; +}; +sub do_test{ my $self = Class->new(type => 'accessor'); $self->self($self); @@ -47,12 +40,23 @@ do { ok(Scalar::Util::isweak($object->{self}), "weak reference"); ok($object->self->self->self->self, "we've got circularity"); } -}; +} + +do_test(); is($destroyed{accessor}, 1, "destroyed from the accessor"); is($destroyed{constructor}, 1, "destroyed from the constructor"); is($destroyed{middle}, 1, "casuality of war"); +Class->meta->make_immutable(); +ok(Class->meta->is_immutable, 'make_immutable made it immutable'); +do_test(); + +is($destroyed{accessor}, 2, "destroyed from the accessor (after make_immutable)"); +is($destroyed{constructor}, 2, "destroyed from the constructor (after make_immutable)"); +is($destroyed{middle}, 2, "casuality of war (after make_immutable)"); + + ok(!Class->meta->get_attribute('type')->is_weak_ref, "type is not a weakref"); ok(Class->meta->get_attribute('self')->is_weak_ref, "self IS a weakref");