File: method-conflicts.t

package info (click to toggle)
librole-tiny-perl 1.003004-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 236 kB
  • ctags: 43
  • sloc: perl: 400; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 902 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use strict;
use warnings FATAL => 'all';

use Test::More;

{
    package Local::R1;
    use Role::Tiny;
    sub method { 1 };
}

{
    package Local::R2;
    use Role::Tiny;
    sub method { 2 };
}

# Need to use stringy eval, so not Test::Fatal
$@ = undef;
ok(
    !eval(q{
        package Local::C1;
        use Role::Tiny::With;
        with qw(Local::R1 Local::R2);
        1;
    }),
    'method conflict dies',
);

like(
    $@,
    qr{^Due to a method name conflict between roles 'Local::R. and Local::R.', the method 'method' must be implemented by 'Local::C1'},
    '... with correct error message',
);

$@ = undef;
ok(
    eval(q{
        package Local::C2;
        use Role::Tiny::With;
        with qw(Local::R1 Local::R2);
        sub method { 3 };
        1;
    }),
    '... but can be resolved',
);

is(
    "Local::C2"->method,
    3,
    "... which works properly",
);

done_testing;