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