X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F073_make_mutable.t;h=52b3c3590dd1a09fcbc44013c9d1477199018e39;hb=939ec2879f2eef695c063d980c47ecf5c6437481;hp=1ad0c968d6b6119293058e237fbe24012cd8f097;hpb=44d6ea77ff5ddf47824a680d3fe11a2263290ed0;p=gitmo%2FClass-MOP.git diff --git a/t/073_make_mutable.t b/t/073_make_mutable.t index 1ad0c96..52b3c35 100644 --- a/t/073_make_mutable.t +++ b/t/073_make_mutable.t @@ -1,8 +1,8 @@ use strict; use warnings; -use Test::More tests => 114; -use Test::Exception; +use Test::More; +use Test::Fatal; use Scalar::Util; @@ -44,49 +44,38 @@ use Class::MOP; my %orig_keys = map { $_ => 1 } grep { !/^_/ } keys %$meta; # Since this has no default it won't be present yet, but it will # be after the class is made immutable. - $orig_keys{immutable_transformer} = 1; - lives_ok {$meta->make_immutable; } '... changed Baz to be immutable'; + is( exception {$meta->make_immutable; }, undef, '... changed Baz to be immutable' ); ok(!$meta->is_mutable, '... our class is no longer mutable'); ok($meta->is_immutable, '... our class is now immutable'); ok(!$meta->make_immutable, '... make immutable now returns nothing'); - ok($meta->get_method_map->{new}, '... inlined constructor created'); - ok($meta->has_method('new'), '... inlined constructor created for sure'); - ok($meta->immutable_transformer->inlined_constructor, - '... transformer says it did inline the constructor'); + ok($meta->get_method('new'), '... inlined constructor created'); + ok($meta->has_method('new'), '... inlined constructor created for sure'); + is_deeply([ map { $_->name } $meta->_inlined_methods ], [ 'new' ], '... really, i mean it'); - lives_ok { $meta->make_mutable; } '... changed Baz to be mutable'; + is( exception { $meta->make_mutable; }, undef, '... changed Baz to be mutable' ); ok($meta->is_mutable, '... our class is mutable'); ok(!$meta->is_immutable, '... our class is not immutable'); ok(!$meta->make_mutable, '... make mutable now returns nothing'); - ok(!$meta->get_method_map->{new}, '... inlined constructor removed'); - ok(!$meta->has_method('new'), '... inlined constructor removed for sure'); - ok(!$meta->immutable_transformer->inlined_constructor, - '... transformer says it did not inline the constructor'); + ok(!$meta->get_method('new'), '... inlined constructor created'); + ok(!$meta->has_method('new'), '... inlined constructor removed for sure'); my %new_keys = map { $_ => 1 } grep { !/^_/ } keys %$meta; is_deeply(\%orig_keys, \%new_keys, '... no extraneous hashkeys'); isa_ok($meta, 'Class::MOP::Class', '... Baz->meta isa Class::MOP::Class'); - ok( $meta->add_method('xyz', sub{'xxx'}), '... added method'); + $meta->add_method('xyz', sub{'xxx'}); is( Baz->xyz, 'xxx', '... method xyz works'); - ok(! $meta->has_method('zxy') ,'... we dont have the aliased method yet'); - ok( $meta->alias_method('zxy',sub{'xxx'}),'... aliased method'); - ok( $meta->has_method('zxy') ,'... the aliased method does register'); - is( Baz->zxy, 'xxx', '... method zxy works'); - ok( $meta->remove_method('xyz'), '... removed method'); - ok( $meta->remove_method('zxy'), '... removed aliased method'); - ok($meta->add_attribute('fickle', accessor => 'fickle'), '... added attribute'); ok(Baz->can('fickle'), '... Baz can fickle'); ok($meta->remove_attribute('fickle'), '... removed attribute'); my $reef = \ 'reef'; - ok($meta->add_package_symbol('$ref', $reef), '... added package symbol'); + $meta->add_package_symbol('$ref', $reef); is($meta->get_package_symbol('$ref'), $reef, '... values match'); - lives_ok { $meta->remove_package_symbol('$ref') } '... removed it'; + is( exception { $meta->remove_package_symbol('$ref') }, undef, '... removed it' ); isnt($meta->get_package_symbol('$ref'), $reef, '... values match'); ok( my @supers = $meta->superclasses, '... got the superclasses okay'); @@ -96,39 +85,37 @@ use Class::MOP; is_deeply([@supers], [$meta->superclasses], '... reset the superclasses okay'); ok( $meta->$_ , "... ${_} works") - for qw(get_meta_instance compute_all_applicable_attributes - class_precedence_list get_method_map ); + for qw(get_meta_instance get_all_attributes + class_precedence_list ); - lives_ok {$meta->make_immutable; } '... changed Baz to be immutable again'; - ok($meta->get_method_map->{new}, '... inlined constructor recreated'); + is( exception {$meta->make_immutable; }, undef, '... changed Baz to be immutable again' ); + ok($meta->get_method('new'), '... inlined constructor recreated'); } { my $meta = Baz->meta; - lives_ok { $meta->make_immutable() } 'Changed Baz to be immutable'; - lives_ok { $meta->make_mutable() } '... changed Baz to be mutable'; - lives_ok { $meta->make_immutable() } '... changed Baz to be immutable'; + is( exception { $meta->make_immutable() }, undef, 'Changed Baz to be immutable' ); + is( exception { $meta->make_mutable() }, undef, '... changed Baz to be mutable' ); + is( exception { $meta->make_immutable() }, undef, '... changed Baz to be immutable' ); - dies_ok{ $meta->add_method('xyz', sub{'xxx'}) } '... exception thrown as expected'; - dies_ok{ $meta->alias_method('zxy',sub{'xxx'}) } '... exception thrown as expected'; - dies_ok{ $meta->remove_method('zxy') } '... exception thrown as expected'; + isnt( exception { $meta->add_method('xyz', sub{'xxx'}) }, undef, '... exception thrown as expected' ); - dies_ok { + isnt( exception { $meta->add_attribute('fickle', accessor => 'fickle') - } '... exception thrown as expected'; - dies_ok { $meta->remove_attribute('fickle') } '... exception thrown as expected'; + }, undef, '... exception thrown as expected' ); + isnt( exception { $meta->remove_attribute('fickle') }, undef, '... exception thrown as expected' ); my $reef = \ 'reef'; - dies_ok { $meta->add_package_symbol('$ref', $reef) } '... exception thrown as expected'; - dies_ok { $meta->remove_package_symbol('$ref') } '... exception thrown as expected'; + isnt( exception { $meta->add_package_symbol('$ref', $reef) }, undef, '... exception thrown as expected' ); + isnt( exception { $meta->remove_package_symbol('$ref') }, undef, '... exception thrown as expected' ); ok( my @supers = $meta->superclasses, '... got the superclasses okay'); - dies_ok { $meta->superclasses('Foo') } '... set the superclasses'; + isnt( exception { $meta->superclasses('Foo') }, undef, '... set the superclasses' ); ok( $meta->$_ , "... ${_} works") - for qw(get_meta_instance compute_all_applicable_attributes - class_precedence_list get_method_map ); + for qw(get_meta_instance get_all_attributes + class_precedence_list ); } { @@ -136,24 +123,22 @@ use Class::MOP; ok(Baz->meta->is_immutable, 'Superclass is immutable'); my $meta = Baz->meta->create_anon_class(superclasses => ['Baz']); my %orig_keys = map { $_ => 1 } grep { !/^_/ } keys %$meta; - $orig_keys{immutable_transformer} = 1; - my @orig_meths = sort { $a->{name} cmp $b->{name} } - $meta->compute_all_applicable_methods; + my @orig_meths = sort { $a->name cmp $b->name } $meta->get_all_methods; ok($meta->is_anon_class, 'We have an anon metaclass'); ok($meta->is_mutable, '... our anon class is mutable'); ok(!$meta->is_immutable, '... our anon class is not immutable'); - lives_ok {$meta->make_immutable( + is( exception {$meta->make_immutable( inline_accessor => 1, inline_destructor => 0, inline_constructor => 1, ) - } '... changed class to be immutable'; + }, undef, '... changed class to be immutable' ); ok(!$meta->is_mutable, '... our class is no longer mutable'); ok($meta->is_immutable, '... our class is now immutable'); ok(!$meta->make_immutable, '... make immutable now returns nothing'); - lives_ok { $meta->make_mutable } '... changed Baz to be mutable'; + is( exception { $meta->make_mutable }, undef, '... changed Baz to be mutable' ); ok($meta->is_mutable, '... our class is mutable'); ok(!$meta->is_immutable, '... our class is not immutable'); ok(!$meta->make_mutable, '... make mutable now returns nothing'); @@ -161,28 +146,25 @@ use Class::MOP; my $instance = $meta->new_object; my %new_keys = map { $_ => 1 } grep { !/^_/ } keys %$meta; - my @new_meths = sort { $a->{name} cmp $b->{name} } - $meta->compute_all_applicable_methods; + my @new_meths = sort { $a->name cmp $b->name } + $meta->get_all_methods; is_deeply(\%orig_keys, \%new_keys, '... no extraneous hashkeys'); - is_deeply(\@orig_meths, \@new_meths, '... no extraneous methods'); + is_deeply(\@orig_meths, \@new_meths, '... no straneous methods'); isa_ok($meta, 'Class::MOP::Class', '... Anon class isa Class::MOP::Class'); - ok( $meta->add_method('xyz', sub{'xxx'}), '... added method'); + $meta->add_method('xyz', sub{'xxx'}); is( $instance->xyz , 'xxx', '... method xyz works'); - ok( $meta->alias_method('zxy',sub{'xxx'}),'... aliased method'); - is( $instance->zxy, 'xxx', '... method zxy works'); ok( $meta->remove_method('xyz'), '... removed method'); - ok( $meta->remove_method('zxy'), '... removed aliased method'); ok($meta->add_attribute('fickle', accessor => 'fickle'), '... added attribute'); ok($instance->can('fickle'), '... instance can fickle'); ok($meta->remove_attribute('fickle'), '... removed attribute'); my $reef = \ 'reef'; - ok($meta->add_package_symbol('$ref', $reef), '... added package symbol'); + $meta->add_package_symbol('$ref', $reef); is($meta->get_package_symbol('$ref'), $reef, '... values match'); - lives_ok { $meta->remove_package_symbol('$ref') } '... removed it'; + is( exception { $meta->remove_package_symbol('$ref') }, undef, '... removed it' ); isnt($meta->get_package_symbol('$ref'), $reef, '... values match'); ok( my @supers = $meta->superclasses, '... got the superclasses okay'); @@ -192,8 +174,8 @@ use Class::MOP; is_deeply([@supers], [$meta->superclasses], '... reset the superclasses okay'); ok( $meta->$_ , "... ${_} works") - for qw(get_meta_instance compute_all_applicable_attributes - class_precedence_list get_method_map ); + for qw(get_meta_instance get_all_attributes + class_precedence_list ); }; @@ -201,41 +183,38 @@ use Class::MOP; { my $meta = Baz->meta->create_anon_class(superclasses => ['Baz']); - lives_ok {$meta->make_immutable( + is( exception {$meta->make_immutable( inline_accessor => 1, inline_destructor => 0, inline_constructor => 1, ) - } '... changed class to be immutable'; - lives_ok { $meta->make_mutable() } '... changed class to be mutable'; - lives_ok {$meta->make_immutable } '... changed class to be immutable'; + }, undef, '... changed class to be immutable' ); + is( exception { $meta->make_mutable() }, undef, '... changed class to be mutable' ); + is( exception {$meta->make_immutable }, undef, '... changed class to be immutable' ); - dies_ok{ $meta->add_method('xyz', sub{'xxx'}) } '... exception thrown as expected'; - dies_ok{ $meta->alias_method('zxy',sub{'xxx'}) } '... exception thrown as expected'; - dies_ok{ $meta->remove_method('zxy') } '... exception thrown as expected'; + isnt( exception { $meta->add_method('xyz', sub{'xxx'}) }, undef, '... exception thrown as expected' ); - dies_ok { + isnt( exception { $meta->add_attribute('fickle', accessor => 'fickle') - } '... exception thrown as expected'; - dies_ok { $meta->remove_attribute('fickle') } '... exception thrown as expected'; + }, undef, '... exception thrown as expected' ); + isnt( exception { $meta->remove_attribute('fickle') }, undef, '... exception thrown as expected' ); my $reef = \ 'reef'; - dies_ok { $meta->add_package_symbol('$ref', $reef) } '... exception thrown as expected'; - dies_ok { $meta->remove_package_symbol('$ref') } '... exception thrown as expected'; + isnt( exception { $meta->add_package_symbol('$ref', $reef) }, undef, '... exception thrown as expected' ); + isnt( exception { $meta->remove_package_symbol('$ref') }, undef, '... exception thrown as expected' ); ok( my @supers = $meta->superclasses, '... got the superclasses okay'); - dies_ok { $meta->superclasses('Foo') } '... set the superclasses'; + isnt( exception { $meta->superclasses('Foo') }, undef, '... set the superclasses' ); ok( $meta->$_ , "... ${_} works") - for qw(get_meta_instance compute_all_applicable_attributes - class_precedence_list get_method_map ); + for qw(get_meta_instance get_all_attributes + class_precedence_list ); } { Foo->meta->make_immutable; Bar->meta->make_immutable; Bar->meta->make_mutable; - - isnt( Foo->meta->immutable_transformer, Bar->meta->immutable_transformer, - 'Foo and Bar should have different immutable transformer objects' ); } + +done_testing;