update repo to point to github
[gitmo/Moo.git] / xt / moo-roles-into-moose-class.t
1 use strict;
2 use warnings;
3 use Test::More;
4 use Test::Fatal;
5
6 {
7     package Foo;
8     use Moo::Role;
9     # if we autoclean here there's nothing left and then load_class tries
10     # to require Foo during Moose application and everything breaks.
11 }
12 {
13     package Bar;
14     use Moo::Role;
15     use namespace::autoclean;
16
17     has attr => (
18         is => 'ro'
19     );
20
21     sub thing {}
22 }
23 {
24     package Baz;
25     use Moose;
26     no Moose;
27
28     ::ok(!__PACKAGE__->can('has'), 'No has function after no Moose;');
29     Moose::with('Baz', 'Bar');
30 }
31
32 ::is(Baz->can('thing'), Bar->can('thing'), 'Role copies method correctly');
33 ::ok(Baz->can('attr'), 'Attr accessor correct');
34 ::ok(!Bar->can('has'), 'Moo::Role sugar removed by autoclean');
35 ::ok(!Bar->can('with'), 'Role::Tiny sugar removed by autoclean');
36 ::ok(!Baz->can('has'), 'Sugar not copied');
37
38 {
39     package Bax;
40     use Moose;
41     with qw/
42         Foo
43         Bar
44     /;
45 }
46
47 {
48     package Baw;
49     use Moo::Role;
50     has attr => (
51         is => 'ro',
52         traits => ['Array'],
53         default => sub { [] },
54         handles => {
55             push_attr => 'push',
56         },
57     );
58 }
59 {
60     package Buh;
61     use Moose;
62     with 'Baw';
63 }
64
65 is exception {
66   Buh->new->push_attr(1);
67 }, undef, 'traits in role attributes are inflated properly';
68
69 done_testing;
70