calculate mro module once
[gitmo/Role-Tiny.git] / t / role-basic-exceptions.t
CommitLineData
ceabcbb7 1use lib 'lib', 't/role-basic/lib';
2use MyTests;
2c580674 3require Role::Tiny;
ceabcbb7 4
5{
6 package My::Does::Basic;
7
2c580674 8 use Role::Tiny;
ceabcbb7 9
10 requires 'turbo_charger';
11
12 sub conflict {
13 return "My::Does::Basic::conflict";
14 }
15}
16
17eval <<'END_PACKAGE';
ceabcbb7 18package My::Bad::Requirement;
2c580674 19use Role::Tiny::With;
ceabcbb7 20with 'My::Does::Basic'; # requires turbo_charger
21END_PACKAGE
22like $@,
23qr/missing turbo_charger/,
24 'Trying to use a role without providing required methods should fail';
25
26{
27 {
28 package My::Conflict;
2c580674 29 use Role::Tiny;
ceabcbb7 30 sub conflict {};
31 }
32 eval <<' END_PACKAGE';
33 package My::Bad::MethodConflicts;
2c580674 34 use Role::Tiny::With;
ceabcbb7 35 with qw(My::Does::Basic My::Conflict);
36 sub turbo_charger {}
37 END_PACKAGE
38 like $@,
39 qr/.*/,
40 'Trying to use multiple roles with the same method should fail';
41}
42
43
44{
45 {
46 package Role1;
2c580674 47 use Role::Tiny;
ceabcbb7 48 requires 'missing_method';
49 sub method1 { 'method1' }
50 }
51 {
52 package Role2;
2c580674 53 use Role::Tiny;
ceabcbb7 54 with 'Role1';
55 sub method2 { 'method2' }
56 }
57 eval <<" END";
58 package My::Class::Missing1;
2c580674 59 use Role::Tiny::With;
ceabcbb7 60 with 'Role2';
61 END
62 like $@,
63 qr/missing missing_method/,
64 'Roles composed from roles should propogate requirements upwards';
65}
66{
67 {
68 package Role3;
2c580674 69 use Role::Tiny;
ceabcbb7 70 requires qw(this that);
71 }
72 eval <<" END";
73 package My::Class::Missing2;
2c580674 74 use Role::Tiny::With;
ceabcbb7 75 with 'Role3';
76 END
77 like $@,
78 qr/missing this, that/,
79 'Roles should be able to require multiple methods';
80}
81
82done_testing;