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