Commit | Line | Data |
ceabcbb7 |
1 | #!/usr/bin/env perl |
2 | |
3 | use lib 'lib', 't/role-basic/lib'; |
4 | use MyTests; |
2c580674 |
5 | require Role::Tiny; |
ceabcbb7 |
6 | |
7 | { |
8 | package My::Does::Basic; |
9 | |
2c580674 |
10 | use Role::Tiny; |
ceabcbb7 |
11 | |
12 | requires 'turbo_charger'; |
13 | |
14 | sub conflict { |
15 | return "My::Does::Basic::conflict"; |
16 | } |
17 | } |
18 | |
19 | eval <<'END_PACKAGE'; |
ceabcbb7 |
20 | package My::Bad::Requirement; |
2c580674 |
21 | use Role::Tiny::With; |
ceabcbb7 |
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; |
2c580674 |
31 | use Role::Tiny; |
ceabcbb7 |
32 | sub conflict {}; |
33 | } |
34 | eval <<' END_PACKAGE'; |
35 | package My::Bad::MethodConflicts; |
2c580674 |
36 | use Role::Tiny::With; |
ceabcbb7 |
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; |
2c580674 |
49 | use Role::Tiny; |
ceabcbb7 |
50 | requires 'missing_method'; |
51 | sub method1 { 'method1' } |
52 | } |
53 | { |
54 | package Role2; |
2c580674 |
55 | use Role::Tiny; |
ceabcbb7 |
56 | with 'Role1'; |
57 | sub method2 { 'method2' } |
58 | } |
59 | eval <<" END"; |
60 | package My::Class::Missing1; |
2c580674 |
61 | use Role::Tiny::With; |
ceabcbb7 |
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; |
2c580674 |
71 | use Role::Tiny; |
ceabcbb7 |
72 | requires qw(this that); |
73 | } |
74 | eval <<" END"; |
75 | package My::Class::Missing2; |
2c580674 |
76 | use Role::Tiny::With; |
ceabcbb7 |
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; |