From: Tokuhiro Matsuno Date: Tue, 9 Jun 2009 06:18:36 +0000 (+0900) Subject: update the test code from latest moose repo X-Git-Tag: 0.24~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c2d7552a4161bdbf505e8dfbcbd53ba244c430b9;p=gitmo%2FMouse.git update the test code from latest moose repo --- diff --git a/t/030_roles/failing/005_role_conflict_detection.t b/t/030_roles/failing/005_role_conflict_detection.t index d3051a2..2faeffd 100755 --- a/t/030_roles/failing/005_role_conflict_detection.t +++ b/t/030_roles/failing/005_role_conflict_detection.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 88; # it's really 124 with kolibrie's tests; +use Test::More tests => 88; use Test::Exception; =pod @@ -17,31 +17,31 @@ Mutually recursive roles. use Mouse::Role; requires 'foo'; - + sub bar { 'Role::Foo::bar' } - + package Role::Bar; use Mouse::Role; - + requires 'bar'; - - sub foo { 'Role::Bar::foo' } + + sub foo { 'Role::Bar::foo' } } { package My::Test1; use Mouse; - + ::lives_ok { with 'Role::Foo', 'Role::Bar'; } '... our mutually recursive roles combine okay'; - + package My::Test2; use Mouse; - + ::lives_ok { with 'Role::Bar', 'Role::Foo'; - } '... our mutually recursive roles combine okay (no matter what order)'; + } '... our mutually recursive roles combine okay (no matter what order)'; } my $test1 = My::Test1->new; @@ -70,13 +70,11 @@ is($test2->bar, 'Role::Foo::bar', '... $test2->bar worked'); # check some meta-stuff -TODO: { todo_skip "Mouse: not yet implemented" => 4; ok(Role::Foo->meta->has_method('bar'), '... it still has the bar method'); ok(Role::Foo->meta->requires_method('foo'), '... it still has the required foo method'); ok(Role::Bar->meta->has_method('foo'), '... it still has the foo method'); ok(Role::Bar->meta->requires_method('bar'), '... it still has the required bar method'); -} =pod @@ -87,55 +85,53 @@ Role method conflicts { package Role::Bling; use Mouse::Role; - + sub bling { 'Role::Bling::bling' } - + package Role::Bling::Bling; use Mouse::Role; - - sub bling { 'Role::Bling::Bling::bling' } + + sub bling { 'Role::Bling::Bling::bling' } } { package My::Test3; use Mouse; - + ::throws_ok { with 'Role::Bling', 'Role::Bling::Bling'; - } qr/requires the method \'bling\' to be implemented/, '... role methods conflicted and method was required'; - + } qr/Due to a method name conflict in roles 'Role::Bling' and 'Role::Bling::Bling', the method 'bling' must be implemented or excluded by 'My::Test3'/, '... role methods conflict and method was required'; + package My::Test4; use Mouse; - + ::lives_ok { with 'Role::Bling'; with 'Role::Bling::Bling'; - } '... role methods didnt conflict when manually combined'; - + } '... role methods didnt conflict when manually combined'; + package My::Test5; use Mouse; - + ::lives_ok { with 'Role::Bling::Bling'; with 'Role::Bling'; - } '... role methods didnt conflict when manually combined (in opposite order)'; - + } '... role methods didnt conflict when manually combined (in opposite order)'; + package My::Test6; use Mouse; - + ::lives_ok { with 'Role::Bling::Bling', 'Role::Bling'; - } '... role methods didnt conflict when manually resolved'; - + } '... role methods didnt conflict when manually resolved'; + sub bling { 'My::Test6::bling' } } -TODO: { todo_skip "Mouse: not yet implemented" => 4; ok(!My::Test3->meta->has_method('bling'), '... we didnt get any methods in the conflict'); ok(My::Test4->meta->has_method('bling'), '... we did get the method when manually dealt with'); ok(My::Test5->meta->has_method('bling'), '... we did get the method when manually dealt with'); ok(My::Test6->meta->has_method('bling'), '... we did get the method when manually dealt with'); -} ok(!My::Test3->does('Role::Bling'), '... our class does() the correct roles'); ok(!My::Test3->does('Role::Bling::Bling'), '... our class does() the correct roles'); @@ -155,22 +151,19 @@ is(My::Test6->bling, 'My::Test6::bling', '... and we got the local method'); { package Role::Bling::Bling::Bling; use Mouse::Role; - + with 'Role::Bling::Bling'; - - sub bling { 'Role::Bling::Bling::Bling::bling' } + + sub bling { 'Role::Bling::Bling::Bling::bling' } } -TODO: { todo_skip "Mouse: not yet implemented" => 1; ok(Role::Bling::Bling->meta->has_method('bling'), '... still got the bling method in Role::Bling::Bling'); - } ok(Role::Bling::Bling->meta->does_role('Role::Bling::Bling'), '... our role correctly does() the other role'); -TODO: { todo_skip "Mouse: not yet implemented" => 2; ok(Role::Bling::Bling::Bling->meta->has_method('bling'), '... dont have the bling method in Role::Bling::Bling::Bling'); -is(Role::Bling::Bling::Bling->meta->get_method('bling')->(), +is(Role::Bling::Bling::Bling->meta->get_method('bling')->(), 'Role::Bling::Bling::Bling::bling', '... still got the bling method in Role::Bling::Bling::Bling'); -} + =pod @@ -181,23 +174,23 @@ Role attribute conflicts { package Role::Boo; use Mouse::Role; - + has 'ghost' => (is => 'ro', default => 'Role::Boo::ghost'); - + package Role::Boo::Hoo; use Mouse::Role; - + has 'ghost' => (is => 'ro', default => 'Role::Boo::Hoo::ghost'); } { package My::Test7; use Mouse; - + ::throws_ok { with 'Role::Boo', 'Role::Boo::Hoo'; - } qr/We have encountered an attribute conflict/, - '... role attrs conflicted and method was required'; + } qr/We have encountered an attribute conflict/, + '... role attrs conflict and method was required'; package My::Test8; use Mouse; @@ -206,24 +199,24 @@ Role attribute conflicts with 'Role::Boo'; with 'Role::Boo::Hoo'; } '... role attrs didnt conflict when manually combined'; - + package My::Test9; use Mouse; ::lives_ok { with 'Role::Boo::Hoo'; with 'Role::Boo'; - } '... role attrs didnt conflict when manually combined'; + } '... role attrs didnt conflict when manually combined'; package My::Test10; use Mouse; - - has 'ghost' => (is => 'ro', default => 'My::Test10::ghost'); - + + has 'ghost' => (is => 'ro', default => 'My::Test10::ghost'); + ::throws_ok { with 'Role::Boo', 'Role::Boo::Hoo'; - } qr/We have encountered an attribute conflict/, - '... role attrs conflicted and cannot be manually disambiguted'; + } qr/We have encountered an attribute conflict/, + '... role attrs conflict and cannot be manually disambiguted'; } @@ -258,14 +251,14 @@ Role override method conflicts { package Role::Plot; use Mouse::Role; - + override 'twist' => sub { super() . ' -> Role::Plot::twist'; }; - + package Role::Truth; use Mouse::Role; - + override 'twist' => sub { super() . ' -> Role::Truth::twist'; }; @@ -274,43 +267,43 @@ Role override method conflicts { package My::Test::Base; use Mouse; - + sub twist { 'My::Test::Base::twist' } - + package My::Test11; use Mouse; - + extends 'My::Test::Base'; ::lives_ok { with 'Role::Truth'; } '... composed the role with override okay'; - + package My::Test12; use Mouse; extends 'My::Test::Base'; - ::lives_ok { + ::lives_ok { with 'Role::Plot'; } '... composed the role with override okay'; - + package My::Test13; use Mouse; ::dies_ok { - with 'Role::Plot'; + with 'Role::Plot'; } '... cannot compose it because we have no superclass'; - + package My::Test14; use Mouse; extends 'My::Test::Base'; ::throws_ok { - with 'Role::Plot', 'Role::Truth'; - } qr/Two \'override\' methods of the same name encountered/, - '... cannot compose it because we have no superclass'; + with 'Role::Plot', 'Role::Truth'; + } qr/Two \'override\' methods of the same name encountered/, + '... cannot compose it because we have no superclass'; } ok(My::Test11->meta->has_method('twist'), '... the twist method has been added'); @@ -335,22 +328,44 @@ is(My::Test14->twist(), 'My::Test::Base::twist', '... got the right method retur package Role::Reality; use Mouse::Role; - ::throws_ok { + ::throws_ok { with 'Role::Plot'; - } qr/A local method of the same name as been found/, + } qr/A local method of the same name as been found/, '... could not compose roles here, it dies'; sub twist { 'Role::Reality::twist'; } -} +} ok(Role::Reality->meta->has_method('twist'), '... the twist method has not been added'); -ok(!Role::Reality->meta->does_role('Role::Plot'), '... our role does() the correct roles'); -is(Role::Reality->meta->get_method('twist')->(), - 'Role::Reality::twist', +#ok(!Role::Reality->meta->does_role('Role::Plot'), '... our role does() the correct roles'); +is(Role::Reality->meta->get_method('twist')->(), + 'Role::Reality::twist', '... the twist method returns the right value'); +# Ovid's test case from rt.cpan.org #44 +{ + package Role1; + use Mouse::Role; + + sub foo {} +} +{ + package Role2; + use Mouse::Role; + + sub foo {} +} +{ + package Conflicts; + use Mouse; + + ::throws_ok { + with qw(Role1 Role2); + } qr/Due to a method name conflict in roles 'Role1' and 'Role2', the method 'foo' must be implemented or excluded by 'Conflicts'/; +} + =pod Role conflicts between attributes and methods @@ -380,22 +395,22 @@ Now I have to decide actually what happens, and how to fix it. { package Role::Method; use Mouse::Role; - + sub ghost { 'Role::Method::ghost' } package Role::Method2; use Mouse::Role; - + sub ghost { 'Role::Method2::ghost' } package Role::Attribute; use Mouse::Role; - + has 'ghost' => (is => 'ro', default => 'Role::Attribute::ghost'); package Role::Attribute2; use Mouse::Role; - + has 'ghost' => (is => 'ro', default => 'Role::Attribute2::ghost'); } @@ -403,7 +418,7 @@ Now I have to decide actually what happens, and how to fix it. package My::Test15; use Mouse; - ::lives_ok { + ::lives_ok { with 'Role::Method'; } '... composed the method role into the method class'; diff --git a/t/030_roles/failing/011_overriding.t b/t/030_roles/failing/011_overriding.t index 01df0c3..89e1668 100644 --- a/t/030_roles/failing/011_overriding.t +++ b/t/030_roles/failing/011_overriding.t @@ -8,7 +8,7 @@ use Test::Exception; -{ +{ # test no conflicts here package Role::A; use Mouse::Role; @@ -22,7 +22,7 @@ use Test::Exception; package Role::C; use Mouse::Role; - + ::lives_ok { with qw(Role::A Role::B); # no conflict here } "define role C"; @@ -36,7 +36,7 @@ use Test::Exception; ::lives_ok { with qw(Role::C); } "define class A"; - + sub zot { 'Class::A::zot' } } @@ -49,30 +49,30 @@ is( Class::A->new->xxy, "Role::B::xxy", "... got the right xxy method" ); { # check that when a role is added to another role - # and they conflict and the method they conflicted - # with is then required. - + # and they conflict and the method they conflict + # with is then required. + package Role::A::Conflict; use Mouse::Role; - + with 'Role::A'; - + sub bar { 'Role::A::Conflict::bar' } - + package Class::A::Conflict; use Mouse; - + ::throws_ok { with 'Role::A::Conflict'; - } qr/requires.*'bar'/, '... did not fufill the requirement of &bar method'; - + } qr/Due to a method name conflict in roles 'Role::A' and 'Role::A::Conflict', the method 'bar' must be implemented or excluded by 'Class::A::Conflict'/, '... did not fufill the requirement of &bar method'; + package Class::A::Resolved; use Mouse; - + ::lives_ok { with 'Role::A::Conflict'; - } '... did fufill the requirement of &bar method'; - + } '... did fufill the requirement of &bar method'; + sub bar { 'Class::A::Resolved::bar' } } @@ -85,12 +85,12 @@ is( Class::A::Resolved->new->bar, 'Class::A::Resolved::bar', "... got the right { # check that when two roles are composed, they conflict # but the composing role can resolve that conflict - + package Role::D; use Mouse::Role; sub foo { 'Role::D::foo' } - sub bar { 'Role::D::bar' } + sub bar { 'Role::D::bar' } package Role::E; use Mouse::Role; @@ -104,17 +104,17 @@ is( Class::A::Resolved->new->bar, 'Class::A::Resolved::bar', "... got the right ::lives_ok { with qw(Role::D Role::E); # conflict between 'foo's here } "define role Role::F"; - + sub foo { 'Role::F::foo' } - sub zot { 'Role::F::zot' } - + sub zot { 'Role::F::zot' } + package Class::B; use Mouse; - + ::lives_ok { with qw(Role::F); } "define class Class::B"; - + sub zot { 'Class::B::zot' } } @@ -129,21 +129,21 @@ ok(!Role::F->meta->requires_method('foo'), '... Role::F fufilled the &foo requir { # check that a conflict can be resolved - # by a role, but also new ones can be + # by a role, but also new ones can be # created just as easily ... - + package Role::D::And::E::Conflict; use Mouse::Role; ::lives_ok { with qw(Role::D Role::E); # conflict between 'foo's here } "... define role Role::D::And::E::Conflict"; - + sub foo { 'Role::D::And::E::Conflict::foo' } # this overrides ... - - # but these conflict - sub xxy { 'Role::D::And::E::Conflict::xxy' } - sub bar { 'Role::D::And::E::Conflict::bar' } + + # but these conflict + sub xxy { 'Role::D::And::E::Conflict::xxy' } + sub bar { 'Role::D::And::E::Conflict::bar' } } @@ -153,12 +153,12 @@ ok(Role::D::And::E::Conflict->meta->requires_method('bar'), '... Role::D::And::E { # conflict propagation - + package Role::H; use Mouse::Role; sub foo { 'Role::H::foo' } - sub bar { 'Role::H::bar' } + sub bar { 'Role::H::bar' } package Role::J; use Mouse::Role; @@ -172,16 +172,16 @@ ok(Role::D::And::E::Conflict->meta->requires_method('bar'), '... Role::D::And::E ::lives_ok { with qw(Role::J Role::H); # conflict between 'foo's here } "define role Role::I"; - + sub zot { 'Role::I::zot' } sub zzy { 'Role::I::zzy' } package Class::C; use Mouse; - + ::throws_ok { with qw(Role::I); - } qr/requires.*'foo'/, "defining class Class::C fails"; + } qr/Due to a method name conflict in roles 'Role::H' and 'Role::J', the method 'foo' must be implemented or excluded by 'Class::C'/, "defining class Class::C fails"; sub zot { 'Class::C::zot' } @@ -190,10 +190,10 @@ ok(Role::D::And::E::Conflict->meta->requires_method('bar'), '... Role::D::And::E ::lives_ok { with qw(Role::I); - } "resolved with method"; + } "resolved with method"; sub foo { 'Class::E::foo' } - sub zot { 'Class::E::zot' } + sub zot { 'Class::E::zot' } } can_ok( Class::E->new, qw(foo bar xxy zot) ); diff --git a/t/030_roles/failing/012_method_exclusion_in_composition.t b/t/030_roles/failing/012_method_exclusion_in_composition.t index 56d8516..1ea0858 100644 --- a/t/030_roles/failing/012_method_exclusion_in_composition.t +++ b/t/030_roles/failing/012_method_exclusion_in_composition.t @@ -43,37 +43,37 @@ ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is requ { package Foo::Role; use Mouse::Role; - + sub foo { 'Foo::Role::foo' } - + package Bar::Role; use Mouse::Role; - - sub foo { 'Bar::Role::foo' } + + sub foo { 'Bar::Role::foo' } package Baz::Role; use Mouse::Role; - - sub foo { 'Baz::Role::foo' } - + + sub foo { 'Baz::Role::foo' } + package My::Foo::Class; use Mouse; - + ::lives_ok { with 'Foo::Role' => { excludes => 'foo' }, - 'Bar::Role' => { excludes => 'foo' }, + 'Bar::Role' => { excludes => 'foo' }, 'Baz::Role'; } '... composed our roles correctly'; - + package My::Foo::Class::Broken; use Mouse; - + ::throws_ok { with 'Foo::Role', - 'Bar::Role' => { excludes => 'foo' }, + 'Bar::Role' => { excludes => 'foo' }, 'Baz::Role'; - } qr/\'Foo::Role\|Bar::Role\|Baz::Role\' requires the method \'foo\' to be implemented by \'My::Foo::Class::Broken\'/, - '... composed our roles correctly'; + } qr/Due to a method name conflict in roles 'Baz::Role' and 'Foo::Role', the method 'foo' must be implemented or excluded by 'My::Foo::Class::Broken'/, + '... composed our roles correctly'; } { @@ -89,7 +89,7 @@ ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is requ ::lives_ok { with 'Foo::Role' => { excludes => 'foo' }, - 'Bar::Role' => { excludes => 'foo' }, + 'Bar::Role' => { excludes => 'foo' }, 'Baz::Role'; } '... composed our roles correctly'; } @@ -103,7 +103,7 @@ ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not ::lives_ok { with 'Foo::Role', - 'Bar::Role' => { excludes => 'foo' }, + 'Bar::Role' => { excludes => 'foo' }, 'Baz::Role'; } '... composed our roles correctly'; } diff --git a/t/030_roles/failing/013_method_aliasing_in_composition.t b/t/030_roles/failing/013_method_aliasing_in_composition.t index 2fbdbe8..bbe7d7d 100644 --- a/t/030_roles/failing/013_method_aliasing_in_composition.t +++ b/t/030_roles/failing/013_method_aliasing_in_composition.t @@ -15,7 +15,7 @@ use Test::Exception; sub foo { 'Foo::foo' } sub bar { 'Foo::bar' } sub baz { 'Foo::baz' } - + requires 'role_bar'; package My::Class; @@ -24,14 +24,14 @@ use Test::Exception; ::lives_ok { with 'My::Role' => { alias => { bar => 'role_bar' } }; } '... this succeeds'; - + package My::Class::Failure; use Mouse; ::throws_ok { with 'My::Role' => { alias => { bar => 'role_bar' } }; - } qr/Cannot create a method alias if a local method of the same name exists/, '... this succeeds'; - + } qr/Cannot create a method alias if a local method of the same name exists/, '... this succeeds'; + sub role_bar { 'FAIL' } } @@ -46,15 +46,15 @@ ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz bar ro } '... this succeeds'; sub bar { 'My::OtherRole::bar' } - + package My::OtherRole::Failure; use Mouse::Role; ::throws_ok { with 'My::Role' => { alias => { bar => 'role_bar' } }; - } qr/Cannot create a method alias if a local method of the same name exists/, '... this succeeds'; - - sub role_bar { 'FAIL' } + } qr/Cannot create a method alias if a local method of the same name exists/, '... this succeeds'; + + sub role_bar { 'FAIL' } } ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar); @@ -76,37 +76,37 @@ ok(My::AliasingRole->meta->requires_method('bar'), '... and the &bar method is r { package Foo::Role; use Mouse::Role; - + sub foo { 'Foo::Role::foo' } - + package Bar::Role; use Mouse::Role; - - sub foo { 'Bar::Role::foo' } + + sub foo { 'Bar::Role::foo' } package Baz::Role; use Mouse::Role; - - sub foo { 'Baz::Role::foo' } - + + sub foo { 'Baz::Role::foo' } + package My::Foo::Class; use Mouse; - + ::lives_ok { with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, - 'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' }, + 'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' }, 'Baz::Role'; - } '... composed our roles correctly'; - + } '... composed our roles correctly'; + package My::Foo::Class::Broken; use Mouse; - + ::throws_ok { with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, - 'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, + 'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, 'Baz::Role'; - } qr/\'Foo::Role\|Bar::Role\|Baz::Role\' requires the method \'foo_foo\' to be implemented by \'My::Foo::Class::Broken\'/, - '... composed our roles correctly'; + } qr/Due to a method name conflict in roles 'Bar::Role' and 'Foo::Role', the method 'foo_foo' must be implemented or excluded by 'My::Foo::Class::Broken'/, + '... composed our roles correctly'; } { @@ -114,8 +114,8 @@ ok(My::AliasingRole->meta->requires_method('bar'), '... and the &bar method is r isa_ok($foo, 'My::Foo::Class'); can_ok($foo, $_) for qw/foo foo_foo bar_foo/; is($foo->foo, 'Baz::Role::foo', '... got the right method'); - is($foo->foo_foo, 'Foo::Role::foo', '... got the right method'); - is($foo->bar_foo, 'Bar::Role::foo', '... got the right method'); + is($foo->foo_foo, 'Foo::Role::foo', '... got the right method'); + is($foo->bar_foo, 'Bar::Role::foo', '... got the right method'); } { @@ -124,7 +124,7 @@ ok(My::AliasingRole->meta->requires_method('bar'), '... and the &bar method is r ::lives_ok { with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, - 'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' }, + 'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' }, 'Baz::Role'; } '... composed our roles correctly'; } @@ -139,7 +139,7 @@ ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not ::lives_ok { with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, - 'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, + 'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, 'Baz::Role'; } '... composed our roles correctly'; }