calculate mro module once
[gitmo/Role-Tiny.git] / t / method-conflicts.t
CommitLineData
e75127f5 1use strict;
2use warnings;
3
4use 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;
20ok(
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
30like(
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;
37ok(
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
48is(
49 "Local::C2"->method,
50 3,
51 "... which works properly",
52);
53
54done_testing;