X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Frole-tiny.t;h=f93cc787a04dc89ed918d5cacbaa788fab025772;hb=fe2e95b162dca1f93c04e38d5a4d2a5cbed8e1ab;hp=69ee7ef8a20f9b8e050405bc2e146d670821e73d;hpb=c4fd8838d160a75dd495ed357ca50bfc4aedfd70;p=gitmo%2FRole-Tiny.git diff --git a/t/role-tiny.t b/t/role-tiny.t index 69ee7ef..f93cc78 100644 --- a/t/role-tiny.t +++ b/t/role-tiny.t @@ -1,4 +1,5 @@ -use strictures 1; +use strict; +use warnings FATAL => 'all'; use Test::More; use Test::Fatal; @@ -9,8 +10,6 @@ BEGIN { requires qw(req1 req2); - around foo => sub { my $orig = shift; join ' ', 'role foo', $orig->(@_) }; - sub bar { 'role bar' } sub baz { 'role baz' } @@ -19,6 +18,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' } @@ -49,16 +52,23 @@ BEGIN { sub req1 { } } +BEGIN { + package ExtraRole; + use Role::Tiny; + + sub extra1 { 'role extra' } +} + sub try_apply_to { my $to = shift; exception { Role::Tiny->apply_role_to_package($to, 'MyRole') } } is(try_apply_to('MyClass'), undef, 'role applies cleanly'); -is(MyClass->foo, 'role foo class foo', 'method modifier'); is(MyClass->bar, 'role bar', 'method from role'); is(MyClass->baz, 'class baz', 'method from class'); ok(MyClass->does('MyRole'), 'class does role'); +ok(!MyClass->does('IntermediaryRole'), 'class does not do non-applied role'); ok(!MyClass->does('Random'), 'class does not do non-role'); like(try_apply_to('NoMethods'), qr/req1, req2/, 'error for both methods'); @@ -74,5 +84,17 @@ ok(ExtraClass->does('IntermediaryRole'), 'ExtraClass does IntermediaryRole'); is(ExtraClass->bar, 'role bar', 'method from role'); is(ExtraClass->baz, 'class baz', 'method from class'); +my $new_class; +is exception { + $new_class = Role::Tiny->create_class_with_roles('MyClass', 'ExtraRole'); +}, undef, 'No errors creating class with roles'; + +isa_ok($new_class, 'MyClass'); +is($new_class->extra1, 'role extra', 'method from role'); + +ok(Role::Tiny->is_role('MyRole'), 'is_role true for roles'); +ok(!Role::Tiny->is_role('MyClass'), 'is_role false for classes'); + + done_testing;