X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F004_w_cycles.t;h=6dd816e0c6caaaa741cf38e799ef022d3cbed93c;hb=9d3c60f5f35a8d28951049e8daccd9f67c22f9aa;hp=3cb3a0b16f7b6b17968bf78e5ee172fc9146b727;hpb=b430caa3fe1898fd40d743f5ff1347b7df9671f2;p=gitmo%2FMooseX-Storage.git diff --git a/t/004_w_cycles.t b/t/004_w_cycles.t index 3cb3a0b..6dd816e 100644 --- a/t/004_w_cycles.t +++ b/t/004_w_cycles.t @@ -3,8 +3,8 @@ use strict; use warnings; -use Test::More no_plan => 1; -use Test::Exception; +use Test::More tests => 18; +use Test::Fatal; BEGIN { use_ok('MooseX::Storage'); @@ -37,20 +37,20 @@ This test demonstrates two things: $circular->cycle($circular); - throws_ok { + like(exception { $circular->pack; - } qr/^Basic Engine does not support cycles/, - '... cannot collapse a cycle with the basic engine'; + }, qr/^Basic Engine does not support cycles/, + '... cannot collapse a cycle with the basic engine'); } { my $packed_circular = { __CLASS__ => 'Circular' }; $packed_circular->{cycle} = $packed_circular; - throws_ok { + like( exception { Circular->unpack($packed_circular); - } qr/^Basic Engine does not support cycles/, - '... cannot expand a cycle with the basic engine'; + }, qr/^Basic Engine does not support cycles/, + '... cannot expand a cycle with the basic engine'); } { @@ -70,7 +70,7 @@ This test demonstrates two things: ); has 'parent' => ( - metaclass => 'MooseX::Storage::Meta::Attribute::DoNotSerialize', + metaclass => 'DoNotSerialize', is => 'rw', isa => 'Tree', ); @@ -130,4 +130,54 @@ This test demonstrates two things: '... got the right packed version (with parent attribute skipped)'); } +### this fails with cycle detection on +{ package Double; + use Moose; + use MooseX::Storage; + with Storage; + + has 'x' => ( is => 'rw', isa => 'HashRef' ); + has 'y' => ( is => 'rw', isa => 'HashRef' ); +} + +{ my $ref = {}; + + my $double = Double->new( 'x' => $ref, 'y' => $ref ); + + ### currently, the cycle checker's too naive to figure out this is not + ### a problem, pass an empty hashref to the 2nd test to make sure it + ### doesn't warn/die + TODO: { + local $TODO = "Cycle check is too naive"; + my $pack = eval { $double->pack; }; + ok( $pack, "Object with 2 references packed" ); + ok( Double->unpack( $pack || {} ), + " And unpacked again" ); + } + + my $pack = $double->pack( engine_traits => [qw/DisableCycleDetection/] ); + ok( $pack, " Object packs when cycle check is disabled"); + ok( Double->unpack( $pack ), + " And unpacked again" ); + +} + +### the same as above, but now done with a trait +### this fails with cycle detection on +{ package DoubleNoCycle; + use Moose; + use MooseX::Storage; + with Storage( traits => ['DisableCycleDetection'] ); + + has 'x' => ( is => 'rw', isa => 'HashRef' ); + has 'y' => ( is => 'rw', isa => 'HashRef' ); +} + +{ my $ref = {}; + my $double = DoubleNoCycle->new( 'x' => $ref, 'y' => $ref ); + my $pack = $double->pack; + ok( $pack, "Object packs with DisableCycleDetection trait"); + ok( DoubleNoCycle->unpack( $pack ), + " Unpacked again" ); +}