make this work in roles
[gitmo/MooseX-UndefTolerant.git] / t / roles.t
CommitLineData
fff0a09d 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5use Test::Moose;
6use Test::Fatal;
7
8plan 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
42with_immutable {
43 my $foo;
44 is(exception { $foo = Foo->new(foo => undef) }, undef,
45 "can set to undef in constructor");
46 ok(!$foo->has_foo, "role attribute isn't set");
47
48 my $bar;
49 is(exception { $bar = Bar->new(foo => undef) }, undef,
50 "can set to undef in constructor");
51 ok(!$bar->has_foo, "role attribute isn't set");
52} 'Foo', 'Bar';
53
54done_testing;