From: Dave Rolsky Date: Fri, 6 Jan 2012 20:59:07 +0000 (-0600) Subject: Test (that fails) for an edge case in role composition X-Git-Tag: 2.0500~108 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cd96b99819007e8605a5f808ef587e78f93a88f5;p=gitmo%2FMoose.git Test (that fails) for an edge case in role composition When composing three roles, it is possible for the composite to end up with both a conflict on a method and a method of that name. In most practical applications, this doesn't really matter, since the conflict causes an exception that must be resolved by the consumer. However, it means that the composite reports bogus information when has_method or get_method() is called. --- diff --git a/t/roles/role_composition_conflict_detection.t b/t/roles/role_composition_conflict_detection.t new file mode 100644 index 0000000..a9d8f41 --- /dev/null +++ b/t/roles/role_composition_conflict_detection.t @@ -0,0 +1,46 @@ +use strict; +use warnings; + +use Test::More; +use Test::Fatal; + +use Moose::Util qw( find_meta ); + +{ + package RoleA; + use Moose::Role; + + sub foo { 42 } +} + +{ + package RoleB; + use Moose::Role; + + with 'RoleA'; +} + +{ + package RoleC; + use Moose::Role; + + sub foo { 84 } +} + +{ + my $composite + = Moose::Meta::Role->combine( map { [ find_meta($_) => {} ] } + qw( RoleA RoleB RoleC ) ); + ok( $composite->requires_method('foo'), 'Composite of [ABC] requires a foo method' ); + ok( ! $composite->has_method('foo'), 'Composite of [ABC] does not also have a foo method' ); +} + +{ + my $composite + = Moose::Meta::Role->combine( map { [ find_meta($_) => {} ] } + qw( RoleA RoleC RoleB ) ); + ok( $composite->requires_method('foo'), 'Composite of [ACB] requires a foo method' ); + ok( ! $composite->has_method('foo'), 'Composite of [ACB] does not also have a foo method' ); +} + +done_testing;