X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F020_attributes%2F012_misc_attribute_tests.t;h=8d02691e50eb9ebf198634219a9dded59feda988;hb=c19af49f6e834464f5b8a864f4a4ece99d8feeaf;hp=cdb3342f63d2b3cfd9f96b3bd9436385b44c13dd;hpb=1a740d8abccb317908eec52cab6179c1924e1d3b;p=gitmo%2FMoose.git diff --git a/t/020_attributes/012_misc_attribute_tests.t b/t/020_attributes/012_misc_attribute_tests.t index cdb3342..8d02691 100644 --- a/t/020_attributes/012_misc_attribute_tests.t +++ b/t/020_attributes/012_misc_attribute_tests.t @@ -3,12 +3,10 @@ use strict; use warnings; -use Test::More tests => 42; +use Test::More tests => 47; use Test::Exception; -BEGIN { - use_ok('Moose'); -} + { { @@ -87,6 +85,28 @@ BEGIN { { { + package Test::Arrayref::RoleAttributes::Role; + use Moose::Role; + + has [qw(foo bar baz)] => ( + is => 'rw', + ); + + } + { + package Test::Arrayref::RoleAttributes; + use Moose; + with 'Test::Arrayref::RoleAttributes::Role'; + } + + my $test = Test::Arrayref::RoleAttributes->new; + isa_ok($test, 'Test::Arrayref::RoleAttributes'); + can_ok($test, qw(foo bar baz)); + +} + +{ + { package Test::UndefDefault::Attributes; use Moose; @@ -120,7 +140,7 @@ BEGIN { throws_ok { $moose_obj->a_str( $moose_obj ) - } qr/Attribute \(a_str\) does not pass the type constraint because\: Validation failed for 'Str' failed with value OverloadedStr=HASH\(0x.+?\)/, + } qr/Attribute \(a_str\) does not pass the type constraint because\: Validation failed for 'Str' failed with value OverloadedStr=HASH\(0x.+?\)/, '... dies without overloading the string'; } @@ -135,7 +155,7 @@ BEGIN { throws_ok { OverloadBreaker->new; - } qr/Attribute \(a_num\) does not pass the type constraint because\: Validation failed for 'Int' failed with value 7\.5/, + } qr/Attribute \(a_num\) does not pass the type constraint because\: Validation failed for 'Int' failed with value 7\.5/, '... this doesnt trip overload to break anymore '; lives_ok { @@ -164,14 +184,14 @@ BEGIN { is($instance->foo, 'works', "foo builder works"); } -{ +{ { package Test::Builder::Attribute::Broken; use Moose; has 'foo' => ( required => 1, builder => 'build_foo', is => 'ro'); } - + dies_ok { Test::Builder::Attribute::Broken->new; } '... no builder, wtf'; @@ -195,7 +215,6 @@ BEGIN { my $_foo_attr = $meta->get_attribute("_foo"); ok($foo_attr->is_lazy, "foo is lazy"); - ok($foo_attr->is_required, "foo is required"); ok($foo_attr->is_lazy_build, "foo is lazy_build"); ok($foo_attr->has_clearer, "foo has clearer"); @@ -208,7 +227,7 @@ BEGIN { is($foo_attr->predicate, "has_foo", ".. and it's named has_foo"); ok($_foo_attr->is_lazy, "_foo is lazy"); - ok($_foo_attr->is_required, "_foo is required"); + ok(!$_foo_attr->is_required, "lazy_build attributes are no longer automatically required"); ok($_foo_attr->is_lazy_build, "_foo is lazy_build"); ok($_foo_attr->has_clearer, "_foo has clearer"); @@ -231,3 +250,26 @@ BEGIN { } +{ + package OutOfClassTest; + + use Moose; +} + +lives_ok { OutOfClassTest::has('foo'); } 'create attr via direct sub call'; +lives_ok { OutOfClassTest->can('has')->('bar'); } 'create attr via can'; + +ok(OutOfClassTest->meta->get_attribute('foo'), 'attr created from sub call'); +ok(OutOfClassTest->meta->get_attribute('bar'), 'attr created from can'); + + +{ + { + package Foo; + use Moose; + + ::throws_ok { has 'foo' => ( 'ro', isa => 'Str' ) } + qr/^Usage/, 'has throws error with odd number of attribute options'; + } + +}