X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Frole-tiny.t;h=ebd7b8e806d9a56d1fd283fb7085ae035031cee9;hb=7b8177f835014e871d1c75016272ba320f4cd975;hp=9ef8f7379b310443661511de587109d9a8a12452;hpb=5f7ac9797529cfec418489fb405a81181465f08c;p=gitmo%2FRole-Tiny.git diff --git a/t/role-tiny.t b/t/role-tiny.t index 9ef8f73..ebd7b8e 100644 --- a/t/role-tiny.t +++ b/t/role-tiny.t @@ -19,6 +19,10 @@ BEGIN { BEGIN { package MyClass; + use constant SIMPLE => 'simple'; + use constant REF_CONST => [ 'ref_const' ]; + use constant VSTRING_CONST => v1; + sub req1 { } sub req2 { } sub foo { 'class foo' } @@ -27,6 +31,21 @@ BEGIN { } BEGIN { + package ExtraClass; + sub req1 { } + sub req2 { } + sub req3 { } + sub foo { } + sub baz { 'class baz' } +} + +BEGIN { + package IntermediaryRole; + use Role::Tiny; + requires 'req3'; +} + +BEGIN { package NoMethods; package OneMethod; @@ -36,7 +55,7 @@ BEGIN { sub try_apply_to { my $to = shift; - exception { Role::Tiny->apply_role_to_package('MyRole', $to) } + exception { Role::Tiny->apply_role_to_package($to, 'MyRole') } } is(try_apply_to('MyClass'), undef, 'role applies cleanly'); @@ -49,4 +68,15 @@ ok(!MyClass->does('Random'), 'class does not do non-role'); like(try_apply_to('NoMethods'), qr/req1, req2/, 'error for both methods'); like(try_apply_to('OneMethod'), qr/req2/, 'error for one method'); +is exception { + Role::Tiny->apply_role_to_package('IntermediaryRole', 'MyRole'); + Role::Tiny->apply_role_to_package('ExtraClass', 'IntermediaryRole'); +}, undef, 'No errors applying roles'; + +ok(ExtraClass->does('MyRole'), 'ExtraClass does MyRole'); +ok(ExtraClass->does('IntermediaryRole'), 'ExtraClass does IntermediaryRole'); +is(ExtraClass->bar, 'role bar', 'method from role'); +is(ExtraClass->baz, 'class baz', 'method from class'); + done_testing; +