X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fdefaults.t;h=34f25cd7d53124e16ea22c4061906b5dff42dbf0;hb=d2392ff6417375a22a07e3784bcf9ac58e67578e;hp=2ae2c7695c70d155f3a6b30baf29442e228bdfde;hpb=3991a5d2d6058c15d85b028dae0c548922c38dbe;p=gitmo%2FMooseX-UndefTolerant.git diff --git a/t/defaults.t b/t/defaults.t index 2ae2c76..34f25cd 100644 --- a/t/defaults.t +++ b/t/defaults.t @@ -1,6 +1,9 @@ -#use Test::More; -use Test::Most 'die'; +use strict; +use warnings; + +use Test::More; use Test::Fatal; +use Test::Moose; use MooseX::UndefTolerant::Attribute (); @@ -59,6 +62,9 @@ package main; sub do_tests { + note 'Default behaviour: ', + (Foo->meta->is_immutable ? 'im' : '') . 'mutable classes', "\n"; + note 'Testing class with a single UndefTolerant attribute'; do_tests_with_class('Foo'); @@ -82,14 +88,27 @@ sub do_tests_with_class is($obj->attr3, 3, 'attr3\'s value is its default'); } - { - my $obj = $class->new(attr1 => undef, attr3 => undef); - ok($obj->has_attr1, 'UT attr1 has a value when assigned undef in constructor'); - ok($obj->has_attr3, 'attr3 retains its undef value when assigned undef in constructor'); - - is($obj->attr1, 1, 'attr1\'s value is its default'); - is($obj->attr2, 2, 'attr2\'s value is its default'); - is($obj->attr3, undef, 'attr3\'s value is not its default (explicitly set)'); + TODO: { + my $e = exception { + my $obj = $class->new(attr1 => undef, attr3 => undef); + { + local $TODO = 'not sure why this fails still... needs attr trait rewrite' if $obj->meta->is_immutable; + # FIXME: the object is successfully constructed, and the value + # for attr1 is properly removed, but the default is not then + # used instead... + # note "### constructed object: ", $obj->dump(2); + ok($obj->has_attr1, 'UT attr1 has a value when assigned undef in constructor'); + is($obj->attr1, 1, 'attr1\'s value is its default'); + } + ok($obj->has_attr3, 'attr3 retains its undef value when assigned undef in constructor'); + + is($obj->attr2, 2, 'attr2\'s value is its default'); + is($obj->attr3, undef, 'attr3\'s value is not its default (explicitly set)'); + }; + local $TODO = 'some immutable cases are not handled yet; see CAVEATS' + if $class->meta->is_immutable and $class eq 'Foo'; + + is($e, undef, 'these tests do not die'); } { @@ -105,22 +124,13 @@ sub do_tests_with_class } } -note 'Default behaviour: mutable classes'; -note ''; -do_tests; - -note ''; -note 'Default behaviour: immutable classes'; -note ''; -Foo->meta->make_immutable; -Bar->meta->make_immutable; +with_immutable { + do_tests; +} qw(Foo Bar); TODO: { - local $TODO = 'some immutable cases are not handled yet'; - # for now, catch errors - is (exception { do_tests }, undef, 'tests do not die'); - - is(Test::More->builder->current_test, 44, 'if we got here, we can declare victory!'); + local $TODO = 'some cases are still not handled yet; see CAVEATS'; + is(Test::More->builder->current_test, 98, 'if we got here, we can declare victory!'); } done_testing;