X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F070_immutable_metaclass.t;h=ca3ecf963cc02450960325e1c64900261b638a1b;hb=5e5102f19ccb1dc52b290577b0363e97dacbd5b3;hp=b2ee906c101ad889b2401d50485533c0125bc614;hpb=f5d080227b5fe6c95712defbf9212e94673ad4d2;p=gitmo%2FClass-MOP.git diff --git a/t/070_immutable_metaclass.t b/t/070_immutable_metaclass.t index b2ee906..ca3ecf9 100644 --- a/t/070_immutable_metaclass.t +++ b/t/070_immutable_metaclass.t @@ -1,8 +1,8 @@ use strict; use warnings; -use Test::More tests => 75; -use Test::Exception; +use Test::More; +use Test::Fatal; use Class::MOP; @@ -40,23 +40,38 @@ use Class::MOP; my $meta = Foo->meta; my $original_metaclass_name = ref $meta; + is_deeply( + { $meta->immutable_options }, {}, + 'immutable_options is empty before a class is made_immutable' + ); + $meta->make_immutable; - my $immutable_metaclass = $meta->immutable_metaclass->meta; + my $immutable_metaclass = $meta->_immutable_metaclass->meta; - #I don't understand why i need to ->meta here... - my $obj = $immutable_metaclass->name; + my $immutable_class_name = $immutable_metaclass->name; - ok( !$obj->is_mutable, '... immutable_metaclass is not mutable' ); - ok( $obj->is_immutable, '... immutable_metaclass is immutable' ); - ok( !$obj->make_immutable, - '... immutable_metaclass make_mutable is noop' ); - is( $obj->meta, $immutable_metaclass, + ok( !$immutable_class_name->is_mutable, '... immutable_metaclass is not mutable' ); + ok( $immutable_class_name->is_immutable, '... immutable_metaclass is immutable' ); + is( $immutable_class_name->meta, $immutable_metaclass, '... immutable_metaclass meta hack works' ); - isa_ok( $meta, "Class::MOP::Class::Immutable::Trait" ); - isa_ok( $meta, "Class::MOP::Class" ); + is_deeply( + { $meta->immutable_options }, + { + inline_accessors => 1, + inline_constructor => 1, + inline_destructor => 0, + debug => 0, + immutable_trait => 'Class::MOP::Class::Immutable::Trait', + constructor_name => 'new', + constructor_class => 'Class::MOP::Method::Constructor', + destructor_class => undef, + }, + 'immutable_options is empty before a class is made_immutable' + ); + isa_ok( $meta, "Class::MOP::Class" ); } { @@ -68,44 +83,37 @@ use Class::MOP; isa_ok( $meta, 'Class::MOP::Class' ); - dies_ok { $meta->add_method() } '... exception thrown as expected'; - dies_ok { $meta->alias_method() } '... exception thrown as expected'; - dies_ok { $meta->remove_method() } '... exception thrown as expected'; + isnt( exception { $meta->add_method() }, undef, '... exception thrown as expected' ); + isnt( exception { $meta->alias_method() }, undef, '... exception thrown as expected' ); + isnt( exception { $meta->remove_method() }, undef, '... exception thrown as expected' ); - dies_ok { $meta->add_attribute() } '... exception thrown as expected'; - dies_ok { $meta->remove_attribute() } '... exception thrown as expected'; + isnt( exception { $meta->add_attribute() }, undef, '... exception thrown as expected' ); + isnt( exception { $meta->remove_attribute() }, undef, '... exception thrown as expected' ); - dies_ok { $meta->add_package_symbol() } - '... exception thrown as expected'; - dies_ok { $meta->remove_package_symbol() } - '... exception thrown as expected'; + isnt( exception { $meta->add_package_symbol() }, undef, '... exception thrown as expected' ); + isnt( exception { $meta->remove_package_symbol() }, undef, '... exception thrown as expected' ); - lives_ok { $meta->identifier() } - '... no exception for get_package_symbol special case'; + is( exception { $meta->identifier() }, undef, '... no exception for get_package_symbol special case' ); my @supers; - lives_ok { + is( exception { @supers = $meta->superclasses; - } - '... got the superclasses okay'; + }, undef, '... got the superclasses okay' ); - dies_ok { $meta->superclasses( ['UNIVERSAL'] ) } - '... but could not set the superclasses okay'; + isnt( exception { $meta->superclasses( ['UNIVERSAL'] ) }, undef, '... but could not set the superclasses okay' ); my $meta_instance; - lives_ok { + is( exception { $meta_instance = $meta->get_meta_instance; - } - '... got the meta instance okay'; + }, undef, '... got the meta instance okay' ); isa_ok( $meta_instance, 'Class::MOP::Instance' ); is( $meta_instance, $meta->get_meta_instance, '... and we know it is cached' ); my @cpl; - lives_ok { + is( exception { @cpl = $meta->class_precedence_list; - } - '... got the class precedence list okay'; + }, undef, '... got the class precedence list okay' ); is_deeply( \@cpl, ['Foo'], @@ -113,10 +121,9 @@ use Class::MOP; ); my @attributes; - lives_ok { + is( exception { @attributes = $meta->get_all_attributes; - } - '... got the attribute list okay'; + }, undef, '... got the attribute list okay' ); is_deeply( \@attributes, [ $meta->get_attribute('bar') ], @@ -131,10 +138,9 @@ use Class::MOP; ok( $meta->is_mutable, '... our class is mutable' ); ok( !$meta->is_immutable, '... our class is not immutable' ); - lives_ok { + is( exception { $meta->make_immutable(); - } - '... changed Bar to be immutable'; + }, undef, '... changed Bar to be immutable' ); ok( !$meta->make_immutable, '... make immutable now returns nothing' ); @@ -143,41 +149,35 @@ use Class::MOP; isa_ok( $meta, 'Class::MOP::Class' ); - dies_ok { $meta->add_method() } '... exception thrown as expected'; - dies_ok { $meta->alias_method() } '... exception thrown as expected'; - dies_ok { $meta->remove_method() } '... exception thrown as expected'; + isnt( exception { $meta->add_method() }, undef, '... exception thrown as expected' ); + isnt( exception { $meta->alias_method() }, undef, '... exception thrown as expected' ); + isnt( exception { $meta->remove_method() }, undef, '... exception thrown as expected' ); - dies_ok { $meta->add_attribute() } '... exception thrown as expected'; - dies_ok { $meta->remove_attribute() } '... exception thrown as expected'; + isnt( exception { $meta->add_attribute() }, undef, '... exception thrown as expected' ); + isnt( exception { $meta->remove_attribute() }, undef, '... exception thrown as expected' ); - dies_ok { $meta->add_package_symbol() } - '... exception thrown as expected'; - dies_ok { $meta->remove_package_symbol() } - '... exception thrown as expected'; + isnt( exception { $meta->add_package_symbol() }, undef, '... exception thrown as expected' ); + isnt( exception { $meta->remove_package_symbol() }, undef, '... exception thrown as expected' ); my @supers; - lives_ok { + is( exception { @supers = $meta->superclasses; - } - '... got the superclasses okay'; + }, undef, '... got the superclasses okay' ); - dies_ok { $meta->superclasses( ['UNIVERSAL'] ) } - '... but could not set the superclasses okay'; + isnt( exception { $meta->superclasses( ['UNIVERSAL'] ) }, undef, '... but could not set the superclasses okay' ); my $meta_instance; - lives_ok { + is( exception { $meta_instance = $meta->get_meta_instance; - } - '... got the meta instance okay'; + }, undef, '... got the meta instance okay' ); isa_ok( $meta_instance, 'Class::MOP::Instance' ); is( $meta_instance, $meta->get_meta_instance, '... and we know it is cached' ); my @cpl; - lives_ok { + is( exception { @cpl = $meta->class_precedence_list; - } - '... got the class precedence list okay'; + }, undef, '... got the class precedence list okay' ); is_deeply( \@cpl, [ 'Bar', 'Foo' ], @@ -185,10 +185,9 @@ use Class::MOP; ); my @attributes; - lives_ok { + is( exception { @attributes = $meta->get_all_attributes; - } - '... got the attribute list okay'; + }, undef, '... got the attribute list okay' ); is_deeply( [ sort { $a->name cmp $b->name } @attributes ], [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ], @@ -203,10 +202,9 @@ use Class::MOP; ok( $meta->is_mutable, '... our class is mutable' ); ok( !$meta->is_immutable, '... our class is not immutable' ); - lives_ok { + is( exception { $meta->make_immutable(); - } - '... changed Baz to be immutable'; + }, undef, '... changed Baz to be immutable' ); ok( !$meta->make_immutable, '... make immutable now returns nothing' ); @@ -215,41 +213,35 @@ use Class::MOP; isa_ok( $meta, 'Class::MOP::Class' ); - dies_ok { $meta->add_method() } '... exception thrown as expected'; - dies_ok { $meta->alias_method() } '... exception thrown as expected'; - dies_ok { $meta->remove_method() } '... exception thrown as expected'; + isnt( exception { $meta->add_method() }, undef, '... exception thrown as expected' ); + isnt( exception { $meta->alias_method() }, undef, '... exception thrown as expected' ); + isnt( exception { $meta->remove_method() }, undef, '... exception thrown as expected' ); - dies_ok { $meta->add_attribute() } '... exception thrown as expected'; - dies_ok { $meta->remove_attribute() } '... exception thrown as expected'; + isnt( exception { $meta->add_attribute() }, undef, '... exception thrown as expected' ); + isnt( exception { $meta->remove_attribute() }, undef, '... exception thrown as expected' ); - dies_ok { $meta->add_package_symbol() } - '... exception thrown as expected'; - dies_ok { $meta->remove_package_symbol() } - '... exception thrown as expected'; + isnt( exception { $meta->add_package_symbol() }, undef, '... exception thrown as expected' ); + isnt( exception { $meta->remove_package_symbol() }, undef, '... exception thrown as expected' ); my @supers; - lives_ok { + is( exception { @supers = $meta->superclasses; - } - '... got the superclasses okay'; + }, undef, '... got the superclasses okay' ); - dies_ok { $meta->superclasses( ['UNIVERSAL'] ) } - '... but could not set the superclasses okay'; + isnt( exception { $meta->superclasses( ['UNIVERSAL'] ) }, undef, '... but could not set the superclasses okay' ); my $meta_instance; - lives_ok { + is( exception { $meta_instance = $meta->get_meta_instance; - } - '... got the meta instance okay'; + }, undef, '... got the meta instance okay' ); isa_ok( $meta_instance, 'Class::MOP::Instance' ); is( $meta_instance, $meta->get_meta_instance, '... and we know it is cached' ); my @cpl; - lives_ok { + is( exception { @cpl = $meta->class_precedence_list; - } - '... got the class precedence list okay'; + }, undef, '... got the class precedence list okay' ); is_deeply( \@cpl, [ 'Baz', 'Bar', 'Foo' ], @@ -257,10 +249,9 @@ use Class::MOP; ); my @attributes; - lives_ok { + is( exception { @attributes = $meta->get_all_attributes; - } - '... got the attribute list okay'; + }, undef, '... got the attribute list okay' ); is_deeply( [ sort { $a->name cmp $b->name } @attributes ], [ @@ -270,3 +261,32 @@ use Class::MOP; '... got the right list of attributes' ); } + +# This test probably needs to go last since it will muck up the Foo class +{ + my $meta = Foo->meta; + + $meta->make_mutable; + $meta->make_immutable( + inline_accessors => 0, + inline_constructor => 0, + constructor_name => 'newer', + ); + + is_deeply( + { $meta->immutable_options }, + { + inline_accessors => 0, + inline_constructor => 0, + inline_destructor => 0, + debug => 0, + immutable_trait => 'Class::MOP::Class::Immutable::Trait', + constructor_name => 'newer', + constructor_class => 'Class::MOP::Method::Constructor', + destructor_class => undef, + }, + 'custom immutable_options are returned by immutable_options accessor' + ); +} + +done_testing;