From: Dave Rolsky Date: Thu, 18 Sep 2008 15:06:30 +0000 (+0000) Subject: Add some MetaRole related tests for error_class. Added a test plan. X-Git-Tag: 0.58~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1aa93ae8ad0a2e30d6f7b92574ac8c97b4385cda;p=gitmo%2FMoose.git Add some MetaRole related tests for error_class. Added a test plan. --- diff --git a/t/050_metaclasses/018_throw_error.t b/t/050_metaclasses/018_throw_error.t index 131e155..656bbce 100644 --- a/t/050_metaclasses/018_throw_error.t +++ b/t/050_metaclasses/018_throw_error.t @@ -3,7 +3,8 @@ use strict; use warnings; -use Test::More 'no_plan';; +use Test::More tests => 24; +use Test::Exception; { @@ -87,3 +88,69 @@ sub create_error { is_deeply( $e->{error}->data, [ $baz, 4 ], "captured args" ); like( $e->{error}->last_error, qr/Blah/, "last error preserved" ); } + +{ + package Role::Foo; + use Moose::Role; + + sub foo { } +} + +{ + package Baz::Sub; + + use Moose; + extends 'Baz'; + + Moose::Util::MetaRole::apply_metaclass_roles( + for_class => __PACKAGE__, + metaclass_roles => ['Role::Foo'], + ); +} + +{ + package Baz::Sub::Sub; + use metaclass ( + metaclass => 'Moose::Meta::Class', + error_class => 'Moose::Error::Croak', + ); + use Moose; + + ::dies_ok { extends 'Baz::Sub' } 'error_class is included in metaclass compatibility checks'; +} + +{ + package Foo::Sub; + + use metaclass ( + metaclass => 'Moose::Meta::Class', + error_class => 'Moose::Error::Croak', + ); + + use Moose; + + Moose::Util::MetaRole::apply_metaclass_roles( + for_class => __PACKAGE__, + metaclass_roles => ['Role::Foo'], + ); +} + +ok( Foo::Sub->meta->error_class->isa('Moose::Error::Croak'), + q{Foo::Sub's error_class still isa Moose::Error::Croak} ); + +{ + package Foo::Sub::Sub; + use Moose; + + ::lives_ok { extends 'Foo::Sub' } 'error_class differs by role so incompat is handled'; + + Moose::Util::MetaRole::apply_metaclass_roles( + for_class => __PACKAGE__, + error_class_roles => ['Role::Foo'], + ); +} + +ok( Foo::Sub::Sub->meta->error_class->meta->does_role('Role::Foo'), + q{Foo::Sub::Sub's error_class does Role::Foo} ); +ok( Foo::Sub::Sub->meta->error_class->isa('Moose::Error::Croak'), + q{Foo::Sub::Sub's error_class now subclasses Moose::Error::Croak} );