More tests for Hash trait to ensure we test all code gen paths
[gitmo/Moose.git] / t / 010_basics / 013_create.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Exception;
8
9 {
10     package Class;
11     use Moose;
12
13     package Foo;
14     use Moose::Role;
15     sub foo_role_applied { 1 }
16
17     package Conflicts::With::Foo;
18     use Moose::Role;
19     sub foo_role_applied { 0 }
20
21     package Not::A::Role;
22     sub lol_wut { 42 }
23 }
24
25 my $new_class;
26
27 lives_ok {
28     $new_class = Moose::Meta::Class->create(
29         'Class::WithFoo',
30         superclasses => ['Class'],
31         roles        => ['Foo'],
32     );
33 } 'creating lives';
34 ok $new_class;
35
36 my $with_foo = Class::WithFoo->new;
37
38 ok $with_foo->foo_role_applied;
39 isa_ok $with_foo, 'Class', '$with_foo';
40
41 throws_ok {
42     Moose::Meta::Class->create(
43         'Made::Of::Fail',
44         superclasses => ['Class'],
45         roles => 'Foo', # "oops"
46     );
47 } qr/You must pass an ARRAY ref of roles/;
48
49 ok !Made::Of::Fail->isa('UNIVERSAL'), "did not create Made::Of::Fail";
50
51 dies_ok {
52     Moose::Meta::Class->create(
53         'Continuing::To::Fail',
54         superclasses => ['Class'],
55         roles        => ['Foo', 'Conflicts::With::Foo'],
56     );
57 } 'conflicting roles == death';
58
59 # XXX: Continuing::To::Fail gets created anyway
60
61 done_testing;