From: Stevan Little Date: Thu, 13 Apr 2006 20:50:58 +0000 (+0000) Subject: error_tests X-Git-Tag: 0_05~35 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e46edf94befc235dbaac9636cb98bfa0d817751f;p=gitmo%2FMoose.git error_tests --- diff --git a/lib/Moose/Role.pm b/lib/Moose/Role.pm index afd0a4c..ecc016f 100644 --- a/lib/Moose/Role.pm +++ b/lib/Moose/Role.pm @@ -109,7 +109,7 @@ Moose::Role - The Moose Role use warnings; use Moose::Role; - sub equal { confess "equal must be implemented" } + requires 'equal'; sub no_equal { my ($self, $other) = @_; @@ -150,24 +150,12 @@ Currently, the role support has a number of caveats. They are as follows: =item * -There is no support for Roles consuming other Roles. The details of this -are not totally worked out yet, but it will mostly follow what is set out -in the Perl 6 Synopsis 12. - -=item * - At this time classes I consume more than one Role, but they are simply applied one after another in the order you ask for them. This is incorrect behavior, the roles should be merged first, and conflicts determined, etc. However, if your roles do not have any conflicts, then things will work just fine. -=item * - -I want to have B methods, which is unlike Perl 6 roles, and more -like the original Traits on which roles are based. This would be similar -in behavior to L. These are not yet implemented or course. - =item * Roles cannot use the C keyword, it will throw an exception for now. diff --git a/t/007_basic.t b/t/007_basic.t index 90c5ceb..bcafd6b 100644 --- a/t/007_basic.t +++ b/t/007_basic.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 54; +use Test::More tests => 52; use Test::Exception; BEGIN { @@ -161,15 +161,3 @@ foreach my $method_name (qw( )) { ok($currency_meta->has_method($method_name), '... US::Currency has_method ' . $method_name); } - -# check some errors - -{ - package Foo; - use strict; - use warnings; - use Moose; - ::dies_ok { with('Eq') } '... no equal_to method implemented by Foo'; - ::dies_ok { with('Ord') } '... no compare method implemented by Foo'; -} - diff --git a/t/043_role_composition_errors.t b/t/043_role_composition_errors.t new file mode 100644 index 0000000..09569f9 --- /dev/null +++ b/t/043_role_composition_errors.t @@ -0,0 +1,65 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 5; +use Test::Exception; + +BEGIN { + use_ok('Moose'); +} + +{ + package Foo::Role; + use strict; + use warnings; + use Moose::Role; + + requires 'foo'; +} + +# classes which does not implement required method +{ + package Foo::Class; + use strict; + use warnings; + use Moose; + + ::dies_ok { with('Foo::Role') } '... no foo method implemented by Foo::Class'; +} + +# class which does implement required method +{ + package Bar::Class; + use strict; + use warnings; + use Moose; + + ::lives_ok { with('Foo::Role') } '... has a foo method implemented by Bar::Class'; + + sub foo { 'Bar::Class::foo' } +} + +# role which does implement required method +{ + package Bar::Role; + use strict; + use warnings; + use Moose::Role; + + ::lives_ok { with('Foo::Role') } '... has a foo method implemented by Bar::Role'; + + sub foo { 'Bar::Role::foo' } +} + +# role which does not implement required method +{ + package Baz::Role; + use strict; + use warnings; + use Moose; + + ::dies_ok { with('Foo::Role') } '... no foo method implemented by Baz::Role'; +} +