From: Fuji, Goro Date: Sat, 25 Sep 2010 04:32:51 +0000 (+0900) Subject: Reorganize t/050_metaclasses/ X-Git-Tag: 0.72~26 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6217087ac410ed5f4b7f19d689f113f3a6765be2;p=gitmo%2FMouse.git Reorganize t/050_metaclasses/ --- diff --git a/t/050_metaclasses/001_custom_attr_meta_with_roles.t b/t/050_metaclasses/001_custom_attr_meta_with_roles.t index 613e0f9..4e5feb4 100644 --- a/t/050_metaclasses/001_custom_attr_meta_with_roles.t +++ b/t/050_metaclasses/001_custom_attr_meta_with_roles.t @@ -1,13 +1,15 @@ #!/usr/bin/perl +# This is automatically generated by author/import-moose-test.pl. +# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! +use t::lib::MooseCompat; use strict; use warnings; -use Test::More tests => 3; +use Test::More; use Test::Exception; - { package My::Custom::Meta::Attr; use Mouse; @@ -40,4 +42,4 @@ ok($c->meta->has_attribute('bling_bling'), '... got the attribute'); isa_ok($c->meta->get_attribute('bling_bling'), 'My::Custom::Meta::Attr'); - +done_testing; diff --git a/t/050_metaclasses/002_custom_attr_meta_as_role.t b/t/050_metaclasses/002_custom_attr_meta_as_role.t index 106f19c..2f8f519 100644 --- a/t/050_metaclasses/002_custom_attr_meta_as_role.t +++ b/t/050_metaclasses/002_custom_attr_meta_as_role.t @@ -1,13 +1,14 @@ #!/usr/bin/perl +# This is automatically generated by author/import-moose-test.pl. +# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! +use t::lib::MooseCompat; use strict; use warnings; -use Test::More tests => 2; +use Test::More; use Test::Exception; -; - lives_ok { package MouseX::Attribute::Test; use Mouse::Role; @@ -20,3 +21,5 @@ lives_ok { extends 'Mouse::Meta::Attribute'; with 'MouseX::Attribute::Test'; } 'custom attribute metaclass extending role is okay'; + +done_testing; diff --git a/t/050_metaclasses/004_moose_for_meta.t b/t/050_metaclasses/004_moose_for_meta.t new file mode 100644 index 0000000..aa37b04 --- /dev/null +++ b/t/050_metaclasses/004_moose_for_meta.t @@ -0,0 +1,82 @@ +#!/usr/bin/perl +# This is automatically generated by author/import-moose-test.pl. +# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! +use t::lib::MooseCompat; + +use strict; +use warnings; + +use Test::More; +use Test::Exception; + + +=pod + +This test demonstrates the ability to extend +Mouse meta-level classes using Mouse itself. + +=cut + +{ + package My::Meta::Class; + use Mouse; + + extends 'Mouse::Meta::Class'; + + around 'create_anon_class' => sub { + my $next = shift; + my ($self, %options) = @_; + $options{superclasses} = [ 'Mouse::Object' ] + unless exists $options{superclasses}; + $next->($self, %options); + }; +} + +my $anon = My::Meta::Class->create_anon_class(); +isa_ok($anon, 'My::Meta::Class'); +isa_ok($anon, 'Mouse::Meta::Class'); +isa_ok($anon, 'Mouse::Meta::Class'); + +is_deeply( + [ $anon->superclasses ], + [ 'Mouse::Object' ], + '... got the default superclasses'); + +{ + package My::Meta::Attribute::DefaultReadOnly; + use Mouse; + + extends 'Mouse::Meta::Attribute'; + + around 'new' => sub { + my $next = shift; + my ($self, $name, %options) = @_; + $options{is} = 'ro' + unless exists $options{is}; + $next->($self, $name, %options); + }; +} + +{ + my $attr = My::Meta::Attribute::DefaultReadOnly->new('foo'); + isa_ok($attr, 'My::Meta::Attribute::DefaultReadOnly'); + isa_ok($attr, 'Mouse::Meta::Attribute'); + isa_ok($attr, 'Mouse::Meta::Attribute'); + + ok($attr->has_reader, '... the attribute has a reader (as expected)'); + ok(!$attr->has_writer, '... the attribute does not have a writer (as expected)'); + ok(!$attr->has_accessor, '... the attribute does not have an accessor (as expected)'); +} + +{ + my $attr = My::Meta::Attribute::DefaultReadOnly->new('foo', (is => 'rw')); + isa_ok($attr, 'My::Meta::Attribute::DefaultReadOnly'); + isa_ok($attr, 'Mouse::Meta::Attribute'); + isa_ok($attr, 'Mouse::Meta::Attribute'); + + ok(!$attr->has_reader, '... the attribute does not have a reader (as expected)'); + ok(!$attr->has_writer, '... the attribute does not have a writer (as expected)'); + ok($attr->has_accessor, '... the attribute does have an accessor (as expected)'); +} + +done_testing; diff --git a/t/050_metaclasses/013_metaclass_traits.t b/t/050_metaclasses/013_metaclass_traits.t index 06159a0..c04959f 100644 --- a/t/050_metaclasses/013_metaclass_traits.t +++ b/t/050_metaclasses/013_metaclass_traits.t @@ -1,11 +1,14 @@ #!/usr/bin/perl +# This is automatically generated by author/import-moose-test.pl. +# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! +use t::lib::MooseCompat; use strict; use warnings; use lib 't/lib', 'lib'; -use Test::More tests => 32; +use Test::More; use Test::Exception; { @@ -173,7 +176,6 @@ is( Role::Foo->meta()->simple(), 5, '... and error provides a useful explanation' ); } - { package Foo::Subclass; @@ -221,3 +223,5 @@ lives_ok { is( $instance->an_attr, 'value', 'Can get value' ); } 'Can create instance and access attributes'; + +done_testing; diff --git a/t/050_metaclasses/017_use_base_of_moose.t b/t/050_metaclasses/017_use_base_of_moose.t index b8962bd..607a067 100644 --- a/t/050_metaclasses/017_use_base_of_moose.t +++ b/t/050_metaclasses/017_use_base_of_moose.t @@ -1,21 +1,22 @@ #!/usr/bin/env perl +# This is automatically generated by author/import-moose-test.pl. +# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! +use t::lib::MooseCompat; use strict; use warnings; -use Test::More tests => 4; +use Test::More; use Test::Exception; { package NoOpTrait; use Mouse::Role; - - } { package Parent; - use Mouse "-traits" => 'NoOpTrait'; + use Mouse -traits => 'NoOpTrait'; has attr => ( is => 'rw', @@ -27,12 +28,15 @@ use Test::Exception; package Child; use base 'Parent'; } + is(Child->meta->name, 'Child', "correct metaclass name"); + my $child = Child->new(attr => "ibute"); ok($child, "constructor works"); - is($child->attr, "ibute", "getter inherited properly"); $child->attr("ition"); is($child->attr, "ition", "setter inherited properly"); + +done_testing; diff --git a/t/050_metaclasses/020_metaclass_parameterized_traits.t b/t/050_metaclasses/020_metaclass_parameterized_traits.t index a590605..b6544f9 100644 --- a/t/050_metaclasses/020_metaclass_parameterized_traits.t +++ b/t/050_metaclasses/020_metaclass_parameterized_traits.t @@ -1,8 +1,10 @@ #!/usr/bin/env perl +# This is automatically generated by author/import-moose-test.pl. +# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! +use t::lib::MooseCompat; use strict; use warnings; - -use Test::More tests => 5; +use Test::More; { package My::Trait; @@ -46,3 +48,4 @@ is($other_meta->reversed, 'ssalC::rehtO::yM', 'parameterized trait applied'); ok(!$other_meta->can('enam'), "the method was not installed under the other class' alias"); ok(!$other_meta->can('reversed_name'), "the method was not installed under the original name when that was excluded"); +done_testing; diff --git a/t/050_metaclasses/021_export_with_prototype.t b/t/050_metaclasses/021_export_with_prototype.t new file mode 100644 index 0000000..d288900 --- /dev/null +++ b/t/050_metaclasses/021_export_with_prototype.t @@ -0,0 +1,25 @@ +use lib "t/lib"; +# This is automatically generated by author/import-moose-test.pl. +# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! +use t::lib::MooseCompat; +package MyExporter::User; +use MyExporter; + +use Test::More; +use Test::Exception; +{ local $TODO = q{Mouse does not support with_meta option in the exporter}; +lives_and { + with_prototype { + my $caller = caller(0); + is($caller, 'MyExporter', "With_caller prototype code gets called from MyMouseX"); + }; +} "check function with prototype"; +} # end of TODO +lives_and { + as_is_prototype { + my $caller = caller(0); + is($caller, 'MyExporter', "As-is prototype code gets called from MyMouseX"); + }; +} "check function with prototype"; + +done_testing; diff --git a/t/050_metaclasses/041_moose_nonmoose_moose_chain_init_meta.t b/t/050_metaclasses/041_moose_nonmoose_moose_chain_init_meta.t new file mode 100644 index 0000000..9741e72 --- /dev/null +++ b/t/050_metaclasses/041_moose_nonmoose_moose_chain_init_meta.t @@ -0,0 +1,27 @@ +use strict; +# This is automatically generated by author/import-moose-test.pl. +# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! +use t::lib::MooseCompat; +use warnings; +{ + package ParentClass; + use Mouse; +} +{ + package SomeClass; + use base 'ParentClass'; +} +{ + package SubClassUseBase; + use base qw/SomeClass/; + use Mouse; +} + +use Test::More; +use Test::Exception; + +lives_ok { + Mouse->init_meta(for_class => 'SomeClass'); +} 'Mouse class => use base => Mouse Class, then Mouse->init_meta on middle class ok'; + +done_testing; diff --git a/t/050_metaclasses/051_metarole_on_anon.t b/t/050_metaclasses/051_metarole_on_anon.t index f0ec101..7a79418 100644 --- a/t/050_metaclasses/051_metarole_on_anon.t +++ b/t/050_metaclasses/051_metarole_on_anon.t @@ -1,4 +1,7 @@ use strict; +# This is automatically generated by author/import-moose-test.pl. +# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! +use t::lib::MooseCompat; use warnings; use Test::More; diff --git a/t/050_metaclasses/052_new_object_BUILD.t b/t/050_metaclasses/052_new_object_BUILD.t new file mode 100644 index 0000000..b3badc8 --- /dev/null +++ b/t/050_metaclasses/052_new_object_BUILD.t @@ -0,0 +1,23 @@ +#!/usr/bin/env perl +# This is automatically generated by author/import-moose-test.pl. +# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! +use t::lib::MooseCompat; +use strict; +use warnings; +use Test::More; + +my $called; +{ + package Foo; + use Mouse; + + sub BUILD { $called++ } +} + +Foo->new; +is($called, 1, "BUILD called from ->new"); +$called = 0; +Foo->meta->new_object; +is($called, 1, "BUILD called from ->meta->new_object"); + +done_testing; diff --git a/t/050_metaclasses/053_immutable_metaclass_compat_bug.t b/t/050_metaclasses/053_immutable_metaclass_compat_bug.t new file mode 100644 index 0000000..08d0c91 --- /dev/null +++ b/t/050_metaclasses/053_immutable_metaclass_compat_bug.t @@ -0,0 +1,41 @@ +#!/usr/bin/env perl +# This is automatically generated by author/import-moose-test.pl. +# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! +use t::lib::MooseCompat; +use strict; +use warnings; +use Test::More; + +{ + package Foo::Base::Meta::Trait; + use Mouse::Role; +} + +{ + package Foo::Base; + use Mouse; + Mouse::Util::MetaRole::apply_metaroles( + for => __PACKAGE__, + class_metaroles => { constructor => ['Foo::Base::Meta::Trait'] }, + ); + __PACKAGE__->meta->make_immutable; +} + +{ + package Foo::Meta::Trait; + use Mouse::Role; +} + +{ + package Foo; + use Mouse; + Mouse::Util::MetaRole::apply_metaroles( + for => __PACKAGE__, + class_metaroles => { constructor => ['Foo::Meta::Trait'] } + ); + ::ok(!Foo->meta->is_immutable); + extends 'Foo::Base'; + ::ok(!Foo->meta->is_immutable); +} + +done_testing; diff --git a/t/050_metaclasses/054_metaclass_compat_no_fixing_bug.t b/t/050_metaclasses/054_metaclass_compat_no_fixing_bug.t new file mode 100644 index 0000000..3fadb21 --- /dev/null +++ b/t/050_metaclasses/054_metaclass_compat_no_fixing_bug.t @@ -0,0 +1,49 @@ +#!/usr/bin/env perl +# This is automatically generated by author/import-moose-test.pl. +# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! +use t::lib::MooseCompat; +use strict; +use warnings; +use Test::More; +use Test::Exception; + +{ + package Foo::Meta::Constructor1; + use Mouse::Role; +} + +{ + package Foo::Meta::Constructor2; + use Mouse::Role; +} + +{ + package Foo; + use Mouse; + Mouse::Util::MetaRole::apply_metaroles( + for => __PACKAGE__, + class_metaroles => { constructor => ['Foo::Meta::Constructor1'] }, + ); +} + +{ + package Foo::Sub; + use Mouse; + Mouse::Util::MetaRole::apply_metaroles( + for => __PACKAGE__, + class_metaroles => { constructor => ['Foo::Meta::Constructor2'] }, + ); + extends 'Foo'; +} + +{ + package Foo::Sub::Sub; + use Mouse; + Mouse::Util::MetaRole::apply_metaroles( + for => __PACKAGE__, + class_metaroles => { constructor => ['Foo::Meta::Constructor2'] }, + ); + ::lives_ok { extends 'Foo::Sub' } "doesn't try to fix if nothing is needed"; +} + +done_testing;