testing for methods_provided_by
[gitmo/Role-Tiny.git] / t / concrete-methods.t
1 use strict;
2 use warnings FATAL => 'all';
3 use Test::More;
4 use Test::Fatal;
5
6 {
7   package MyRole1;
8
9   sub before_role {}
10
11   use Role::Tiny;
12   no warnings 'once';
13
14   our $GLOBAL1 = 1;
15   sub after_role {}
16 }
17
18 {
19   package MyClass1;
20   no warnings 'once';
21
22   our $GLOBAL1 = 1;
23   sub method {}
24 }
25
26 my $role_methods = Role::Tiny->_concrete_methods_of('MyRole1');
27 is_deeply([sort keys %$role_methods], ['after_role'],
28   'only subs after Role::Tiny import are methods' );
29
30 my @role_method_list = Role::Tiny->methods_provided_by('MyRole1');
31 is_deeply(\@role_method_list, ['after_role'],
32   'methods_provided_by gives method list' );
33
34 my $class_methods = Role::Tiny->_concrete_methods_of('MyClass1');
35 is_deeply([sort keys %$class_methods], ['method'],
36   'only subs from non-Role::Tiny packages are methods' );
37
38 like exception { Role::Tiny->methods_provided_by('MyClass1') },
39   qr/is not a Role::Tiny/,
40   'methods_provided_by refuses to work on classes';
41
42 done_testing;