Changelogging
[gitmo/Mouse.git] / t-failing / 030_roles / 006_role_exclusion.t
1 #!/usr/bin/perl
2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
5
6 use strict;
7 use warnings;
8
9 use Test::More;
10 $TODO = q{Mouse is not yet completed};
11 use Test::Exception;
12
13 =pod
14
15 The idea and examples for this feature are taken
16 from the Fortress spec.
17
18 http://research.sun.com/projects/plrg/fortress0903.pdf
19
20 trait OrganicMolecule extends Molecule
21     excludes { InorganicMolecule }
22 end
23 trait InorganicMolecule extends Molecule end
24
25 =cut
26
27 {
28     package Molecule;
29     use Mouse::Role;
30
31     package Molecule::Organic;
32     use Mouse::Role;
33
34     with 'Molecule';
35     excludes 'Molecule::Inorganic';
36
37     package Molecule::Inorganic;
38     use Mouse::Role;
39
40     with 'Molecule';
41 }
42
43 ok(Molecule::Organic->meta->excludes_role('Molecule::Inorganic'), '... Molecule::Organic exludes Molecule::Inorganic');
44 is_deeply(
45    [ Molecule::Organic->meta->get_excluded_roles_list() ],
46    [ 'Molecule::Inorganic' ],
47    '... Molecule::Organic exludes Molecule::Inorganic');
48
49 =pod
50
51 Check some basic conflicts when combining
52 the roles into the same class
53
54 =cut
55
56 {
57     package My::Test1;
58     use Mouse;
59
60     ::lives_ok {
61         with 'Molecule::Organic';
62     } '... adding the role (w/ excluded roles) okay';
63
64     package My::Test2;
65     use Mouse;
66
67     ::throws_ok {
68         with 'Molecule::Organic', 'Molecule::Inorganic';
69     } qr/Conflict detected: Role Molecule::Organic excludes role 'Molecule::Inorganic'/,
70     '... adding the role w/ excluded role conflict dies okay';
71
72     package My::Test3;
73     use Mouse;
74
75     ::lives_ok {
76         with 'Molecule::Organic';
77     } '... adding the role (w/ excluded roles) okay';
78
79     ::throws_ok {
80         with 'Molecule::Inorganic';
81     } qr/Conflict detected: My::Test3 excludes role 'Molecule::Inorganic'/,
82     '... adding the role w/ excluded role conflict dies okay';
83 }
84
85 ok(My::Test1->does('Molecule::Organic'), '... My::Test1 does Molecule::Organic');
86 ok(My::Test1->does('Molecule'), '... My::Test1 does Molecule');
87 ok(My::Test1->meta->excludes_role('Molecule::Inorganic'), '... My::Test1 excludes Molecule::Organic');
88
89 ok(!My::Test2->does('Molecule::Organic'), '... ! My::Test2 does Molecule::Organic');
90 ok(!My::Test2->does('Molecule::Inorganic'), '... ! My::Test2 does Molecule::Inorganic');
91
92 ok(My::Test3->does('Molecule::Organic'), '... My::Test3 does Molecule::Organic');
93 ok(My::Test3->does('Molecule'), '... My::Test1 does Molecule');
94 ok(My::Test3->meta->excludes_role('Molecule::Inorganic'), '... My::Test3 excludes Molecule::Organic');
95 ok(!My::Test3->does('Molecule::Inorganic'), '... ! My::Test3 does Molecule::Inorganic');
96
97 =pod
98
99 Check some basic conflicts when combining
100 the roles into the a superclass
101
102 =cut
103
104 {
105     package Methane;
106     use Mouse;
107
108     with 'Molecule::Organic';
109
110     package My::Test4;
111     use Mouse;
112
113     extends 'Methane';
114
115     ::throws_ok {
116         with 'Molecule::Inorganic';
117     } qr/Conflict detected: My::Test4 excludes role \'Molecule::Inorganic\'/,
118     '... cannot add exculded role into class which extends Methane';
119 }
120
121 ok(Methane->does('Molecule::Organic'), '... Methane does Molecule::Organic');
122 ok(My::Test4->isa('Methane'), '... My::Test4 isa Methane');
123 ok(My::Test4->does('Molecule::Organic'), '... My::Test4 does Molecule::Organic');
124 ok(My::Test4->meta->does_role('Molecule::Organic'), '... My::Test4 meat does_role Molecule::Organic');
125 ok(My::Test4->meta->excludes_role('Molecule::Inorganic'), '... My::Test4 meta excludes Molecule::Organic');
126 ok(!My::Test4->does('Molecule::Inorganic'), '... My::Test4 does Molecule::Inorganic');
127
128 done_testing;