Fix a typo
[gitmo/Mouse.git] / Moose-t-failing / 050_metaclasses / 019_create_anon_with_required_attr.t
CommitLineData
41888e7d 1#!/usr/bin/perl
c47cf415 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
41888e7d 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
9use strict;
10use warnings;
11
c47cf415 12use Test::More;
13$TODO = q{Mouse is not yet completed};
41888e7d 14use 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
34package main;
35
36my $anon;
37lives_ok {
38 $anon = My::Metaclass->create_anon_class( foo => 'this' );
39} 'create anon class with required attr';
40isa_ok( $anon, 'My::Metaclass' );
41cmp_ok( $anon->foo, 'eq', 'this', 'foo is this' );
42dies_ok {
43 $anon = My::Metaclass->create_anon_class();
44} 'failed to create anon class without required attr';
45
46my $meta;
47lives_ok {
48 $meta
49 = My::Metaclass->initialize( 'Class::Name1' => ( foo => 'that' ) );
50} 'initialize a class with required attr';
51isa_ok( $meta, 'My::Metaclass' );
52cmp_ok( $meta->foo, 'eq', 'that', 'foo is that' );
53cmp_ok( $meta->name, 'eq', 'Class::Name1', 'for the correct class' );
54dies_ok {
55 $meta
56 = My::Metaclass->initialize( 'Class::Name2' );
57} 'failed to initialize a class without required attr';
58
59lives_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;
70isa_ok( $meta, 'My::Metaclass' );
71cmp_ok( $meta->foo, 'eq', 'another', 'foo is another' );
72cmp_ok( $meta->name, 'eq', 'Class::Name3', 'for the correct class' );
73dies_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?
84dies_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
c47cf415 92done_testing;