From: Dave Rolsky Date: Thu, 28 Oct 2010 21:52:20 +0000 (-0500) Subject: Redo conversion to Test::Fatal X-Git-Tag: 1.11~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=871e9eb5d05b8b9986b2de3f4095f65a31159c56;hp=8371f3de4e9525ab751008dca4a89e6df65345a6;p=gitmo%2FClass-MOP.git Redo conversion to Test::Fatal --- diff --git a/t/001_basic.t b/t/001_basic.t index f45712d..b782491 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; use Class::MOP::Class; diff --git a/t/003_methods.t b/t/003_methods.t index 5340b44..ac985bf 100644 --- a/t/003_methods.t +++ b/t/003_methods.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Scalar::Util qw/reftype/; use Sub::Name; @@ -74,10 +74,9 @@ my $foo = sub {'Foo::foo'}; ok( !UNIVERSAL::isa( $foo, 'Class::MOP::Method' ), '... our method is not yet blessed' ); -lives_ok { +is( exception { $Foo->add_method( 'foo' => $foo ); -} -'... we added the method successfully'; +}, undef, '... we added the method successfully' ); my $foo_method = $Foo->get_method('foo'); @@ -210,7 +209,7 @@ is_deeply( is( $Foo->remove_method('foo')->body, $foo, '... removed the foo method' ); ok( !$Foo->has_method('foo'), '... !Foo->has_method(foo) we just removed it' ); -dies_ok { Foo->foo } '... cannot call Foo->foo because it is not there'; +isnt( exception { Foo->foo }, undef, '... cannot call Foo->foo because it is not there' ); is_deeply( [ sort $Foo->get_method_list ], @@ -236,10 +235,9 @@ ok( $Bar->has_method('bar'), '... Bar->has_method(bar)' ); is( Bar->foo, 'Bar::foo', '... Bar->foo == Bar::foo' ); is( Bar->bar, 'Bar::bar', '... Bar->bar == Bar::bar' ); -lives_ok { +is( exception { $Bar->add_method( 'foo' => sub {'Bar::foo v2'} ); -} -'... overwriting a method is fine'; +}, undef, '... overwriting a method is fine' ); is_deeply( [ Class::MOP::get_code_info( $Bar->get_method('foo')->body ) ], [ "Bar", "foo" ], "subname applied to anonymous method" ); diff --git a/t/004_advanced_methods.t b/t/004_advanced_methods.t index b67cdac..84aadb8 100644 --- a/t/004_advanced_methods.t +++ b/t/004_advanced_methods.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; use Class::MOP::Class; diff --git a/t/005_attributes.t b/t/005_attributes.t index fa10b41..a6df570 100644 --- a/t/005_attributes.t +++ b/t/005_attributes.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -31,17 +31,17 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); use metaclass; my $meta = Foo->meta; - ::lives_ok { + ::is( ::exception { $meta->add_attribute($FOO_ATTR); - } '... we added an attribute to Foo successfully'; + }, undef, '... we added an attribute to Foo successfully' ); ::ok($meta->has_attribute('$foo'), '... Foo has $foo attribute'); ::is($meta->get_attribute('$foo'), $FOO_ATTR, '... got the right attribute back for Foo'); ::ok(!$meta->has_method('foo'), '... no accessor created'); - ::lives_ok { + ::is( ::exception { $meta->add_attribute($BAR_ATTR_2); - } '... we added an attribute to Foo successfully'; + }, undef, '... we added an attribute to Foo successfully' ); ::ok($meta->has_attribute('$bar'), '... Foo has $bar attribute'); ::is($meta->get_attribute('$bar'), $BAR_ATTR_2, '... got the right attribute back for Foo'); @@ -52,9 +52,9 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); our @ISA = ('Foo'); my $meta = Bar->meta; - ::lives_ok { + ::is( ::exception { $meta->add_attribute($BAR_ATTR); - } '... we added an attribute to Bar successfully'; + }, undef, '... we added an attribute to Bar successfully' ); ::ok($meta->has_attribute('$bar'), '... Bar has $bar attribute'); ::is($meta->get_attribute('$bar'), $BAR_ATTR, '... got the right attribute back for Bar'); @@ -70,9 +70,9 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); our @ISA = ('Bar'); my $meta = Baz->meta; - ::lives_ok { + ::is( ::exception { $meta->add_attribute($BAZ_ATTR); - } '... we added an attribute to Baz successfully'; + }, undef, '... we added an attribute to Baz successfully' ); ::ok($meta->has_attribute('$baz'), '... Baz has $baz attribute'); ::is($meta->get_attribute('$baz'), $BAZ_ATTR, '... got the right attribute back for Baz'); @@ -127,9 +127,9 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); '... got the right list of associated classes from the applicable attributes for Baz'); my $attr; - lives_ok { + is( exception { $attr = $meta->remove_attribute('$baz'); - } '... removed the $baz attribute successfully'; + }, undef, '... removed the $baz attribute successfully' ); is($attr, $BAZ_ATTR, '... got the right attribute back for Baz'); ok(!$meta->has_attribute('$baz'), '... Baz no longer has $baz attribute'); @@ -153,9 +153,9 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); { my $attr; - lives_ok { + is( exception { $attr = Bar->meta->remove_attribute('$bar'); - } '... removed the $bar attribute successfully'; + }, undef, '... removed the $bar attribute successfully' ); is($attr, $BAR_ATTR, '... got the right attribute back for Bar'); ok(!Bar->meta->has_attribute('$bar'), '... Bar no longer has $bar attribute'); @@ -178,9 +178,9 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); # remove attribute which is not there my $val; - lives_ok { + is( exception { $val = $meta->remove_attribute('$blammo'); - } '... attempted to remove the non-existent $blammo attribute'; + }, undef, '... attempted to remove the non-existent $blammo attribute' ); is($val, undef, '... got the right value back (undef)'); } @@ -191,11 +191,11 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); use Scalar::Util qw/blessed/; my $meta = Buzz->meta; - ::lives_ok { + ::is( ::exception { $meta->add_attribute($FOO_ATTR_2); - } '... we added an attribute to Buzz successfully'; + }, undef, '... we added an attribute to Buzz successfully' ); - ::lives_ok { + ::is( ::exception { $meta->add_attribute( Class::MOP::Attribute->new( '$bar' => ( @@ -205,9 +205,9 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); ) ) ); - } '... we added an attribute to Buzz successfully'; + }, undef, '... we added an attribute to Buzz successfully' ); - ::lives_ok { + ::is( ::exception { $meta->add_attribute( Class::MOP::Attribute->new( '$bah' => ( @@ -218,18 +218,18 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); ) ) ); - } '... we added an attribute to Buzz successfully'; + }, undef, '... we added an attribute to Buzz successfully' ); - ::lives_ok { + ::is( ::exception { $meta->add_method(build_foo => sub{ blessed shift; }); - } '... we added a method to Buzz successfully'; + }, undef, '... we added a method to Buzz successfully' ); } for(1 .. 2){ my $buzz; - ::lives_ok { $buzz = Buzz->meta->new_object } '...Buzz instantiated successfully'; + ::is( ::exception { $buzz = Buzz->meta->new_object }, undef, '...Buzz instantiated successfully' ); ::is($buzz->foo, 'Buzz', '...foo builder works as expected'); ::ok(!$buzz->has_bar, '...bar is not set'); ::is($buzz->bar, undef, '...bar returns undef'); @@ -242,17 +242,17 @@ for(1 .. 2){ ::ok(!$buzz->has_bar, '...bar is no longerset'); my $buzz2; - ::lives_ok { $buzz2 = Buzz->meta->new_object('$bar' => undef) } '...Buzz instantiated successfully'; + ::is( ::exception { $buzz2 = Buzz->meta->new_object('$bar' => undef) }, undef, '...Buzz instantiated successfully' ); ::ok($buzz2->has_bar, '...bar is set'); ::is($buzz2->bar, undef, '...bar is undef'); my $buzz3; - ::lives_ok { $buzz3 = Buzz->meta->new_object } '...Buzz instantiated successfully'; + ::is( ::exception { $buzz3 = Buzz->meta->new_object }, undef, '...Buzz instantiated successfully' ); ::ok($buzz3->has_bah, '...bah is set'); ::is($buzz3->bah, 'BAH', '...bah returns "BAH" '); my $buzz4; - ::lives_ok { $buzz4 = Buzz->meta->new_object('$bah' => undef) } '...Buzz instantiated successfully'; + ::is( ::exception { $buzz4 = Buzz->meta->new_object('$bah' => undef) }, undef, '...Buzz instantiated successfully' ); ::ok($buzz4->has_bah, '...bah is set'); ::is($buzz4->bah, undef, '...bah is undef'); diff --git a/t/006_new_and_clone_metaclasses.t b/t/006_new_and_clone_metaclasses.t index 6c2a21d..4b655ac 100644 --- a/t/006_new_and_clone_metaclasses.t +++ b/t/006_new_and_clone_metaclasses.t @@ -5,7 +5,7 @@ use FindBin; use File::Spec::Functions; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -100,9 +100,9 @@ isnt($cloned_foo, $foo, '... $cloned_foo is a new object different from $foo'); # check some errors -dies_ok { +isnt( exception { $foo_meta->clone_object($meta); -} '... this dies as expected'; +}, undef, '... this dies as expected' ); # test stuff diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index 207f94f..d16e252 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; use Class::MOP::Class; diff --git a/t/011_create_class.t b/t/011_create_class.t index 2267b5e..63a31d4 100644 --- a/t/011_create_class.t +++ b/t/011_create_class.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -73,9 +73,9 @@ is($point->y, 42, '... the y attribute was set properly with the accessor'); is($point->x, 2, '... the x attribute was initialized correctly through the metaobject'); -dies_ok { +isnt( exception { $point->x(42); -} '... cannot write to a read-only accessor'; +}, undef, '... cannot write to a read-only accessor' ); is($point->x, 2, '... the x attribute was not altered'); $point->clear(); diff --git a/t/012_package_variables.t b/t/012_package_variables.t index 98d62cf..bcf960a 100644 --- a/t/012_package_variables.t +++ b/t/012_package_variables.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -24,9 +24,9 @@ we call all the methods through Class::MOP::Class. ok(!defined($Foo::{foo}), '... the %foo slot has not been created yet'); ok(!Foo->meta->has_package_symbol('%foo'), '... the meta agrees'); -lives_ok { +is( exception { Foo->meta->add_package_symbol('%foo' => { one => 1 }); -} '... created %Foo::foo successfully'; +}, undef, '... created %Foo::foo successfully' ); # ... scalar should NOT be created here @@ -65,9 +65,9 @@ $foo->{two} = 2; ok(!defined($Foo::{bar}), '... the @bar slot has not been created yet'); -lives_ok { +is( exception { Foo->meta->add_package_symbol('@bar' => [ 1, 2, 3 ]); -} '... created @Foo::bar successfully'; +}, undef, '... created @Foo::bar successfully' ); ok(defined($Foo::{bar}), '... the @bar slot was created successfully'); ok(Foo->meta->has_package_symbol('@bar'), '... the meta agrees'); @@ -91,9 +91,9 @@ ok(!Foo->meta->has_package_symbol('&bar'), '... CODE shouldnt have been created ok(!defined($Foo::{baz}), '... the $baz slot has not been created yet'); -lives_ok { +is( exception { Foo->meta->add_package_symbol('$baz' => 10); -} '... created $Foo::baz successfully'; +}, undef, '... created $Foo::baz successfully' ); ok(defined($Foo::{baz}), '... the $baz slot was created successfully'); ok(Foo->meta->has_package_symbol('$baz'), '... the meta agrees'); @@ -117,9 +117,9 @@ is(${Foo->meta->get_package_symbol('$baz')}, 10, '... got the right value back') ok(!defined($Foo::{funk}), '... the &funk slot has not been created yet'); -lives_ok { +is( exception { Foo->meta->add_package_symbol('&funk' => sub { "Foo::funk" }); -} '... created &Foo::funk successfully'; +}, undef, '... created &Foo::funk successfully' ); ok(defined($Foo::{funk}), '... the &funk slot was created successfully'); ok(Foo->meta->has_package_symbol('&funk'), '... the meta agrees'); @@ -141,23 +141,23 @@ is(Foo->funk(), 'Foo::funk', '... got the right value from the function'); my $ARRAY = [ 1, 2, 3 ]; my $CODE = sub { "Foo::foo" }; -lives_ok { +is( exception { Foo->meta->add_package_symbol('@foo' => $ARRAY); -} '... created @Foo::foo successfully'; +}, undef, '... created @Foo::foo successfully' ); ok(Foo->meta->has_package_symbol('@foo'), '... the @foo slot was added successfully'); is(Foo->meta->get_package_symbol('@foo'), $ARRAY, '... got the right values for @Foo::foo'); -lives_ok { +is( exception { Foo->meta->add_package_symbol('&foo' => $CODE); -} '... created &Foo::foo successfully'; +}, undef, '... created &Foo::foo successfully' ); ok(Foo->meta->has_package_symbol('&foo'), '... the meta agrees'); is(Foo->meta->get_package_symbol('&foo'), $CODE, '... got the right value for &Foo::foo'); -lives_ok { +is( exception { Foo->meta->add_package_symbol('$foo' => 'Foo::foo'); -} '... created $Foo::foo successfully'; +}, undef, '... created $Foo::foo successfully' ); ok(Foo->meta->has_package_symbol('$foo'), '... the meta agrees'); my $SCALAR = Foo->meta->get_package_symbol('$foo'); @@ -168,9 +168,9 @@ is($$SCALAR, 'Foo::foo', '... got the right scalar value back'); is(${'Foo::foo'}, 'Foo::foo', '... got the right value from the scalar'); } -lives_ok { +is( exception { Foo->meta->remove_package_symbol('%foo'); -} '... removed %Foo::foo successfully'; +}, undef, '... removed %Foo::foo successfully' ); ok(!Foo->meta->has_package_symbol('%foo'), '... the %foo slot was removed successfully'); ok(Foo->meta->has_package_symbol('@foo'), '... the @foo slot still exists'); @@ -189,9 +189,9 @@ is(Foo->meta->get_package_symbol('$foo'), $SCALAR, '... got the right value for ok(defined(${"Foo::foo"}), '... the $foo slot has NOT been removed'); } -lives_ok { +is( exception { Foo->meta->remove_package_symbol('&foo'); -} '... removed &Foo::foo successfully'; +}, undef, '... removed &Foo::foo successfully' ); ok(!Foo->meta->has_package_symbol('&foo'), '... the &foo slot no longer exists'); @@ -209,9 +209,9 @@ is(Foo->meta->get_package_symbol('$foo'), $SCALAR, '... got the right value for ok(defined(${"Foo::foo"}), '... the $foo slot has NOT been removed'); } -lives_ok { +is( exception { Foo->meta->remove_package_symbol('$foo'); -} '... removed $Foo::foo successfully'; +}, undef, '... removed $Foo::foo successfully' ); ok(!Foo->meta->has_package_symbol('$foo'), '... the $foo slot no longer exists'); diff --git a/t/013_add_attribute_alternate.t b/t/013_add_attribute_alternate.t index 4cfb338..f7ecde1 100644 --- a/t/013_add_attribute_alternate.t +++ b/t/013_add_attribute_alternate.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -69,9 +69,9 @@ is($point->y, 42, '... the y attribute was set properly with the accessor'); is($point->x, 2, '... the x attribute was initialized correctly through the metaobject'); -dies_ok { +isnt( exception { $point->x(42); -} '... cannot write to a read-only accessor'; +}, undef, '... cannot write to a read-only accessor' ); is($point->x, 2, '... the x attribute was not altered'); $point->clear(); diff --git a/t/014_attribute_introspection.t b/t/014_attribute_introspection.t index 7b77803..112b9c0 100644 --- a/t/014_attribute_introspection.t +++ b/t/014_attribute_introspection.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; diff --git a/t/015_metaclass_inheritance.t b/t/015_metaclass_inheritance.t index fc784c5..49a5298 100644 --- a/t/015_metaclass_inheritance.t +++ b/t/015_metaclass_inheritance.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; diff --git a/t/016_class_errors_and_edge_cases.t b/t/016_class_errors_and_edge_cases.t index 18429c5..36a1ac4 100644 --- a/t/016_class_errors_and_edge_cases.t +++ b/t/016_class_errors_and_edge_cases.t @@ -2,175 +2,175 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; { - dies_ok { + isnt( exception { Class::MOP::Class->initialize(); - } '... initialize requires a name parameter'; + }, undef, '... initialize requires a name parameter' ); - dies_ok { + isnt( exception { Class::MOP::Class->initialize(''); - } '... initialize requires a name valid parameter'; + }, undef, '... initialize requires a name valid parameter' ); - dies_ok { + isnt( exception { Class::MOP::Class->initialize(bless {} => 'Foo'); - } '... initialize requires an unblessed parameter' + }, undef, '... initialize requires an unblessed parameter' ); } { - dies_ok { + isnt( exception { Class::MOP::Class->_construct_class_instance(); - } '... _construct_class_instance requires an :package parameter'; + }, undef, '... _construct_class_instance requires an :package parameter' ); - dies_ok { + isnt( exception { Class::MOP::Class->_construct_class_instance(':package' => undef); - } '... _construct_class_instance requires a defined :package parameter'; + }, undef, '... _construct_class_instance requires a defined :package parameter' ); - dies_ok { + isnt( exception { Class::MOP::Class->_construct_class_instance(':package' => ''); - } '... _construct_class_instance requires a valid :package parameter'; + }, undef, '... _construct_class_instance requires a valid :package parameter' ); } { - dies_ok { + isnt( exception { Class::MOP::Class->create(); - } '... create requires an package_name parameter'; + }, undef, '... create requires an package_name parameter' ); - dies_ok { + isnt( exception { Class::MOP::Class->create(undef); - } '... create requires a defined package_name parameter'; + }, undef, '... create requires a defined package_name parameter' ); - dies_ok { + isnt( exception { Class::MOP::Class->create(''); - } '... create requires a valid package_name parameter'; + }, undef, '... create requires a valid package_name parameter' ); - throws_ok { + like( exception { Class::MOP::Class->create('+++'); - } qr/^creation of \+\+\+ failed/, '... create requires a valid package_name parameter'; + }, qr/^creation of \+\+\+ failed/, '... create requires a valid package_name parameter' ); } { - dies_ok { + isnt( exception { Class::MOP::Class->clone_object(1); - } '... can only clone instances'; + }, undef, '... can only clone instances' ); } { - dies_ok { + isnt( exception { Class::MOP::Class->add_method(); - } '... add_method dies as expected'; + }, undef, '... add_method dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->add_method(''); - } '... add_method dies as expected'; + }, undef, '... add_method dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->add_method('foo' => 'foo'); - } '... add_method dies as expected'; + }, undef, '... add_method dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->add_method('foo' => []); - } '... add_method dies as expected'; + }, undef, '... add_method dies as expected' ); } { - dies_ok { + isnt( exception { Class::MOP::Class->has_method(); - } '... has_method dies as expected'; + }, undef, '... has_method dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->has_method(''); - } '... has_method dies as expected'; + }, undef, '... has_method dies as expected' ); } { - dies_ok { + isnt( exception { Class::MOP::Class->get_method(); - } '... get_method dies as expected'; + }, undef, '... get_method dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->get_method(''); - } '... get_method dies as expected'; + }, undef, '... get_method dies as expected' ); } { - dies_ok { + isnt( exception { Class::MOP::Class->remove_method(); - } '... remove_method dies as expected'; + }, undef, '... remove_method dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->remove_method(''); - } '... remove_method dies as expected'; + }, undef, '... remove_method dies as expected' ); } { - dies_ok { + isnt( exception { Class::MOP::Class->find_all_methods_by_name(); - } '... find_all_methods_by_name dies as expected'; + }, undef, '... find_all_methods_by_name dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->find_all_methods_by_name(''); - } '... find_all_methods_by_name dies as expected'; + }, undef, '... find_all_methods_by_name dies as expected' ); } { - dies_ok { + isnt( exception { Class::MOP::Class->add_attribute(bless {} => 'Foo'); - } '... add_attribute dies as expected'; + }, undef, '... add_attribute dies as expected' ); } { - dies_ok { + isnt( exception { Class::MOP::Class->has_attribute(); - } '... has_attribute dies as expected'; + }, undef, '... has_attribute dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->has_attribute(''); - } '... has_attribute dies as expected'; + }, undef, '... has_attribute dies as expected' ); } { - dies_ok { + isnt( exception { Class::MOP::Class->get_attribute(); - } '... get_attribute dies as expected'; + }, undef, '... get_attribute dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->get_attribute(''); - } '... get_attribute dies as expected'; + }, undef, '... get_attribute dies as expected' ); } { - dies_ok { + isnt( exception { Class::MOP::Class->remove_attribute(); - } '... remove_attribute dies as expected'; + }, undef, '... remove_attribute dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->remove_attribute(''); - } '... remove_attribute dies as expected'; + }, undef, '... remove_attribute dies as expected' ); } { - dies_ok { + isnt( exception { Class::MOP::Class->add_package_symbol(); - } '... add_package_symbol dies as expected'; + }, undef, '... add_package_symbol dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->add_package_symbol(''); - } '... add_package_symbol dies as expected'; + }, undef, '... add_package_symbol dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->add_package_symbol('foo'); - } '... add_package_symbol dies as expected'; + }, undef, '... add_package_symbol dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->add_package_symbol('&foo'); - } '... add_package_symbol dies as expected'; + }, undef, '... add_package_symbol dies as expected' ); # throws_ok { # Class::MOP::Class->meta->add_package_symbol('@-'); @@ -179,45 +179,45 @@ use Class::MOP; } { - dies_ok { + isnt( exception { Class::MOP::Class->has_package_symbol(); - } '... has_package_symbol dies as expected'; + }, undef, '... has_package_symbol dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->has_package_symbol(''); - } '... has_package_symbol dies as expected'; + }, undef, '... has_package_symbol dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->has_package_symbol('foo'); - } '... has_package_symbol dies as expected'; + }, undef, '... has_package_symbol dies as expected' ); } { - dies_ok { + isnt( exception { Class::MOP::Class->get_package_symbol(); - } '... get_package_symbol dies as expected'; + }, undef, '... get_package_symbol dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->get_package_symbol(''); - } '... get_package_symbol dies as expected'; + }, undef, '... get_package_symbol dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->get_package_symbol('foo'); - } '... get_package_symbol dies as expected'; + }, undef, '... get_package_symbol dies as expected' ); } { - dies_ok { + isnt( exception { Class::MOP::Class->remove_package_symbol(); - } '... remove_package_symbol dies as expected'; + }, undef, '... remove_package_symbol dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->remove_package_symbol(''); - } '... remove_package_symbol dies as expected'; + }, undef, '... remove_package_symbol dies as expected' ); - dies_ok { + isnt( exception { Class::MOP::Class->remove_package_symbol('foo'); - } '... remove_package_symbol dies as expected'; + }, undef, '... remove_package_symbol dies as expected' ); } done_testing; diff --git a/t/017_add_method_modifier.t b/t/017_add_method_modifier.t index a9c7945..03ba641 100644 --- a/t/017_add_method_modifier.t +++ b/t/017_add_method_modifier.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -65,11 +65,11 @@ use Class::MOP; } ); - ::throws_ok( - sub { - CheckingAccount->meta->add_before_method_modifier( - 'does_not_exist' => sub { } ); - }, + ::like( + ::exception{ CheckingAccount->meta->add_before_method_modifier( + 'does_not_exist' => sub { } + ); + }, qr/\QThe method 'does_not_exist' was not found in the inheritance hierarchy for CheckingAccount/ ); @@ -90,16 +90,14 @@ my $savings_account = BankAccount->new( balance => 250 ); isa_ok( $savings_account, 'BankAccount' ); is( $savings_account->balance, 250, '... got the right savings balance' ); -lives_ok { +is( exception { $savings_account->withdraw(50); -} -'... withdrew from savings successfully'; +}, undef, '... withdrew from savings successfully' ); is( $savings_account->balance, 200, '... got the right savings balance after withdrawal' ); -dies_ok { +isnt( exception { $savings_account->withdraw(250); -} -'... could not withdraw from savings successfully'; +}, undef, '... could not withdraw from savings successfully' ); $savings_account->deposit(150); is( $savings_account->balance, 350, @@ -117,20 +115,18 @@ is( $checking_account->overdraft_account, $savings_account, is( $checking_account->balance, 100, '... got the right checkings balance' ); -lives_ok { +is( exception { $checking_account->withdraw(50); -} -'... withdrew from checking successfully'; +}, undef, '... withdrew from checking successfully' ); is( $checking_account->balance, 50, '... got the right checkings balance after withdrawal' ); is( $savings_account->balance, 350, '... got the right savings balance after checking withdrawal (no overdraft)' ); -lives_ok { +is( exception { $checking_account->withdraw(200); -} -'... withdrew from checking successfully'; +}, undef, '... withdrew from checking successfully' ); is( $checking_account->balance, 0, '... got the right checkings balance after withdrawal' ); is( $savings_account->balance, 200, diff --git a/t/018_anon_class.t b/t/018_anon_class.t index d314e7a..1b06879 100644 --- a/t/018_anon_class.t +++ b/t/018_anon_class.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -31,18 +31,18 @@ my $anon_class_id; [$anon_class->superclasses], [], '... got an empty superclass list'); - lives_ok { + is( exception { $anon_class->superclasses('Foo'); - } '... can add a superclass to anon class'; + }, undef, '... can add a superclass to anon class' ); is_deeply( [$anon_class->superclasses], [ 'Foo' ], '... got the right superclass list'); ok(!$anon_class->has_method('foo'), '... no foo method'); - lives_ok { + is( exception { $anon_class->add_method('foo' => sub { "__ANON__::foo" }); - } '... added a method to my anon-class'; + }, undef, '... added a method to my anon-class' ); ok($anon_class->has_method('foo'), '... we have a foo method now'); $instance = $anon_class->new_object(); diff --git a/t/019_anon_class_keep_alive.t b/t/019_anon_class_keep_alive.t index 17aedac..4963a56 100644 --- a/t/019_anon_class_keep_alive.t +++ b/t/019_anon_class_keep_alive.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; diff --git a/t/020_attribute.t b/t/020_attribute.t index 48ddbf9..f23a434 100644 --- a/t/020_attribute.t +++ b/t/020_attribute.t @@ -4,14 +4,14 @@ use warnings; use Scalar::Util 'reftype', 'blessed'; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; use Class::MOP::Attribute; use Class::MOP::Method; -dies_ok { Class::MOP::Attribute->name } q{... can't call name() as a class method}; +isnt( exception { Class::MOP::Attribute->name }, undef, q{... can't call name() as a class method} ); { @@ -42,9 +42,9 @@ dies_ok { Class::MOP::Attribute->name } q{... can't call name() as a class metho my $class = Class::MOP::Class->initialize('Foo'); isa_ok($class, 'Class::MOP::Class'); - lives_ok { + is( exception { $attr->attach_to_class($class); - } '... attached a class successfully'; + }, undef, '... attached a class successfully' ); is($attr->associated_class, $class, '... the class was associated correctly'); @@ -229,18 +229,18 @@ dies_ok { Class::MOP::Attribute->name } q{... can't call name() as a class metho { for my $value ({}, bless({}, 'Foo')) { - throws_ok { + like( exception { Class::MOP::Attribute->new('$foo', default => $value); - } qr/References are not allowed as default values/; + }, qr/References are not allowed as default values/ ); } } { my $attr; - lives_ok { + is( exception { my $meth = Class::MOP::Method->wrap(sub {shift}, name => 'foo', package_name => 'bar'); $attr = Class::MOP::Attribute->new('$foo', default => $meth); - } 'Class::MOP::Methods accepted as default'; + }, undef, 'Class::MOP::Methods accepted as default' ); is($attr->default(42), 42, 'passthrough for default on attribute'); } diff --git a/t/021_attribute_errors_and_edge_cases.t b/t/021_attribute_errors_and_edge_cases.t index d00d4c3..e4a87d6 100644 --- a/t/021_attribute_errors_and_edge_cases.t +++ b/t/021_attribute_errors_and_edge_cases.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; use Class::MOP::Attribute; @@ -10,84 +10,84 @@ use Class::MOP::Attribute; # most values are static { - dies_ok { + isnt( exception { Class::MOP::Attribute->new('$test' => ( default => qr/hello (.*)/ )); - } '... no refs for defaults'; + }, undef, '... no refs for defaults' ); - dies_ok { + isnt( exception { Class::MOP::Attribute->new('$test' => ( default => [] )); - } '... no refs for defaults'; + }, undef, '... no refs for defaults' ); - dies_ok { + isnt( exception { Class::MOP::Attribute->new('$test' => ( default => {} )); - } '... no refs for defaults'; + }, undef, '... no refs for defaults' ); - dies_ok { + isnt( exception { Class::MOP::Attribute->new('$test' => ( default => \(my $var) )); - } '... no refs for defaults'; + }, undef, '... no refs for defaults' ); - dies_ok { + isnt( exception { Class::MOP::Attribute->new('$test' => ( default => bless {} => 'Foo' )); - } '... no refs for defaults'; + }, undef, '... no refs for defaults' ); } { - dies_ok { + isnt( exception { Class::MOP::Attribute->new('$test' => ( builder => qr/hello (.*)/ )); - } '... no refs for builders'; + }, undef, '... no refs for builders' ); - dies_ok { + isnt( exception { Class::MOP::Attribute->new('$test' => ( builder => [] )); - } '... no refs for builders'; + }, undef, '... no refs for builders' ); - dies_ok { + isnt( exception { Class::MOP::Attribute->new('$test' => ( builder => {} )); - } '... no refs for builders'; + }, undef, '... no refs for builders' ); - dies_ok { + isnt( exception { Class::MOP::Attribute->new('$test' => ( builder => \(my $var) )); - } '... no refs for builders'; + }, undef, '... no refs for builders' ); - dies_ok { + isnt( exception { Class::MOP::Attribute->new('$test' => ( builder => bless {} => 'Foo' )); - } '... no refs for builders'; + }, undef, '... no refs for builders' ); - dies_ok { + isnt( exception { Class::MOP::Attribute->new('$test' => ( builder => 'Foo', default => 'Foo' )); - } '... no default AND builder'; + }, undef, '... no default AND builder' ); my $undef_attr; - lives_ok { + is( exception { $undef_attr = Class::MOP::Attribute->new('$test' => ( default => undef, predicate => 'has_test', )); - } '... undef as a default is okay'; + }, undef, '... undef as a default is okay' ); ok($undef_attr->has_default, '... and it counts as an actual default'); ok(!Class::MOP::Attribute->new('$test')->has_default, '... but attributes with no default have no default'); @@ -101,8 +101,7 @@ use Class::MOP::Attribute; ok($obj->has_test, '... and the default is populated'); is($obj->meta->get_attribute('$test')->get_value($obj), undef, '... with the right value'); } - lives_ok { Foo->meta->make_immutable } - '... and it can be inlined'; + is( exception { Foo->meta->make_immutable }, undef, '... and it can be inlined' ); { my $obj = Foo->new; ok($obj->has_test, '... and the default is populated'); @@ -113,33 +112,33 @@ use Class::MOP::Attribute; { # bad construtor args - dies_ok { + isnt( exception { Class::MOP::Attribute->new(); - } '... no name argument'; + }, undef, '... no name argument' ); # These are no longer errors - lives_ok { + is( exception { Class::MOP::Attribute->new(''); - } '... bad name argument'; + }, undef, '... bad name argument' ); - lives_ok { + is( exception { Class::MOP::Attribute->new(0); - } '... bad name argument'; + }, undef, '... bad name argument' ); } { my $attr = Class::MOP::Attribute->new('$test'); - dies_ok { + isnt( exception { $attr->attach_to_class(); - } '... attach_to_class died as expected'; + }, undef, '... attach_to_class died as expected' ); - dies_ok { + isnt( exception { $attr->attach_to_class('Fail'); - } '... attach_to_class died as expected'; + }, undef, '... attach_to_class died as expected' ); - dies_ok { + isnt( exception { $attr->attach_to_class(bless {} => 'Fail'); - } '... attach_to_class died as expected'; + }, undef, '... attach_to_class died as expected' ); } { @@ -149,17 +148,17 @@ use Class::MOP::Attribute; $attr->attach_to_class(Class::MOP::Class->initialize('Foo')); - dies_ok { + isnt( exception { $attr->install_accessors; - } '... bad reader format'; + }, undef, '... bad reader format' ); } { my $attr = Class::MOP::Attribute->new('$test'); - dies_ok { + isnt( exception { $attr->_process_accessors('fail', 'my_failing_sub'); - } '... cannot find "fail" type generator'; + }, undef, '... cannot find "fail" type generator' ); } @@ -174,9 +173,9 @@ use Class::MOP::Attribute; reader => 'test' )); - dies_ok { + isnt( exception { $attr->install_accessors; - } '... failed to generate accessors correctly'; + }, undef, '... failed to generate accessors correctly' ); } { @@ -207,27 +206,27 @@ use Class::MOP::Attribute; # it works, which is kinda silly, but it # tests the API change, so I keep it. - lives_ok { + is( exception { Class::MOP::Attribute->new('$foo', ( accessor => 'foo', reader => 'get_foo', )); - } '... can create accessors with reader/writers'; + }, undef, '... can create accessors with reader/writers' ); - lives_ok { + is( exception { Class::MOP::Attribute->new('$foo', ( accessor => 'foo', writer => 'set_foo', )); - } '... can create accessors with reader/writers'; + }, undef, '... can create accessors with reader/writers' ); - lives_ok { + is( exception { Class::MOP::Attribute->new('$foo', ( accessor => 'foo', reader => 'get_foo', writer => 'set_foo', )); - } '... can create accessors with reader/writers'; + }, undef, '... can create accessors with reader/writers' ); } done_testing; diff --git a/t/030_method.t b/t/030_method.t index 89605f0..f70df12 100644 --- a/t/030_method.t +++ b/t/030_method.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; use Class::MOP::Method; @@ -28,21 +28,14 @@ is( $method->original_fully_qualified_name, 'main::__ANON__', '... the original_fully_qualified_name is the same as fully_qualified_name' ); -dies_ok { Class::MOP::Method->wrap } -q{... can't call wrap() without some code}; -dies_ok { Class::MOP::Method->wrap( [] ) } -q{... can't call wrap() without some code}; -dies_ok { Class::MOP::Method->wrap( bless {} => 'Fail' ) } -q{... can't call wrap() without some code}; - -dies_ok { Class::MOP::Method->name } -q{... can't call name() as a class method}; -dies_ok { Class::MOP::Method->body } -q{... can't call body() as a class method}; -dies_ok { Class::MOP::Method->package_name } -q{... can't call package_name() as a class method}; -dies_ok { Class::MOP::Method->fully_qualified_name } -q{... can't call fully_qualified_name() as a class method}; +isnt( exception { Class::MOP::Method->wrap }, undef, q{... can't call wrap() without some code} ); +isnt( exception { Class::MOP::Method->wrap( [] ) }, undef, q{... can't call wrap() without some code} ); +isnt( exception { Class::MOP::Method->wrap( bless {} => 'Fail' ) }, undef, q{... can't call wrap() without some code} ); + +isnt( exception { Class::MOP::Method->name }, undef, q{... can't call name() as a class method} ); +isnt( exception { Class::MOP::Method->body }, undef, q{... can't call body() as a class method} ); +isnt( exception { Class::MOP::Method->package_name }, undef, q{... can't call package_name() as a class method} ); +isnt( exception { Class::MOP::Method->fully_qualified_name }, undef, q{... can't call fully_qualified_name() as a class method} ); my $meta = Class::MOP::Method->meta; isa_ok( $meta, 'Class::MOP::Class' ); @@ -63,41 +56,34 @@ foreach my $method_name ( '... our sub name is "' . $method_name . '"' ); } -dies_ok { +isnt( exception { Class::MOP::Method->wrap(); -} -'... bad args for &wrap'; +}, undef, '... bad args for &wrap' ); -dies_ok { +isnt( exception { Class::MOP::Method->wrap('Fail'); -} -'... bad args for &wrap'; +}, undef, '... bad args for &wrap' ); -dies_ok { +isnt( exception { Class::MOP::Method->wrap( [] ); -} -'... bad args for &wrap'; +}, undef, '... bad args for &wrap' ); -dies_ok { +isnt( exception { Class::MOP::Method->wrap( sub {'FAIL'} ); -} -'... bad args for &wrap'; +}, undef, '... bad args for &wrap' ); -dies_ok { +isnt( exception { Class::MOP::Method->wrap( sub {'FAIL'}, package_name => 'main' ); -} -'... bad args for &wrap'; +}, undef, '... bad args for &wrap' ); -dies_ok { +isnt( exception { Class::MOP::Method->wrap( sub {'FAIL'}, name => '__ANON__' ); -} -'... bad args for &wrap'; +}, undef, '... bad args for &wrap' ); -lives_ok { +is( exception { Class::MOP::Method->wrap( bless( sub {'FAIL'}, "Foo" ), name => '__ANON__', package_name => 'Foo::Bar' ); -} -'... blessed coderef to &wrap'; +}, undef, '... blessed coderef to &wrap' ); my $clone = $method->clone( package_name => 'NewPackage', diff --git a/t/031_method_modifiers.t b/t/031_method_modifiers.t index ee5abf6..cb7078d 100644 --- a/t/031_method_modifiers.t +++ b/t/031_method_modifiers.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; use Class::MOP::Method; @@ -31,10 +31,9 @@ use Class::MOP::Method; '... got the right return value from the wrapped method' ); $trace = ''; - lives_ok { + is( exception { $wrapped->add_before_modifier( sub { $trace .= 'before -> ' } ); - } - '... added the before modifier okay'; + }, undef, '... added the before modifier okay' ); $wrapped->(); is( $trace, 'before -> primary', @@ -42,10 +41,9 @@ use Class::MOP::Method; ); $trace = ''; - lives_ok { + is( exception { $wrapped->add_after_modifier( sub { $trace .= ' -> after' } ); - } - '... added the after modifier okay'; + }, undef, '... added the after modifier okay' ); $wrapped->(); is( $trace, 'before -> primary -> after', @@ -71,13 +69,12 @@ use Class::MOP::Method; is( $wrapped->(), 4, '... got the right value from the wrapped method' ); - lives_ok { + is( exception { $wrapped->add_around_modifier( sub { ( 3, $_[0]->() ) } ); $wrapped->add_around_modifier( sub { ( 2, $_[0]->() ) } ); $wrapped->add_around_modifier( sub { ( 1, $_[0]->() ) } ); $wrapped->add_around_modifier( sub { ( 0, $_[0]->() ) } ); - } - '... added the around modifier okay'; + }, undef, '... added the around modifier okay' ); is_deeply( [ $wrapped->() ], @@ -104,29 +101,26 @@ use Class::MOP::Method; isa_ok( $wrapped, 'Class::MOP::Method::Wrapped' ); isa_ok( $wrapped, 'Class::MOP::Method' ); - lives_ok { + is( exception { $wrapped->add_before_modifier( sub { push @tracelog => 'before 1' } ); $wrapped->add_before_modifier( sub { push @tracelog => 'before 2' } ); $wrapped->add_before_modifier( sub { push @tracelog => 'before 3' } ); - } - '... added the before modifier okay'; + }, undef, '... added the before modifier okay' ); - lives_ok { + is( exception { $wrapped->add_around_modifier( sub { push @tracelog => 'around 1'; $_[0]->(); } ); $wrapped->add_around_modifier( sub { push @tracelog => 'around 2'; $_[0]->(); } ); $wrapped->add_around_modifier( sub { push @tracelog => 'around 3'; $_[0]->(); } ); - } - '... added the around modifier okay'; + }, undef, '... added the around modifier okay' ); - lives_ok { + is( exception { $wrapped->add_after_modifier( sub { push @tracelog => 'after 1' } ); $wrapped->add_after_modifier( sub { push @tracelog => 'after 2' } ); $wrapped->add_after_modifier( sub { push @tracelog => 'after 3' } ); - } - '... added the after modifier okay'; + }, undef, '... added the after modifier okay' ); $wrapped->(); is_deeply( diff --git a/t/041_metaclass_incompatibility.t b/t/041_metaclass_incompatibility.t index 5b0223f..5148c29 100644 --- a/t/041_metaclass_incompatibility.t +++ b/t/041_metaclass_incompatibility.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use metaclass; @@ -32,79 +32,79 @@ for my $suffix ('Class', keys %metaclass_attrs) { # checking... -lives_ok { +is( exception { Foo::Meta::Class->create('Foo') -} '... Foo.meta => Foo::Meta::Class is compatible'; -lives_ok { +}, undef, '... Foo.meta => Foo::Meta::Class is compatible' ); +is( exception { Bar::Meta::Class->create('Bar') -} '... Bar.meta => Bar::Meta::Class is compatible'; +}, undef, '... Bar.meta => Bar::Meta::Class is compatible' ); -throws_ok { +like( exception { Bar::Meta::Class->create('Foo::Foo', superclasses => ['Foo']) -} qr/compatible/, '... Foo::Foo.meta => Bar::Meta::Class is not compatible'; -throws_ok { +}, qr/compatible/, '... Foo::Foo.meta => Bar::Meta::Class is not compatible' ); +like( exception { Foo::Meta::Class->create('Bar::Bar', superclasses => ['Bar']) -} qr/compatible/, '... Bar::Bar.meta => Foo::Meta::Class is not compatible'; +}, qr/compatible/, '... Bar::Bar.meta => Foo::Meta::Class is not compatible' ); -lives_ok { +is( exception { FooBar::Meta::Class->create('FooBar', superclasses => ['Foo']) -} '... FooBar.meta => FooBar::Meta::Class is compatible'; -lives_ok { +}, undef, '... FooBar.meta => FooBar::Meta::Class is compatible' ); +is( exception { FooBar::Meta::Class->create('FooBar2', superclasses => ['Bar']) -} '... FooBar2.meta => FooBar::Meta::Class is compatible'; +}, undef, '... FooBar2.meta => FooBar::Meta::Class is compatible' ); Foo::Meta::Class->create( 'Foo::All', map { $metaclass_attrs{$_} => "Foo::Meta::$_" } keys %metaclass_attrs, ); -throws_ok { +like( exception { Bar::Meta::Class->create( 'Foo::All::Sub::Class', superclasses => ['Foo::All'], map { $metaclass_attrs{$_} => "Foo::Meta::$_" } keys %metaclass_attrs, ) -} qr/compatible/, 'incompatible Class metaclass'; +}, qr/compatible/, 'incompatible Class metaclass' ); for my $suffix (keys %metaclass_attrs) { - throws_ok { + like( exception { Foo::Meta::Class->create( "Foo::All::Sub::$suffix", superclasses => ['Foo::All'], (map { $metaclass_attrs{$_} => "Foo::Meta::$_" } keys %metaclass_attrs), $metaclass_attrs{$suffix} => "Bar::Meta::$suffix", ) - } qr/compatible/, "incompatible $suffix metaclass"; + }, qr/compatible/, "incompatible $suffix metaclass" ); } # fixing... -lives_ok { +is( exception { Class::MOP::Class->create('Foo::Foo::CMOP', superclasses => ['Foo']) -} 'metaclass fixing fixes a cmop metaclass, when the parent has a subclass'; +}, undef, 'metaclass fixing fixes a cmop metaclass, when the parent has a subclass' ); isa_ok(Foo::Foo::CMOP->meta, 'Foo::Meta::Class'); -lives_ok { +is( exception { Class::MOP::Class->create('Bar::Bar::CMOP', superclasses => ['Bar']) -} 'metaclass fixing fixes a cmop metaclass, when the parent has a subclass'; +}, undef, 'metaclass fixing fixes a cmop metaclass, when the parent has a subclass' ); isa_ok(Bar::Bar::CMOP->meta, 'Bar::Meta::Class'); -lives_ok { +is( exception { Class::MOP::Class->create( 'Foo::All::Sub::CMOP::Class', superclasses => ['Foo::All'], map { $metaclass_attrs{$_} => "Foo::Meta::$_" } keys %metaclass_attrs, ) -} 'metaclass fixing works with other non-default metaclasses'; +}, undef, 'metaclass fixing works with other non-default metaclasses' ); isa_ok(Foo::All::Sub::CMOP::Class->meta, 'Foo::Meta::Class'); for my $suffix (keys %metaclass_attrs) { - lives_ok { + is( exception { Foo::Meta::Class->create( "Foo::All::Sub::CMOP::$suffix", superclasses => ['Foo::All'], (map { $metaclass_attrs{$_} => "Foo::Meta::$_" } keys %metaclass_attrs), $metaclass_attrs{$suffix} => "Class::MOP::$suffix", ) - } "$metaclass_attrs{$suffix} fixing works with other non-default metaclasses"; + }, undef, "$metaclass_attrs{$suffix} fixing works with other non-default metaclasses" ); for my $suffix2 (keys %metaclass_attrs) { my $method = $metaclass_attrs{$suffix2}; isa_ok("Foo::All::Sub::CMOP::$suffix"->meta->$method, "Foo::Meta::$suffix2"); @@ -188,9 +188,7 @@ isa_ok(Class::MOP::class_of('Foo::Reverse::Sub::Sub'), 'Foo::Meta::Class'); 'Foo::Unsafe::Sub', ); $meta->add_attribute(foo => reader => 'foo'); - throws_ok { $meta->superclasses('Foo::Unsafe') } - qr/compatibility.*pristine/, - "can't switch out the attribute metaclass of a class that already has attributes"; + like( exception { $meta->superclasses('Foo::Unsafe') }, qr/compatibility.*pristine/, "can't switch out the attribute metaclass of a class that already has attributes" ); } # immutability... @@ -207,11 +205,10 @@ isa_ok(Class::MOP::class_of('Foo::Reverse::Sub::Sub'), 'Foo::Meta::Class'); 'Baz::Mutable', ); $bazmeta->superclasses($foometa->name); - lives_ok { $bazmeta->superclasses($barmeta->name) } - "can still set superclasses"; + is( exception { $bazmeta->superclasses($barmeta->name) }, undef, "can still set superclasses" ); ok(!$bazmeta->is_immutable, "immutable superclass doesn't make this class immutable"); - lives_ok { $bazmeta->make_immutable } "can still make immutable"; + is( exception { $bazmeta->make_immutable }, undef, "can still make immutable" ); } # nonexistent metaclasses @@ -221,37 +218,37 @@ Class::MOP::Class->create( superclasses => ['Class::MOP::Method'], ); -lives_ok { +is( exception { Class::MOP::Class->create( 'Weird::Class', destructor_class => 'Weird::Meta::Method::Destructor', ); -} "defined metaclass in child with defined metaclass in parent is fine"; +}, undef, "defined metaclass in child with defined metaclass in parent is fine" ); is(Weird::Class->meta->destructor_class, 'Weird::Meta::Method::Destructor', "got the right destructor class"); -lives_ok { +is( exception { Class::MOP::Class->create( 'Weird::Class::Sub', superclasses => ['Weird::Class'], destructor_class => undef, ); -} "undef metaclass in child with defined metaclass in parent can be fixed"; +}, undef, "undef metaclass in child with defined metaclass in parent can be fixed" ); is(Weird::Class::Sub->meta->destructor_class, 'Weird::Meta::Method::Destructor', "got the right destructor class"); -lives_ok { +is( exception { Class::MOP::Class->create( 'Weird::Class::Sub2', destructor_class => undef, ); -} "undef metaclass in child with defined metaclass in parent can be fixed"; +}, undef, "undef metaclass in child with defined metaclass in parent can be fixed" ); -lives_ok { +is( exception { Weird::Class::Sub2->meta->superclasses('Weird::Class'); -} "undef metaclass in child with defined metaclass in parent can be fixed"; +}, undef, "undef metaclass in child with defined metaclass in parent can be fixed" ); is(Weird::Class::Sub->meta->destructor_class, 'Weird::Meta::Method::Destructor', "got the right destructor class"); diff --git a/t/046_rebless_instance.t b/t/046_rebless_instance.t index 7eb0f68..b1bd4e3 100644 --- a/t/046_rebless_instance.t +++ b/t/046_rebless_instance.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Scalar::Util 'blessed'; { @@ -33,7 +33,7 @@ my $foo = Parent->new; is(blessed($foo), 'Parent', 'Parent->new gives a Parent'); is($foo->whoami, "parent", 'Parent->whoami gives parent'); is($foo->parent, "parent", 'Parent->parent gives parent'); -dies_ok { $foo->child } "Parent->child method doesn't exist"; +isnt( exception { $foo->child }, undef, "Parent->child method doesn't exist" ); Child->meta->rebless_instance($foo); is(blessed($foo), 'Child', 'rebless_instance really reblessed the instance'); @@ -41,23 +41,19 @@ is($foo->whoami, "child", 'reblessed->whoami gives child'); is($foo->parent, "parent", 'reblessed->parent gives parent'); is($foo->child, "child", 'reblessed->child gives child'); -throws_ok { LeftField->meta->rebless_instance($foo) } - qr/You may rebless only into a subclass of \(Child\), of which \(LeftField\) isn't\./; +like( exception { LeftField->meta->rebless_instance($foo) }, qr/You may rebless only into a subclass of \(Child\), of which \(LeftField\) isn't\./ ); -throws_ok { Class::MOP::Class->initialize("NonExistent")->rebless_instance($foo) } - qr/You may rebless only into a subclass of \(Child\), of which \(NonExistent\) isn't\./; +like( exception { Class::MOP::Class->initialize("NonExistent")->rebless_instance($foo) }, qr/You may rebless only into a subclass of \(Child\), of which \(NonExistent\) isn't\./ ); Parent->meta->rebless_instance_back($foo); is(blessed($foo), 'Parent', 'Parent->new gives a Parent'); is($foo->whoami, "parent", 'Parent->whoami gives parent'); is($foo->parent, "parent", 'Parent->parent gives parent'); -dies_ok { $foo->child } "Parent->child method doesn't exist"; +isnt( exception { $foo->child }, undef, "Parent->child method doesn't exist" ); -throws_ok { LeftField->meta->rebless_instance_back($foo) } - qr/You may rebless only into a superclass of \(Parent\), of which \(LeftField\) isn't\./; +like( exception { LeftField->meta->rebless_instance_back($foo) }, qr/You may rebless only into a superclass of \(Parent\), of which \(LeftField\) isn't\./ ); -throws_ok { Class::MOP::Class->initialize("NonExistent")->rebless_instance_back($foo) } - qr/You may rebless only into a superclass of \(Parent\), of which \(NonExistent\) isn't\./; +like( exception { Class::MOP::Class->initialize("NonExistent")->rebless_instance_back($foo) }, qr/You may rebless only into a superclass of \(Parent\), of which \(NonExistent\) isn't\./ ); # make sure our ->meta is still sane my $bar = Parent->new; diff --git a/t/047_rebless_with_extra_params.t b/t/047_rebless_with_extra_params.t index 17af892..ee29aa3 100644 --- a/t/047_rebless_with_extra_params.t +++ b/t/047_rebless_with_extra_params.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -27,17 +27,17 @@ use Class::MOP; is($foo->bar, 'BAR', '... got the expect value'); ok(!$foo->can('baz'), '... no baz method though'); - lives_ok { + is( exception { Bar->meta->rebless_instance($foo) - } '... this works'; + }, undef, '... this works' ); is($foo->bar, 'BAR', '... got the expect value'); ok($foo->can('baz'), '... we have baz method now'); is($foo->baz, 'BAZ', '... got the expect value'); - lives_ok { + is( exception { Foo->meta->rebless_instance_back($foo) - } '... this works'; + }, undef, '... this works' ); is($foo->bar, 'BAR', '... got the expect value'); ok(!$foo->can('baz'), '... no baz method though'); } @@ -50,17 +50,17 @@ use Class::MOP; is($foo->bar, 'BAR', '... got the expect value'); ok(!$foo->can('baz'), '... no baz method though'); - lives_ok { + is( exception { Bar->meta->rebless_instance($foo, (baz => 'FOO-BAZ')) - } '... this works'; + }, undef, '... this works' ); is($foo->bar, 'BAR', '... got the expect value'); ok($foo->can('baz'), '... we have baz method now'); is($foo->baz, 'FOO-BAZ', '... got the expect value'); - lives_ok { + is( exception { Foo->meta->rebless_instance_back($foo) - } '... this works'; + }, undef, '... this works' ); is($foo->bar, 'BAR', '... got the expect value'); ok(!$foo->can('baz'), '... no baz method though'); @@ -75,17 +75,17 @@ use Class::MOP; is($foo->bar, 'BAR', '... got the expect value'); ok(!$foo->can('baz'), '... no baz method though'); - lives_ok { + is( exception { Bar->meta->rebless_instance($foo, (bar => 'FOO-BAR', baz => 'FOO-BAZ')) - } '... this works'; + }, undef, '... this works' ); is($foo->bar, 'FOO-BAR', '... got the expect value'); ok($foo->can('baz'), '... we have baz method now'); is($foo->baz, 'FOO-BAZ', '... got the expect value'); - lives_ok { + is( exception { Foo->meta->rebless_instance_back($foo) - } '... this works'; + }, undef, '... this works' ); is($foo->bar, 'FOO-BAR', '... got the expect value'); ok(!$foo->can('baz'), '... no baz method though'); diff --git a/t/048_anon_class_create_init.t b/t/048_anon_class_create_init.t index b362eae..b42149a 100644 --- a/t/048_anon_class_create_init.t +++ b/t/048_anon_class_create_init.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -124,9 +124,9 @@ my $instance; ok(Class::MOP::class_of($meta_name), "metaclass still exists"); { my $bar_meta; - lives_ok { + is( exception { $bar_meta = $meta_name->initialize('Bar'); - } "we can use the name on its own"; + }, undef, "we can use the name on its own" ); isa_ok($bar_meta, $meta_name); } } diff --git a/t/049_metaclass_reinitialize.t b/t/049_metaclass_reinitialize.t index 7d8dd50..b739836 100644 --- a/t/049_metaclass_reinitialize.t +++ b/t/049_metaclass_reinitialize.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { package Foo; @@ -26,23 +26,23 @@ can_ok('Foo', 'meta'); my $meta = Foo->meta; check_meta_sanity($meta, 'Foo'); -lives_ok { +is( exception { $meta = $meta->reinitialize($meta->name); -}; +}, undef ); check_meta_sanity($meta, 'Foo'); -lives_ok { +is( exception { $meta = $meta->reinitialize($meta); -}; +}, undef ); check_meta_sanity($meta, 'Foo'); -throws_ok { +like( exception { $meta->reinitialize(''); -} qr/You must pass a package name or an existing Class::MOP::Package instance/; +}, qr/You must pass a package name or an existing Class::MOP::Package instance/ ); -throws_ok { +like( exception { $meta->reinitialize($meta->new_object); -} qr/You must pass a package name or an existing Class::MOP::Package instance/; +}, qr/You must pass a package name or an existing Class::MOP::Package instance/ ); { package Bar::Meta::Method; @@ -67,9 +67,9 @@ $meta = Bar->meta; check_meta_sanity($meta, 'Bar'); isa_ok(Bar->meta->get_method('foo'), 'Bar::Meta::Method'); isa_ok(Bar->meta->get_attribute('bar'), 'Bar::Meta::Attribute'); -lives_ok { +is( exception { $meta = $meta->reinitialize('Bar'); -}; +}, undef ); check_meta_sanity($meta, 'Bar'); isa_ok(Bar->meta->get_method('foo'), 'Bar::Meta::Method'); isa_ok(Bar->meta->get_attribute('bar'), 'Bar::Meta::Attribute'); @@ -79,9 +79,9 @@ Bar->meta->get_attribute('bar')->tset('OOF'); is(Bar->meta->get_method('foo')->test, 'FOO'); is(Bar->meta->get_attribute('bar')->tset, 'OOF'); -lives_ok { +is( exception { $meta = $meta->reinitialize('Bar'); -}; +}, undef ); is(Bar->meta->get_method('foo')->test, 'FOO'); is(Bar->meta->get_attribute('bar')->tset, 'OOF'); @@ -107,13 +107,13 @@ $meta = Class::MOP::class_of('Baz'); check_meta_sanity($meta, 'Baz'); ok(!$meta->get_method('foo')->isa('Baz::Meta::Method')); ok(!$meta->get_attribute('bar')->isa('Baz::Meta::Attribute')); -lives_ok { +is( exception { $meta = $meta->reinitialize( 'Baz', attribute_metaclass => 'Baz::Meta::Attribute', method_metaclass => 'Baz::Meta::Method' ); -}; +}, undef ); check_meta_sanity($meta, 'Baz'); isa_ok($meta->get_method('foo'), 'Baz::Meta::Method'); isa_ok($meta->get_attribute('bar'), 'Baz::Meta::Attribute'); @@ -132,13 +132,13 @@ $meta = Quux->meta; check_meta_sanity($meta, 'Quux'); isa_ok(Quux->meta->get_method('foo'), 'Bar::Meta::Method'); isa_ok(Quux->meta->get_attribute('bar'), 'Bar::Meta::Attribute'); -throws_ok { +like( exception { $meta = $meta->reinitialize( 'Quux', attribute_metaclass => 'Baz::Meta::Attribute', method_metaclass => 'Baz::Meta::Method', ); -} qr/compatible/; +}, qr/compatible/ ); { package Quuux::Meta::Attribute; @@ -157,12 +157,12 @@ throws_ok { $meta = Quuux->meta; check_meta_sanity($meta, 'Quuux'); ok($meta->has_method('bar')); -lives_ok { +is( exception { $meta = $meta->reinitialize( 'Quuux', attribute_metaclass => 'Quuux::Meta::Attribute', ); -}; +}, undef ); check_meta_sanity($meta, 'Quuux'); ok(!$meta->has_method('bar')); @@ -189,13 +189,13 @@ ok(!$meta->has_method('bar')); $meta = Class::MOP::class_of('Blah'); check_meta_sanity($meta, 'Blah'); -lives_ok { +is( exception { $meta = Class::MOP::Class->reinitialize( 'Blah', attribute_metaclass => 'Blah::Meta::Attribute', method_metaclass => 'Blah::Meta::Method', ); -}; +}, undef ); check_meta_sanity($meta, 'Blah'); can_ok($meta->get_method('foo'), 'foo'); is($meta->get_method('foo')->foo, 'TEST'); diff --git a/t/060_instance.t b/t/060_instance.t index d61e628..5ab6a55 100644 --- a/t/060_instance.t +++ b/t/060_instance.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Scalar::Util qw/isweak reftype/; diff --git a/t/061_instance_inline.t b/t/061_instance_inline.t index ec61805..7100c80 100644 --- a/t/061_instance_inline.t +++ b/t/061_instance_inline.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP::Instance; diff --git a/t/062_custom_instance.t b/t/062_custom_instance.t index da03fdb..429452f 100644 --- a/t/062_custom_instance.t +++ b/t/062_custom_instance.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -45,40 +45,40 @@ my $instance; } undef $instance; -lives_and { +is( exception { my $foo = Foo::Sub->new; isa_ok($foo, 'Foo'); isa_ok($foo, 'Foo::Sub'); is($foo, $instance, "used the passed-in instance"); -}; +}, undef ); undef $instance; -lives_and { +is( exception { my $foo = Foo::Sub->new(foo => 'FOO'); isa_ok($foo, 'Foo'); isa_ok($foo, 'Foo::Sub'); is($foo, $instance, "used the passed-in instance"); is($foo->foo, 'FOO', "set non-CMOP constructor args"); -}; +}, undef ); undef $instance; -lives_and { +is( exception { my $foo = Foo::Sub->new(bar => 'bar'); isa_ok($foo, 'Foo'); isa_ok($foo, 'Foo::Sub'); is($foo, $instance, "used the passed-in instance"); is($foo->bar, 'BAR', "set CMOP attributes"); -}; +}, undef ); undef $instance; -lives_and { +is( exception { my $foo = Foo::Sub->new(foo => 'FOO', bar => 'bar'); isa_ok($foo, 'Foo'); isa_ok($foo, 'Foo::Sub'); is($foo, $instance, "used the passed-in instance"); is($foo->foo, 'FOO', "set non-CMOP constructor arg"); is($foo->bar, 'BAR', "set correct CMOP attribute"); -}; +}, undef ); { package BadFoo; @@ -117,25 +117,21 @@ lives_and { ); } -throws_ok { BadFoo::Sub->new } - qr/BadFoo=HASH.*is not a BadFoo::Sub/, - "error with incorrect constructors"; +like( exception { BadFoo::Sub->new }, qr/BadFoo=HASH.*is not a BadFoo::Sub/, "error with incorrect constructors" ); { my $meta = Class::MOP::Class->create('Really::Bad::Foo'); - throws_ok { + like( exception { $meta->new_object(__INSTANCE__ => (bless {}, 'Some::Other::Class')) - } qr/Some::Other::Class=HASH.*is not a Really::Bad::Foo/, - "error with completely invalid class"; + }, qr/Some::Other::Class=HASH.*is not a Really::Bad::Foo/, "error with completely invalid class" ); } { my $meta = Class::MOP::Class->create('Really::Bad::Foo::2'); for my $invalid ('foo', 1, 0, '') { - throws_ok { + like( exception { $meta->new_object(__INSTANCE__ => $invalid) - } qr/The __INSTANCE__ parameter must be a blessed reference, not $invalid/, - "error with unblessed thing"; + }, qr/The __INSTANCE__ parameter must be a blessed reference, not $invalid/, "error with unblessed thing" ); } } diff --git a/t/070_immutable_metaclass.t b/t/070_immutable_metaclass.t index 74d470a..ca3ecf9 100644 --- a/t/070_immutable_metaclass.t +++ b/t/070_immutable_metaclass.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -83,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'], @@ -128,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') ], @@ -146,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' ); @@ -158,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' ], @@ -200,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') ], @@ -218,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' ); @@ -230,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' ], @@ -272,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 ], [ diff --git a/t/071_immutable_w_custom_metaclass.t b/t/071_immutable_w_custom_metaclass.t index 92c5f8a..eda3217 100644 --- a/t/071_immutable_w_custom_metaclass.t +++ b/t/071_immutable_w_custom_metaclass.t @@ -5,7 +5,7 @@ use FindBin; use File::Spec::Functions; use Test::More; -use Test::Exception; +use Test::Fatal; use Scalar::Util; use Class::MOP; @@ -40,8 +40,7 @@ use lib catdir( $FindBin::Bin, 'lib' ); shift->meta->mymetaclass_attributes; } - ::lives_ok{ Baz->meta->superclasses('Bar') } - '... we survive the metaclass incompatibility test'; + ::is( ::exception { Baz->meta->superclasses('Bar') }, undef, '... we survive the metaclass incompatibility test' ); } { @@ -58,7 +57,7 @@ use lib catdir( $FindBin::Bin, 'lib' ); '... Baz can do method before immutable' ); ok( $meta->can('mymetaclass_attributes'), '... meta can do method before immutable' ); - lives_ok { $meta->make_immutable } "Baz is now immutable"; + is( exception { $meta->make_immutable }, undef, "Baz is now immutable" ); ok( $meta->is_immutable, '... Baz is immutable' ); isa_ok( $meta, 'MyMetaClass', 'Baz->meta' ); ok( Baz->can('mymetaclass_attributes'), @@ -68,7 +67,7 @@ use lib catdir( $FindBin::Bin, 'lib' ); isnt( Scalar::Util::blessed( Baz->meta ), Scalar::Util::blessed( Bar->meta ), 'Baz and Bar immutable metaclasses are different' ); - lives_ok { $meta->make_mutable } "Baz is now mutable"; + is( exception { $meta->make_mutable }, undef, "Baz is now mutable" ); ok( $meta->is_mutable, '... Baz is mutable again' ); } diff --git a/t/072_immutable_w_constructors.t b/t/072_immutable_w_constructors.t index 21b2ce8..cb95e20 100644 --- a/t/072_immutable_w_constructors.t +++ b/t/072_immutable_w_constructors.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -81,12 +81,12 @@ use Class::MOP; ok(!$meta->is_immutable, '... our class is not immutable'); - lives_ok { + is( exception { $meta->make_immutable( inline_constructor => 1, inline_accessors => 0, ); - } '... changed Foo to be immutable'; + }, undef, '... changed Foo to be immutable' ); ok($meta->is_immutable, '... our class is now immutable'); isa_ok($meta, 'Class::MOP::Class'); @@ -146,12 +146,12 @@ use Class::MOP; ok(!$meta->is_immutable, '... our class is not immutable'); - lives_ok { + is( exception { $meta->make_immutable( inline_constructor => 1, inline_accessors => 1, ); - } '... changed Bar to be immutable'; + }, undef, '... changed Bar to be immutable' ); ok($meta->is_immutable, '... our class is now immutable'); isa_ok($meta, 'Class::MOP::Class'); @@ -215,12 +215,12 @@ use Class::MOP; ok(!$meta->is_immutable, '... our class is not immutable'); - lives_ok { + is( exception { $meta->make_immutable( inline_constructor => 0, inline_accessors => 1, ); - } '... changed Bar to be immutable'; + }, undef, '... changed Bar to be immutable' ); ok($meta->is_immutable, '... our class is now immutable'); isa_ok($meta, 'Class::MOP::Class'); @@ -267,7 +267,7 @@ use Class::MOP; { my $buzz; - ::lives_ok { $buzz = Buzz->meta->new_object } '...Buzz instantiated successfully'; + ::is( ::exception { $buzz = Buzz->meta->new_object }, undef, '...Buzz instantiated successfully' ); ::ok(!$buzz->has_bar, '...bar is not set'); ::is($buzz->bar, undef, '...bar returns undef'); ::ok(!$buzz->has_bar, '...bar was not autovivified'); @@ -279,7 +279,7 @@ use Class::MOP; ::ok(!$buzz->has_bar, '...bar is no longerset'); my $buzz2; - ::lives_ok { $buzz2 = Buzz->meta->new_object('bar' => undef) } '...Buzz instantiated successfully'; + ::is( ::exception { $buzz2 = Buzz->meta->new_object('bar' => undef) }, undef, '...Buzz instantiated successfully' ); ::ok($buzz2->has_bar, '...bar is set'); ::is($buzz2->bar, undef, '...bar is undef'); @@ -287,12 +287,12 @@ use Class::MOP; { my $buzz; - ::lives_ok { $buzz = Buzz->meta->new_object } '...Buzz instantiated successfully'; + ::is( ::exception { $buzz = Buzz->meta->new_object }, undef, '...Buzz instantiated successfully' ); ::ok($buzz->has_bah, '...bah is set'); ::is($buzz->bah, 'BAH', '...bah returns "BAH"' ); my $buzz2; - ::lives_ok { $buzz2 = Buzz->meta->new_object('bah' => undef) } '...Buzz instantiated successfully'; + ::is( ::exception { $buzz2 = Buzz->meta->new_object('bah' => undef) }, undef, '...Buzz instantiated successfully' ); ::ok($buzz2->has_bah, '...bah is set'); ::is($buzz2->bah, undef, '...bah is undef'); diff --git a/t/073_make_mutable.t b/t/073_make_mutable.t index 4070b5c..1454e29 100644 --- a/t/073_make_mutable.t +++ b/t/073_make_mutable.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Scalar::Util; @@ -45,7 +45,7 @@ use Class::MOP; # Since this has no default it won't be present yet, but it will # be after the class is made immutable. - 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'); @@ -53,7 +53,7 @@ use Class::MOP; 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'); @@ -75,7 +75,7 @@ use Class::MOP; my $reef = \ 'reef'; ok($meta->add_package_symbol('$ref', $reef), '... added package symbol'); 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'); @@ -88,30 +88,30 @@ use Class::MOP; for qw(get_meta_instance get_all_attributes class_precedence_list ); - lives_ok {$meta->make_immutable; } '... changed Baz to be immutable again'; + 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'; + 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 get_all_attributes @@ -128,17 +128,17 @@ use Class::MOP; 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'); @@ -164,7 +164,7 @@ use Class::MOP; my $reef = \ 'reef'; ok($meta->add_package_symbol('$ref', $reef), '... added package symbol'); 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'); @@ -183,28 +183,28 @@ 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'; + 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 get_all_attributes diff --git a/t/074_immutable_custom_trait.t b/t/074_immutable_custom_trait.t index 0139317..96ac773 100644 --- a/t/074_immutable_custom_trait.t +++ b/t/074_immutable_custom_trait.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -61,8 +61,7 @@ use Class::MOP; __PACKAGE__->meta->add_attribute('bar'); - ::lives_ok { __PACKAGE__->meta->make_immutable } - 'can safely make a class immutable when it has a custom metaclass and immutable trait'; + ::is( ::exception { __PACKAGE__->meta->make_immutable }, undef, 'can safely make a class immutable when it has a custom metaclass and immutable trait' ); } { diff --git a/t/080_meta_package.t b/t/080_meta_package.t index a5d55fa..8e7f76e 100644 --- a/t/080_meta_package.t +++ b/t/080_meta_package.t @@ -2,14 +2,14 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; use Class::MOP::Package; -dies_ok { Class::MOP::Package->get_all_package_symbols } q{... can't call get_all_package_symbols() as a class method}; -dies_ok { Class::MOP::Package->name } q{... can't call name() as a class method}; +isnt( exception { Class::MOP::Package->get_all_package_symbols }, undef, q{... can't call get_all_package_symbols() as a class method} ); +isnt( exception { Class::MOP::Package->name }, undef, q{... can't call name() as a class method} ); { package Foo; @@ -26,9 +26,9 @@ ok(!defined($Foo::{foo}), '... the %foo slot has not been created yet'); ok(!Foo->meta->has_package_symbol('%foo'), '... the meta agrees'); ok(!defined($Foo::{foo}), '... checking doesn\' vivify'); -lives_ok { +is( exception { Foo->meta->add_package_symbol('%foo' => { one => 1 }); -} '... created %Foo::foo successfully'; +}, undef, '... created %Foo::foo successfully' ); # ... scalar should NOT be created here @@ -67,9 +67,9 @@ $foo->{two} = 2; ok(!defined($Foo::{bar}), '... the @bar slot has not been created yet'); -lives_ok { +is( exception { Foo->meta->add_package_symbol('@bar' => [ 1, 2, 3 ]); -} '... created @Foo::bar successfully'; +}, undef, '... created @Foo::bar successfully' ); ok(defined($Foo::{bar}), '... the @bar slot was created successfully'); ok(Foo->meta->has_package_symbol('@bar'), '... the meta agrees'); @@ -93,9 +93,9 @@ ok(!Foo->meta->has_package_symbol('&bar'), '... CODE shouldnt have been created ok(!defined($Foo::{baz}), '... the $baz slot has not been created yet'); -lives_ok { +is( exception { Foo->meta->add_package_symbol('$baz' => 10); -} '... created $Foo::baz successfully'; +}, undef, '... created $Foo::baz successfully' ); ok(defined($Foo::{baz}), '... the $baz slot was created successfully'); ok(Foo->meta->has_package_symbol('$baz'), '... the meta agrees'); @@ -119,9 +119,9 @@ is(${Foo->meta->get_package_symbol('$baz')}, 10, '... got the right value back') ok(!defined($Foo::{funk}), '... the &funk slot has not been created yet'); -lives_ok { +is( exception { Foo->meta->add_package_symbol('&funk' => sub { "Foo::funk" }); -} '... created &Foo::funk successfully'; +}, undef, '... created &Foo::funk successfully' ); ok(defined($Foo::{funk}), '... the &funk slot was created successfully'); ok(Foo->meta->has_package_symbol('&funk'), '... the meta agrees'); @@ -143,23 +143,23 @@ is(Foo->funk(), 'Foo::funk', '... got the right value from the function'); my $ARRAY = [ 1, 2, 3 ]; my $CODE = sub { "Foo::foo" }; -lives_ok { +is( exception { Foo->meta->add_package_symbol('@foo' => $ARRAY); -} '... created @Foo::foo successfully'; +}, undef, '... created @Foo::foo successfully' ); ok(Foo->meta->has_package_symbol('@foo'), '... the @foo slot was added successfully'); is(Foo->meta->get_package_symbol('@foo'), $ARRAY, '... got the right values for @Foo::foo'); -lives_ok { +is( exception { Foo->meta->add_package_symbol('&foo' => $CODE); -} '... created &Foo::foo successfully'; +}, undef, '... created &Foo::foo successfully' ); ok(Foo->meta->has_package_symbol('&foo'), '... the meta agrees'); is(Foo->meta->get_package_symbol('&foo'), $CODE, '... got the right value for &Foo::foo'); -lives_ok { +is( exception { Foo->meta->add_package_symbol('$foo' => 'Foo::foo'); -} '... created $Foo::foo successfully'; +}, undef, '... created $Foo::foo successfully' ); ok(Foo->meta->has_package_symbol('$foo'), '... the meta agrees'); my $SCALAR = Foo->meta->get_package_symbol('$foo'); @@ -170,9 +170,9 @@ is($$SCALAR, 'Foo::foo', '... got the right scalar value back'); is(${'Foo::foo'}, 'Foo::foo', '... got the right value from the scalar'); } -lives_ok { +is( exception { Foo->meta->remove_package_symbol('%foo'); -} '... removed %Foo::foo successfully'; +}, undef, '... removed %Foo::foo successfully' ); ok(!Foo->meta->has_package_symbol('%foo'), '... the %foo slot was removed successfully'); ok(Foo->meta->has_package_symbol('@foo'), '... the @foo slot still exists'); @@ -191,9 +191,9 @@ is(Foo->meta->get_package_symbol('$foo'), $SCALAR, '... got the right value for ok(defined(${"Foo::foo"}), '... the $foo slot has NOT been removed'); } -lives_ok { +is( exception { Foo->meta->remove_package_symbol('&foo'); -} '... removed &Foo::foo successfully'; +}, undef, '... removed &Foo::foo successfully' ); ok(!Foo->meta->has_package_symbol('&foo'), '... the &foo slot no longer exists'); @@ -211,9 +211,9 @@ is(Foo->meta->get_package_symbol('$foo'), $SCALAR, '... got the right value for ok(defined(${"Foo::foo"}), '... the $foo slot has NOT been removed'); } -lives_ok { +is( exception { Foo->meta->remove_package_symbol('$foo'); -} '... removed $Foo::foo successfully'; +}, undef, '... removed $Foo::foo successfully' ); ok(!Foo->meta->has_package_symbol('$foo'), '... the $foo slot no longer exists'); diff --git a/t/081_meta_package_extension.t b/t/081_meta_package_extension.t index c8b2735..4fcac76 100644 --- a/t/081_meta_package_extension.t +++ b/t/081_meta_package_extension.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -62,9 +62,9 @@ isa_ok($meta, 'Class::MOP::Package'); ok(!defined($Foo::{foo}), '... the %foo slot has not been created yet'); ok(!$meta->has_package_symbol('%foo'), '... the meta agrees'); -lives_ok { +is( exception { $meta->add_package_symbol('%foo' => { one => 1 }); -} '... the %foo symbol is created succcessfully'; +}, undef, '... the %foo symbol is created succcessfully' ); ok(!defined($Foo::{foo}), '... the %foo slot has not been created in the actual Foo package'); ok($meta->has_package_symbol('%foo'), '... the meta agrees'); @@ -78,17 +78,17 @@ is($foo, $meta->get_package_symbol('%foo'), '... our %foo is the same as the met ok(!defined($Foo::{bar}), '... the @bar slot has not been created yet'); -lives_ok { +is( exception { $meta->add_package_symbol('@bar' => [ 1, 2, 3 ]); -} '... created @Foo::bar successfully'; +}, undef, '... created @Foo::bar successfully' ); ok(!defined($Foo::{bar}), '... the @bar slot has still not been created'); ok(!defined($Foo::{baz}), '... the %baz slot has not been created yet'); -lives_ok { +is( exception { $meta->add_package_symbol('%baz'); -} '... created %Foo::baz successfully'; +}, undef, '... created %Foo::baz successfully' ); ok(!defined($Foo::{baz}), '... the %baz slot has still not been created'); diff --git a/t/083_load_class.t b/t/083_load_class.t index b2a41ef..0bf857e 100644 --- a/t/083_load_class.t +++ b/t/083_load_class.t @@ -1,14 +1,14 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; require Class::MOP; use lib 't/lib'; -dies_ok { +isnt( exception { Class::MOP::is_class_loaded() -} "is_class_loaded with no argument dies"; +}, undef, "is_class_loaded with no argument dies" ); ok(!Class::MOP::is_class_loaded(''), "can't load the empty class"); ok(!Class::MOP::is_class_loaded(\"foo"), "can't load a class name reference??"); @@ -20,11 +20,11 @@ ok(!Class::MOP::_is_valid_class_name('bogus name'), q{'bogus name' is not a vali ok(Class::MOP::_is_valid_class_name('Foo'), q{'Foo' is a valid class name}); ok(Class::MOP::_is_valid_class_name('Foo::Bar'), q{'Foo::Bar' is a valid class name}); ok(Class::MOP::_is_valid_class_name('Foo_::Bar2'), q{'Foo_::Bar2' is a valid class name}); -throws_ok { Class::MOP::load_class('bogus name') } qr/Invalid class name \(bogus name\)/; +like( exception { Class::MOP::load_class('bogus name') }, qr/Invalid class name \(bogus name\)/ ); -throws_ok { +like( exception { Class::MOP::load_class('__PACKAGE__') -} qr/__PACKAGE__\.pm.*\@INC/, 'errors sanely on __PACKAGE__.pm'; +}, qr/__PACKAGE__\.pm.*\@INC/, 'errors sanely on __PACKAGE__.pm' ); Class::MOP::load_class('BinaryTree'); can_ok('BinaryTree' => 'traverse'); @@ -43,54 +43,47 @@ do { ok( !Class::MOP::does_metaclass_exist("Class"), "no metaclass for non MOP class" ); -throws_ok { +like( exception { Class::MOP::load_class('FakeClassOhNo'); -} -qr/Can't locate /; +}, qr/Can't locate / ); -throws_ok { +like( exception { Class::MOP::load_class('SyntaxError'); -} -qr/Missing right curly/; +}, qr/Missing right curly/ ); -throws_ok { +like( exception { delete $INC{'SyntaxError.pm'}; Class::MOP::load_first_existing_class( 'FakeClassOhNo', 'SyntaxError', 'Class' ); -} -qr/Missing right curly/, - 'load_first_existing_class does not pass over an existing (bad) module'; +}, qr/Missing right curly/, 'load_first_existing_class does not pass over an existing (bad) module' ); -throws_ok { +like( exception { Class::MOP::load_class('This::Does::Not::Exist'); -} -qr{Can't locate This/Does/Not/Exist\.pm in \@INC}, - 'load_first_existing_class throws a familiar error for a single module'; +}, qr{Can't locate This/Does/Not/Exist\.pm in \@INC}, 'load_first_existing_class throws a familiar error for a single module' ); { package Other; use constant foo => "bar"; } -lives_ok { +is( exception { ok(Class::MOP::is_class_loaded("Other"), 'is_class_loaded(Other)'); -} -"a class with just constants is still a class"; +}, undef, "a class with just constants is still a class" ); { package Lala; use metaclass; } -lives_ok { +is( exception { is(Class::MOP::load_first_existing_class("Lala", "Does::Not::Exist"), "Lala", 'load_first_existing_class 1/2 params ok, class name returned'); is(Class::MOP::load_first_existing_class("Does::Not::Exist", "Lala"), "Lala", 'load_first_existing_class 2/2 params ok, class name returned'); -} 'load_classes works'; +}, undef, 'load_classes works' ); -throws_ok { +like( exception { Class::MOP::load_first_existing_class("Does::Not::Exist", "Also::Does::Not::Exist") -} qr/Does::Not::Exist.*Also::Does::Not::Exist/s, 'Multiple non-existant classes cause exception'; +}, qr/Does::Not::Exist.*Also::Does::Not::Exist/s, 'Multiple non-existant classes cause exception' ); { sub whatever { @@ -157,23 +150,21 @@ throws_ok { ok( !Class::MOP::is_class_loaded('Class::WithVersion', { -version => 42 }), 'version 23 does not satisfy version requirement 42' ); - throws_ok { + like( exception { Class::MOP::load_first_existing_class('Affe', 'Tiger', 'Class::WithVersion' => { -version => 42 }); - } qr/Class::WithVersion version 42 required--this is only version 23/, - 'load_first_existing_class gives correct exception on old version'; + }, qr/Class::WithVersion version 42 required--this is only version 23/, 'load_first_existing_class gives correct exception on old version' ); - lives_ok { + is( exception { Class::MOP::load_first_existing_class('Affe', 'Tiger', 'Class::WithVersion' => { -version => 13 }); - } 'loading class with required version with load_first_existing_class'; + }, undef, 'loading class with required version with load_first_existing_class' ); - throws_ok { + like( exception { Class::MOP::load_class('Class::WithVersion' => { -version => 42 }); - } qr/Class::WithVersion version 42 required--this is only version 23/, - 'load_class gives correct exception on old version'; + }, qr/Class::WithVersion version 42 required--this is only version 23/, 'load_class gives correct exception on old version' ); - lives_ok { + is( exception { Class::MOP::load_class('Class::WithVersion' => { -version => 13 }); - } 'loading class with required version with load_class'; + }, undef, 'loading class with required version with load_class' ); } diff --git a/t/085_load_class_gvstash_detect_bug.t b/t/085_load_class_gvstash_detect_bug.t index 91e6171..8f2ed6e 100644 --- a/t/085_load_class_gvstash_detect_bug.t +++ b/t/085_load_class_gvstash_detect_bug.t @@ -1,23 +1,23 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; use lib 't/lib'; -lives_ok { +is( exception { Class::MOP::load_class('TestClassLoaded::Sub'); -}; +}, undef ); TestClassLoaded->can('a_method'); -lives_ok { +is( exception { Class::MOP::load_class('TestClassLoaded'); -}; +}, undef ); -lives_ok { +is( exception { TestClassLoaded->a_method; -}; +}, undef ); done_testing; diff --git a/t/090_meta_method.t b/t/090_meta_method.t index 774b8b3..f103936 100644 --- a/t/090_meta_method.t +++ b/t/090_meta_method.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; { @@ -50,18 +50,18 @@ use Class::MOP; my $meta = Class::MOP::class_of('Foo'); ok(!$meta->has_method('meta'), "no meta method was installed"); $meta->add_method(meta => sub { die 'META' }); - lives_ok { $meta->find_method_by_name('meta') } "can do meta-level stuff"; - lives_ok { $meta->make_immutable } "can do meta-level stuff"; - lives_ok { $meta->class_precedence_list } "can do meta-level stuff"; + is( exception { $meta->find_method_by_name('meta') }, undef, "can do meta-level stuff" ); + is( exception { $meta->make_immutable }, undef, "can do meta-level stuff" ); + is( exception { $meta->class_precedence_list }, undef, "can do meta-level stuff" ); } { my $meta = Class::MOP::Class->create('Bar', meta_name => undef); ok(!$meta->has_method('meta'), "no meta method was installed"); $meta->add_method(meta => sub { die 'META' }); - lives_ok { $meta->find_method_by_name('meta') } "can do meta-level stuff"; - lives_ok { $meta->make_immutable } "can do meta-level stuff"; - lives_ok { $meta->class_precedence_list } "can do meta-level stuff"; + is( exception { $meta->find_method_by_name('meta') }, undef, "can do meta-level stuff" ); + is( exception { $meta->make_immutable }, undef, "can do meta-level stuff" ); + is( exception { $meta->class_precedence_list }, undef, "can do meta-level stuff" ); } done_testing; diff --git a/t/100_BinaryTree_test.t b/t/100_BinaryTree_test.t index 285994f..f6f1c37 100644 --- a/t/100_BinaryTree_test.t +++ b/t/100_BinaryTree_test.t @@ -5,7 +5,7 @@ use FindBin; use File::Spec::Functions; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -17,9 +17,9 @@ use lib catdir($FindBin::Bin, 'lib'); ok(!Class::MOP::is_class_loaded('BinaryTree'), '... the binary tree class is not loaded'); -lives_ok { +is( exception { Class::MOP::load_class('BinaryTree'); -} '... loaded the BinaryTree class without dying'; +}, undef, '... loaded the BinaryTree class without dying' ); ok(Class::MOP::is_class_loaded('BinaryTree'), '... the binary tree class is now loaded'); diff --git a/t/302_modify_parent_method.t b/t/302_modify_parent_method.t index c52f1a8..2373453 100644 --- a/t/302_modify_parent_method.t +++ b/t/302_modify_parent_method.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; diff --git a/t/303_RT_39001_fix.t b/t/303_RT_39001_fix.t index 210d715..a3575e8 100644 --- a/t/303_RT_39001_fix.t +++ b/t/303_RT_39001_fix.t @@ -1,7 +1,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -16,9 +16,9 @@ This tests a bug sent via RT #39001 use metaclass; } -throws_ok { +like( exception { Foo->meta->superclasses('Foo'); -} qr/^Recursive inheritance detected/, "error occurs when extending oneself"; +}, qr/^Recursive inheritance detected/, "error occurs when extending oneself" ); { package Bar; @@ -29,12 +29,12 @@ throws_ok { # if DEBUG_NO_META is set) @Foo::ISA = (); -lives_ok { +is( exception { Foo->meta->superclasses('Bar'); -} "regular subclass"; +}, undef, "regular subclass" ); -throws_ok { +like( exception { Bar->meta->superclasses('Foo'); -} qr/^Recursive inheritance detected/, "error occurs when Bar extends Foo, when Foo is a Bar"; +}, qr/^Recursive inheritance detected/, "error occurs when Bar extends Foo, when Foo is a Bar" ); done_testing; diff --git a/t/305_RT_41255.t b/t/305_RT_41255.t index 15e5c43..0c87b9d 100644 --- a/t/305_RT_41255.t +++ b/t/305_RT_41255.t @@ -1,6 +1,6 @@ use strict; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -27,7 +27,7 @@ my %methods = map { $_ => $meta->find_method_by_name($_) } 'm1' .. 'm5'; while (my ($name, $meta_method) = each %methods) { is $meta_method->fully_qualified_name, "Derived::${name}"; - throws_ok { $meta_method->execute } qr/Undefined subroutine .* called at/; + like( exception { $meta_method->execute }, qr/Undefined subroutine .* called at/ ); } { @@ -45,7 +45,7 @@ EOC while (my ($name, $meta_method) = each %methods) { is $meta_method->fully_qualified_name, "Derived::${name}"; - lives_ok { $meta_method->execute }; + is( exception { $meta_method->execute }, undef ); } done_testing; diff --git a/t/313_before_after_dollar_under.t b/t/313_before_after_dollar_under.t index 01d8da1..65f9774 100644 --- a/t/313_before_after_dollar_under.t +++ b/t/313_before_after_dollar_under.t @@ -4,7 +4,7 @@ use warnings; use Class::MOP; use Class::MOP::Class; use Test::More; -use Test::Exception; +use Test::Fatal; my %results; @@ -29,12 +29,11 @@ for my $wrap (qw(before after)) { %results = (); my $o = $meta->get_meta_instance->create_instance; isa_ok( $o, 'Base' ); - lives_ok { + is( exception { $o->hey; $o->hey ; # this would die with 'Can't use string ("barf") as a subroutine ref while "strict refs" in use' - } - 'wrapped doesn\'t die when $_ gets changed'; + }, undef, 'wrapped doesn\'t die when $_ gets changed' ); is_deeply( \%results, { base => 2, wrapped => 2 }, 'saw expected calls to wrappers' @@ -57,12 +56,11 @@ for my $wrap (qw(before after)) { %results = (); my $o = $meta->get_meta_instance->create_instance; isa_ok( $o, 'Base' ); - lives_ok { + is( exception { $o->hey; $o->hey ; # this would die with 'Can't use string ("barf") as a subroutine ref while "strict refs" in use' - } - 'double-wrapped doesn\'t die when $_ gets changed'; + }, undef, 'double-wrapped doesn\'t die when $_ gets changed' ); is_deeply( \%results, { base => 2, wrapped => 4 }, 'saw expected calls to wrappers' diff --git a/t/315_magic.t b/t/315_magic.t index 2259d6a..1969253 100755 --- a/t/315_magic.t +++ b/t/315_magic.t @@ -5,7 +5,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; @@ -55,21 +55,21 @@ use Tie::Scalar; { my $x = tie my $value, 'Tie::StdScalar', 'Class::MOP'; - lives_ok{ Class::MOP::load_class($value) } 'load_class(tied scalar)'; + is( exception { Class::MOP::load_class($value) }, undef, 'load_class(tied scalar)' ); $value = undef; $x->STORE('Class::MOP'); # reset - lives_and{ + is( exception { ok Class::MOP::is_class_loaded($value); - } 'is_class_loaded(tied scalar)'; + }, undef, 'is_class_loaded(tied scalar)' ); $value = undef; $x->STORE(\&Class::MOP::get_code_info); # reset - lives_and{ + is( exception { is_deeply [Class::MOP::get_code_info($value)], [qw(Class::MOP get_code_info)], 'get_code_info(tied scalar)'; - } + }, undef ); } done_testing; diff --git a/t/500_deprecated.t b/t/500_deprecated.t index df0eaf5..471fb4a 100755 --- a/t/500_deprecated.t +++ b/t/500_deprecated.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Carp; @@ -11,10 +11,9 @@ $SIG{__WARN__} = \&croak; { package Foo; - ::throws_ok{ + ::like( ::exception { Class::MOP::in_global_destruction(); - } qr/\b deprecated \b/xmsi, - 'Class::MOP::in_global_destruction is deprecated'; + }, qr/\b deprecated \b/xmsi, 'Class::MOP::in_global_destruction is deprecated' ); } { @@ -22,10 +21,9 @@ $SIG{__WARN__} = \&croak; use Class::MOP::Deprecated -api_version => 0.93; - ::throws_ok{ + ::like( ::exception { Class::MOP::in_global_destruction(); - } qr/\b deprecated \b/xmsi, - 'Class::MOP::in_global_destruction is deprecated with 0.93 compatibility'; + }, qr/\b deprecated \b/xmsi, 'Class::MOP::in_global_destruction is deprecated with 0.93 compatibility' ); } { @@ -33,10 +31,9 @@ $SIG{__WARN__} = \&croak; use Class::MOP::Deprecated -api_version => 0.92; - ::lives_ok{ + ::is( ::exception { Class::MOP::in_global_destruction(); - } - 'Class::MOP::in_global_destruction is not deprecated with 0.92 compatibility'; + }, undef, 'Class::MOP::in_global_destruction is not deprecated with 0.92 compatibility' ); } { @@ -44,9 +41,7 @@ $SIG{__WARN__} = \&croak; use metaclass; - ::throws_ok{ Foo2->meta->get_attribute_map } - qr/\Qget_attribute_map method has been deprecated/, - 'get_attribute_map is deprecated'; + ::like( ::exception { Foo2->meta->get_attribute_map }, qr/\Qget_attribute_map method has been deprecated/, 'get_attribute_map is deprecated' ); } {