File: role-basic-exceptions.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 (84 lines) | stat: -rw-r--r-- 1,666 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use strict;
use warnings FATAL => 'all';
use lib 't/role-basic/lib';
use Test::More;
require Role::Tiny;

{
    package My::Does::Basic;

    use Role::Tiny;

    requires 'turbo_charger';

    sub conflict {
        return "My::Does::Basic::conflict";
    }
}

eval <<'END_PACKAGE';
package My::Bad::Requirement;
use Role::Tiny::With;
with 'My::Does::Basic'; # requires turbo_charger
END_PACKAGE
like $@,
qr/missing turbo_charger/,
  'Trying to use a role without providing required methods should fail';

{
    {
        package My::Conflict;
        use Role::Tiny;
        sub conflict {};
    }
    eval <<'    END_PACKAGE';
    package My::Bad::MethodConflicts;
    use Role::Tiny::With;
    with qw(My::Does::Basic My::Conflict);
    sub turbo_charger {}
    END_PACKAGE
    like $@,
    qr/.*/,
      'Trying to use multiple roles with the same method should fail';
}


{
    {
        package Role1;
        use Role::Tiny;
        requires 'missing_method';
        sub method1 { 'method1' }
    }
    {
        package Role2;
        use Role::Tiny;
        with 'Role1';
        sub method2 { 'method2' }
    }
    eval <<"    END";
    package My::Class::Missing1;
    use Role::Tiny::With;
    with 'Role2';
    END
    like $@,
    qr/missing missing_method/,
      'Roles composed from roles should propogate requirements upwards';
}
{
    {
        package Role3;
        use Role::Tiny;
        requires qw(this that);
    }
    eval <<"    END";
    package My::Class::Missing2;
    use Role::Tiny::With;
    with 'Role3';
    END
    like $@,
    qr/missing this, that/,
      'Roles should be able to require multiple methods';
}

done_testing;