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