show the first line here when testing with a harness
[gitmo/Moose.git] / t / attributes / default_class_role_types.t
CommitLineData
340ad0aa 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5use Test::Fatal;
6
7use Moose::Util::TypeConstraints;
8
9{
10 package Foo;
11 use Moose;
12
13 has unknown_class => (
14 is => 'ro',
15 isa => 'UnknownClass',
16 );
17
18 has unknown_role => (
19 is => 'ro',
20 does => 'UnknownRole',
21 );
22}
23
24{
25 my $meta = Foo->meta;
26
27 my $class_tc = $meta->get_attribute('unknown_class')->type_constraint;
28 isa_ok($class_tc, 'Moose::Meta::TypeConstraint::Class');
29 is($class_tc, find_type_constraint('UnknownClass'),
30 "class type is registered");
31 like(
32 exception { subtype 'UnknownClass', as 'Str'; },
33 qr/The type constraint 'UnknownClass' has already been created in Foo and cannot be created again in main/,
34 "Can't redefine implicitly defined class types"
35 );
36
37 my $role_tc = $meta->get_attribute('unknown_role')->type_constraint;
38 isa_ok($role_tc, 'Moose::Meta::TypeConstraint::Role');
39 is($role_tc, find_type_constraint('UnknownRole'),
40 "role type is registered");
41 like(
42 exception { subtype 'UnknownRole', as 'Str'; },
43 qr/The type constraint 'UnknownRole' has already been created in Foo and cannot be created again in main/,
44 "Can't redefine implicitly defined class types"
45 );
46}
47
48done_testing;