From: Todd Hepler Date: Fri, 5 Dec 2008 22:36:27 +0000 (+0000) Subject: more tests for metaclass traits with required attributes X-Git-Tag: 0.63~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6b48e9a339d5c4f98cf8f0ac081970de9100c1c8;p=gitmo%2FMoose.git more tests for metaclass traits with required attributes --- diff --git a/t/050_metaclasses/019_create_anon_with_required_attr.t b/t/050_metaclasses/019_create_anon_with_required_attr.t index 37e340c..5603e1a 100644 --- a/t/050_metaclasses/019_create_anon_with_required_attr.t +++ b/t/050_metaclasses/019_create_anon_with_required_attr.t @@ -1,9 +1,12 @@ #!/usr/bin/perl +# this functionality may be pushing toward parametric roles/classes +# it's off in a corner and may not be that important + use strict; use warnings; -use Test::More tests => 3; +use Test::More tests => 15; use Test::Exception; { @@ -29,7 +32,56 @@ package main; my $anon; lives_ok { $anon = My::Metaclass->create_anon_class( foo => 'this' ); -} 'create anon class'; +} 'create anon class with required attr'; isa_ok( $anon, 'My::Metaclass' ); cmp_ok( $anon->foo, 'eq', 'this', 'foo is this' ); +dies_ok { + $anon = My::Metaclass->create_anon_class(); +} 'failed to create anon class without required attr'; + +my $meta; +lives_ok { + $meta + = My::Metaclass->initialize( 'Class::Name1' => ( foo => 'that' ) ); +} 'initialize a class with required attr'; +isa_ok( $meta, 'My::Metaclass' ); +cmp_ok( $meta->foo, 'eq', 'that', 'foo is that' ); +cmp_ok( $meta->name, 'eq', 'Class::Name1', 'for the correct class' ); +dies_ok { + $meta + = My::Metaclass->initialize( 'Class::Name2' ); +} 'failed to initialize a class without required attr'; + +lives_ok { + eval qq{ + package Class::Name3; + use metaclass 'My::Metaclass' => ( + foo => 'another', + ); + use Moose; + }; + die $@ if $@; +} 'use metaclass with required attr'; +$meta = Class::Name3->meta; +isa_ok( $meta, 'My::Metaclass' ); +cmp_ok( $meta->foo, 'eq', 'another', 'foo is another' ); +cmp_ok( $meta->name, 'eq', 'Class::Name3', 'for the correct class' ); +dies_ok { + eval qq{ + package Class::Name4; + use metaclass 'My::Metaclass'; + use Moose; + }; + die $@ if $@; +} 'failed to use metaclass without required attr'; + + +# how do we pass a required attribute to -traits? +dies_ok { + eval qq{ + package Class::Name5; + use Moose -traits => 'HasFoo'; + }; + die $@ if $@; +} 'failed to use trait without required attr';