Commit | Line | Data |
e75127f5 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | |
6 | { |
7 | package Local::R1; |
8 | use Role::Tiny; |
9 | sub method { 1 }; |
10 | } |
11 | |
12 | { |
13 | package Local::R2; |
14 | use Role::Tiny; |
15 | sub method { 2 }; |
16 | } |
17 | |
18 | # Need to use stringy eval, so not Test::Fatal |
19 | $@ = undef; |
20 | ok( |
21 | !eval(q{ |
22 | package Local::C1; |
23 | use Role::Tiny::With; |
24 | with qw(Local::R1 Local::R2); |
25 | 1; |
26 | }), |
27 | 'method conflict dies', |
28 | ); |
29 | |
30 | like( |
31 | $@, |
32 | qr{^Due to a method name conflict between roles 'Local::R. and Local::R.', the method 'method' must be implemented by 'Local::C1'}, |
33 | '... with correct error message', |
34 | ); |
35 | |
36 | $@ = undef; |
37 | ok( |
38 | eval(q{ |
39 | package Local::C2; |
40 | use Role::Tiny::With; |
41 | with qw(Local::R1 Local::R2); |
42 | sub method { 3 }; |
43 | 1; |
44 | }), |
45 | '... but can be resolved', |
46 | ); |
47 | |
48 | is( |
49 | "Local::C2"->method, |
50 | 3, |
51 | "... which works properly", |
52 | ); |
53 | |
54 | done_testing; |