X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F021_attribute_errors_and_edge_cases.t;h=d00d4c3dc7128fc84f309028a08c27d1a70c1e8b;hb=8371f3de4e9525ab751008dca4a89e6df65345a6;hp=595875284f0542bf1929a37a9cacf57cfb0b0a75;hpb=d65739b4429cbd77a5400b2ac8273af504fcf3da;p=gitmo%2FClass-MOP.git diff --git a/t/021_attribute_errors_and_edge_cases.t b/t/021_attribute_errors_and_edge_cases.t index 5958752..d00d4c3 100644 --- a/t/021_attribute_errors_and_edge_cases.t +++ b/t/021_attribute_errors_and_edge_cases.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Fatal; +use Test::Exception; use Class::MOP; use Class::MOP::Attribute; @@ -10,84 +10,84 @@ use Class::MOP::Attribute; # most values are static { - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( default => qr/hello (.*)/ )); - }, '... no refs for defaults'; + } '... no refs for defaults'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( default => [] )); - }, '... no refs for defaults'; + } '... no refs for defaults'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( default => {} )); - }, '... no refs for defaults'; + } '... no refs for defaults'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( default => \(my $var) )); - }, '... no refs for defaults'; + } '... no refs for defaults'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( default => bless {} => 'Foo' )); - }, '... no refs for defaults'; + } '... no refs for defaults'; } { - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( builder => qr/hello (.*)/ )); - }, '... no refs for builders'; + } '... no refs for builders'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( builder => [] )); - }, '... no refs for builders'; + } '... no refs for builders'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( builder => {} )); - }, '... no refs for builders'; + } '... no refs for builders'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( builder => \(my $var) )); - }, '... no refs for builders'; + } '... no refs for builders'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( builder => bless {} => 'Foo' )); - }, '... no refs for builders'; + } '... no refs for builders'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( builder => 'Foo', default => 'Foo' )); - }, '... no default AND builder'; + } '... no default AND builder'; my $undef_attr; - ok ! exception { + lives_ok { $undef_attr = Class::MOP::Attribute->new('$test' => ( default => undef, predicate => 'has_test', )); - }, '... undef as a default is okay'; + } '... undef as a default is okay'; ok($undef_attr->has_default, '... and it counts as an actual default'); ok(!Class::MOP::Attribute->new('$test')->has_default, '... but attributes with no default have no default'); @@ -101,7 +101,7 @@ use Class::MOP::Attribute; ok($obj->has_test, '... and the default is populated'); is($obj->meta->get_attribute('$test')->get_value($obj), undef, '... with the right value'); } - ok ! exception { Foo->meta->make_immutable }, + lives_ok { Foo->meta->make_immutable } '... and it can be inlined'; { my $obj = Foo->new; @@ -113,33 +113,33 @@ use Class::MOP::Attribute; { # bad construtor args - ok exception { + dies_ok { Class::MOP::Attribute->new(); - }, '... no name argument'; + } '... no name argument'; # These are no longer errors - ok ! exception { + lives_ok { Class::MOP::Attribute->new(''); - }, '... bad name argument'; + } '... bad name argument'; - ok ! exception { + lives_ok { Class::MOP::Attribute->new(0); - }, '... bad name argument'; + } '... bad name argument'; } { my $attr = Class::MOP::Attribute->new('$test'); - ok exception { + dies_ok { $attr->attach_to_class(); - }, '... attach_to_class died as expected'; + } '... attach_to_class died as expected'; - ok exception { + dies_ok { $attr->attach_to_class('Fail'); - }, '... attach_to_class died as expected'; + } '... attach_to_class died as expected'; - ok exception { + dies_ok { $attr->attach_to_class(bless {} => 'Fail'); - }, '... attach_to_class died as expected'; + } '... attach_to_class died as expected'; } { @@ -149,17 +149,17 @@ use Class::MOP::Attribute; $attr->attach_to_class(Class::MOP::Class->initialize('Foo')); - ok exception { + dies_ok { $attr->install_accessors; - }, '... bad reader format'; + } '... bad reader format'; } { my $attr = Class::MOP::Attribute->new('$test'); - ok exception { + dies_ok { $attr->_process_accessors('fail', 'my_failing_sub'); - }, '... cannot find "fail" type generator'; + } '... cannot find "fail" type generator'; } @@ -174,9 +174,9 @@ use Class::MOP::Attribute; reader => 'test' )); - ok exception { + dies_ok { $attr->install_accessors; - }, '... failed to generate accessors correctly'; + } '... failed to generate accessors correctly'; } { @@ -207,27 +207,27 @@ use Class::MOP::Attribute; # it works, which is kinda silly, but it # tests the API change, so I keep it. - ok ! exception { + lives_ok { Class::MOP::Attribute->new('$foo', ( accessor => 'foo', reader => 'get_foo', )); - }, '... can create accessors with reader/writers'; + } '... can create accessors with reader/writers'; - ok ! exception { + lives_ok { Class::MOP::Attribute->new('$foo', ( accessor => 'foo', writer => 'set_foo', )); - }, '... can create accessors with reader/writers'; + } '... can create accessors with reader/writers'; - ok ! exception { + lives_ok { Class::MOP::Attribute->new('$foo', ( accessor => 'foo', reader => 'get_foo', writer => 'set_foo', )); - }, '... can create accessors with reader/writers'; + } '... can create accessors with reader/writers'; } done_testing;