Checking in changes prior to tagging of version 0.92.
[gitmo/Mouse.git] / Moose-t-failing / 050_metaclasses / 019_create_anon_with_required_attr.t
1 #!/usr/bin/perl
2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
5
6 # this functionality may be pushing toward parametric roles/classes
7 # it's off in a corner and may not be that important
8
9 use strict;
10 use warnings;
11
12 use Test::More;
13 $TODO = q{Mouse is not yet completed};
14 use Test::Exception;
15
16 {
17     package HasFoo;
18     use Mouse::Role;
19     has 'foo' => (
20         is       => 'ro',
21         isa      => 'Str',
22         required => 1,
23     );
24
25 }
26
27 {
28     package My::Metaclass;
29     use Mouse;
30     extends 'Mouse::Meta::Class';
31     with 'HasFoo';
32 }
33
34 package main;
35
36 my $anon;
37 lives_ok {
38     $anon = My::Metaclass->create_anon_class( foo => 'this' );
39 } 'create anon class with required attr';
40 isa_ok( $anon, 'My::Metaclass' );
41 cmp_ok( $anon->foo, 'eq', 'this', 'foo is this' );
42 dies_ok {
43     $anon = My::Metaclass->create_anon_class();
44 } 'failed to create anon class without required attr';
45
46 my $meta;
47 lives_ok {
48     $meta
49         = My::Metaclass->initialize( 'Class::Name1' => ( foo => 'that' ) );
50 } 'initialize a class with required attr';
51 isa_ok( $meta, 'My::Metaclass' );
52 cmp_ok( $meta->foo,  'eq', 'that',        'foo is that' );
53 cmp_ok( $meta->name, 'eq', 'Class::Name1', 'for the correct class' );
54 dies_ok {
55     $meta
56         = My::Metaclass->initialize( 'Class::Name2' );
57 } 'failed to initialize a class without required attr';
58
59 lives_ok {
60     eval qq{
61         package Class::Name3;
62         use metaclass 'My::Metaclass' => (
63             foo => 'another',
64         );
65         use Mouse;
66     };
67     die $@ if $@;
68 } 'use metaclass with required attr';
69 $meta = Class::Name3->meta;
70 isa_ok( $meta, 'My::Metaclass' );
71 cmp_ok( $meta->foo,  'eq', 'another',        'foo is another' );
72 cmp_ok( $meta->name, 'eq', 'Class::Name3', 'for the correct class' );
73 dies_ok {
74     eval qq{
75         package Class::Name4;
76         use metaclass 'My::Metaclass';
77         use Mouse;
78     };
79     die $@ if $@;
80 } 'failed to use metaclass without required attr';
81
82
83 # how do we pass a required attribute to -traits?
84 dies_ok {
85     eval qq{
86         package Class::Name5;
87         use Mouse -traits => 'HasFoo';
88     };
89     die $@ if $@;
90 } 'failed to use trait without required attr';
91
92 done_testing;