fix typo in version
[gitmo/Role-Tiny.git] / t / role-basic-exceptions.t
1 use lib 'lib', 't/role-basic/lib';
2 use MyTests;
3 require Role::Tiny;
4
5 {
6     package My::Does::Basic;
7
8     use Role::Tiny;
9
10     requires 'turbo_charger';
11
12     sub conflict {
13         return "My::Does::Basic::conflict";
14     }
15 }
16
17 eval <<'END_PACKAGE';
18 package My::Bad::Requirement;
19 use Role::Tiny::With;
20 with 'My::Does::Basic'; # requires turbo_charger
21 END_PACKAGE
22 like $@,
23 qr/missing turbo_charger/,
24   'Trying to use a role without providing required methods should fail';
25
26 {
27     {
28         package My::Conflict;
29         use Role::Tiny;
30         sub conflict {};
31     }
32     eval <<'    END_PACKAGE';
33     package My::Bad::MethodConflicts;
34     use Role::Tiny::With;
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;
47         use Role::Tiny;
48         requires 'missing_method';
49         sub method1 { 'method1' }
50     }
51     {
52         package Role2;
53         use Role::Tiny;
54         with 'Role1';
55         sub method2 { 'method2' }
56     }
57     eval <<"    END";
58     package My::Class::Missing1;
59     use Role::Tiny::With;
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;
69         use Role::Tiny;
70         requires qw(this that);
71     }
72     eval <<"    END";
73     package My::Class::Missing2;
74     use Role::Tiny::With;
75     with 'Role3';
76     END
77     like $@,
78     qr/missing this, that/,
79       'Roles should be able to require multiple methods';
80 }
81
82 done_testing;