X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F030_roles%2F004_role_composition_errors.t;h=b2c58f42e5ab221afe788b9c1e32ccb2be521f39;hb=948cd1899aaa1b6e1d53b77346c609f332c3e1a3;hp=d47eab39bc66f05aa289f85eb5f94ad60259d22e;hpb=4c035b8208b5286b81e4ee3be730b10c56df92d2;p=gitmo%2FMoose.git diff --git a/t/030_roles/004_role_composition_errors.t b/t/030_roles/004_role_composition_errors.t index d47eab3..b2c58f4 100644 --- a/t/030_roles/004_role_composition_errors.t +++ b/t/030_roles/004_role_composition_errors.t @@ -3,11 +3,10 @@ use strict; use warnings; -use Test::More tests => 10; +use Test::More; use Test::Exception; - { package Foo::Role; @@ -28,7 +27,7 @@ is_deeply( package Foo::Class; use Moose; - ::dies_ok{ with('Foo::Role') } + ::dies_ok { with('Foo::Role') } '... no foo method implemented by Foo::Class'; } @@ -38,9 +37,9 @@ is_deeply( package Bar::Class; use Moose; - ::dies_ok{ with('Foo::Class') } + ::dies_ok { with('Foo::Class') } '... cannot consume a class, it must be a role'; - ::lives_ok{ with('Foo::Role') } + ::lives_ok { with('Foo::Role') } '... has a foo method implemented by Bar::Class'; sub foo {'Bar::Class::foo'} @@ -52,7 +51,7 @@ is_deeply( package Bar::Role; use Moose::Role; - ::lives_ok{ with('Foo::Role') } + ::lives_ok { with('Foo::Role') } '... has a foo method implemented by Bar::Role'; sub foo {'Bar::Role::foo'} @@ -70,7 +69,7 @@ is_deeply( package Baz::Role; use Moose::Role; - ::lives_ok{ with('Foo::Role') } + ::lives_ok { with('Foo::Role') } '... no foo method implemented by Baz::Role'; } @@ -86,7 +85,7 @@ is_deeply( package Baz::Class; use Moose; - ::dies_ok{ with('Baz::Role') } + ::dies_ok { with('Baz::Role') } '... no foo method implemented by Baz::Class2'; } @@ -96,9 +95,64 @@ is_deeply( package Baz::Class2; use Moose; - ::lives_ok{ with('Baz::Role') } + ::lives_ok { with('Baz::Role') } '... has a foo method implemented by Baz::Class2'; sub foo {'Baz::Class2::foo'} } + +{ + package Quux::Role; + use Moose::Role; + + requires qw( meth1 meth2 meth3 meth4 ); +} + +# RT #41119 +{ + + package Quux::Class; + use Moose; + + ::throws_ok { with('Quux::Role') } + qr/\Q'Quux::Role' requires the methods 'meth1', 'meth2', 'meth3', and 'meth4' to be implemented by 'Quux::Class'/, + 'exception mentions all the missing required methods at once'; +} + +{ + package Quux::Class2; + use Moose; + + sub meth1 { } + + ::throws_ok { with('Quux::Role') } + qr/'Quux::Role' requires the methods 'meth2', 'meth3', and 'meth4' to be implemented by 'Quux::Class2'/, + 'exception mentions all the missing required methods at once, but not the one that exists'; +} + +{ + package Quux::Class3; + use Moose; + + has 'meth1' => ( is => 'ro' ); + has 'meth2' => ( is => 'ro' ); + + ::throws_ok { with('Quux::Role') } + qr/'Quux::Role' requires the methods 'meth3' and 'meth4' to be implemented by 'Quux::Class3'/, + 'exception mentions all the missing methods at once, but not the accessors'; +} + +{ + package Quux::Class4; + use Moose; + + sub meth1 { } + has 'meth2' => ( is => 'ro' ); + + ::throws_ok { with('Quux::Role') } + qr/'Quux::Role' requires the methods 'meth3' and 'meth4' to be implemented by 'Quux::Class4'/, + 'exception mentions all the require methods that are accessors at once, as well as missing methods, but not the one that exists'; +} + +done_testing;