remove unneeded shebang
[gitmo/MooseX-UndefTolerant.git] / t / roles.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use Test::Moose;
6 use Test::Fatal;
7
8 plan skip_all => "only relevant for Moose 2.0"
9     if Moose->VERSION < 1.9900;
10
11 {
12     package Foo::Role;
13     use Moose::Role;
14     use MooseX::UndefTolerant;
15
16     has foo => (
17         is        => 'ro',
18         isa       => 'Str',
19         predicate => 'has_foo',
20     );
21 }
22
23 {
24     package Foo;
25     use Moose;
26
27     with 'Foo::Role';
28 }
29
30 {
31     package Bar::Role;
32     use Moose::Role;
33 }
34
35 {
36     package Bar;
37     use Moose;
38
39     with 'Foo::Role', 'Bar::Role';
40 }
41
42 {
43     package Baz::Role;
44     use Moose::Role;
45     with 'Foo::Role';
46 }
47
48 {
49     package Baz;
50     use Moose;
51
52     with 'Baz::Role';
53 }
54
55 {
56     package Quux;
57     use Moose;
58
59     with 'Foo::Role';
60     with 'Bar::Role';
61 }
62
63 with_immutable {
64     my $foo;
65     is(exception { $foo = Foo->new(foo => undef) }, undef,
66        "can set to undef in constructor");
67     ok(!$foo->has_foo, "role attribute isn't set");
68
69     my $bar;
70     is(exception { $bar = Bar->new(foo => undef) }, undef,
71        "can set to undef in constructor");
72     ok(!$bar->has_foo, "role attribute isn't set");
73
74     my $baz;
75     is(exception { $baz = Baz->new(foo => undef) }, undef,
76        "can set to undef in constructor");
77     ok(!$baz->has_foo, "role attribute isn't set");
78
79     my $quux;
80     is(exception { $quux = Quux->new(foo => undef) }, undef,
81        "can set to undef in constructor");
82     ok(!$quux->has_foo, "role attribute isn't set");
83 } 'Foo', 'Bar', 'Baz', 'Quux';
84
85 done_testing;