From: Karen Etheridge Date: Sun, 24 Oct 2010 18:03:43 +0000 (-0700) Subject: convert all uses of Test::Exception to Test::Fatal. X-Git-Tag: 1.11~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=13b8971fa6cc4edf7d55a2e5482820d62ba38f16;p=gitmo%2FClass-MOP.git convert all uses of Test::Exception to Test::Fatal. --- diff --git a/Makefile.PL b/Makefile.PL index 0738305..9832b52 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -33,7 +33,7 @@ requires 'Task::Weaken'; test_requires 'File::Spec'; test_requires 'Test::More' => '0.88'; -test_requires 'Test::Exception' => '0.27'; +test_requires 'Test::Fatal' => '0.001'; test_requires 'Test::Requires' => '0.05'; author_requires 'Algorithm::C3'; 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..de128e4 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,9 +74,9 @@ my $foo = sub {'Foo::foo'}; ok( !UNIVERSAL::isa( $foo, 'Class::MOP::Method' ), '... our method is not yet blessed' ); -lives_ok { +ok ! exception { $Foo->add_method( 'foo' => $foo ); -} +}, '... we added the method successfully'; my $foo_method = $Foo->get_method('foo'); @@ -210,7 +210,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'; +ok exception { Foo->foo }, '... cannot call Foo->foo because it is not there'; is_deeply( [ sort $Foo->get_method_list ], @@ -236,9 +236,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 { +ok ! exception { $Bar->add_method( 'foo' => sub {'Bar::foo v2'} ); -} +}, '... overwriting a method is fine'; is_deeply( [ Class::MOP::get_code_info( $Bar->get_method('foo')->body ) ], 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..036a5b8 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 { + ::ok ! ::exception { $meta->add_attribute($FOO_ATTR); - } '... we added an attribute to Foo successfully'; + }, '... 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 { + ::ok ! ::exception { $meta->add_attribute($BAR_ATTR_2); - } '... we added an attribute to Foo successfully'; + }, '... 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 { + ::ok ! ::exception { $meta->add_attribute($BAR_ATTR); - } '... we added an attribute to Bar successfully'; + }, '... 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 { + ::ok ! ::exception { $meta->add_attribute($BAZ_ATTR); - } '... we added an attribute to Baz successfully'; + }, '... 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 { + ok ! exception { $attr = $meta->remove_attribute('$baz'); - } '... removed the $baz attribute successfully'; + }, '... 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 { + ok ! exception { $attr = Bar->meta->remove_attribute('$bar'); - } '... removed the $bar attribute successfully'; + }, '... 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 { + ok ! exception { $val = $meta->remove_attribute('$blammo'); - } '... attempted to remove the non-existent $blammo attribute'; + }, '... 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 { + ::ok ! ::exception { $meta->add_attribute($FOO_ATTR_2); - } '... we added an attribute to Buzz successfully'; + }, '... we added an attribute to Buzz successfully'; - ::lives_ok { + ::ok ! ::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'; + }, '... we added an attribute to Buzz successfully'; - ::lives_ok { + ::ok ! ::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'; + }, '... we added an attribute to Buzz successfully'; - ::lives_ok { + ::ok ! ::exception { $meta->add_method(build_foo => sub{ blessed shift; }); - } '... we added a method to Buzz successfully'; + }, '... we added a method to Buzz successfully'; } for(1 .. 2){ my $buzz; - ::lives_ok { $buzz = Buzz->meta->new_object } '...Buzz instantiated successfully'; + ::ok ! ::exception { $buzz = Buzz->meta->new_object }, '...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'; + ::ok ! ::exception { $buzz2 = Buzz->meta->new_object('$bar' => 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'; + ::ok ! ::exception { $buzz3 = Buzz->meta->new_object }, '...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'; + ::ok ! ::exception { $buzz4 = Buzz->meta->new_object('$bah' => 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..b91f25c 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 { +ok exception { $foo_meta->clone_object($meta); -} '... this dies as expected'; +}, '... 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..1770990 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 { +ok exception { $point->x(42); -} '... cannot write to a read-only accessor'; +}, '... 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..61c555d 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 { +ok ! exception { Foo->meta->add_package_symbol('%foo' => { one => 1 }); -} '... created %Foo::foo successfully'; +}, '... 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 { +ok ! exception { Foo->meta->add_package_symbol('@bar' => [ 1, 2, 3 ]); -} '... created @Foo::bar successfully'; +}, '... 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 { +ok ! exception { Foo->meta->add_package_symbol('$baz' => 10); -} '... created $Foo::baz successfully'; +}, '... 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 { +ok ! exception { Foo->meta->add_package_symbol('&funk' => sub { "Foo::funk" }); -} '... created &Foo::funk successfully'; +}, '... 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 { +ok ! exception { Foo->meta->add_package_symbol('@foo' => $ARRAY); -} '... created @Foo::foo successfully'; +}, '... 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 { +ok ! exception { Foo->meta->add_package_symbol('&foo' => $CODE); -} '... created &Foo::foo successfully'; +}, '... 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 { +ok ! exception { Foo->meta->add_package_symbol('$foo' => 'Foo::foo'); -} '... created $Foo::foo successfully'; +}, '... 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 { +ok ! exception { Foo->meta->remove_package_symbol('%foo'); -} '... removed %Foo::foo successfully'; +}, '... 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 { +ok ! exception { Foo->meta->remove_package_symbol('&foo'); -} '... removed &Foo::foo successfully'; +}, '... 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 { +ok ! exception { Foo->meta->remove_package_symbol('$foo'); -} '... removed $Foo::foo successfully'; +}, '... 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..b40fc8f 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 { +ok exception { $point->x(42); -} '... cannot write to a read-only accessor'; +}, '... 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..20103d3 100644 --- a/t/016_class_errors_and_edge_cases.t +++ b/t/016_class_errors_and_edge_cases.t @@ -2,222 +2,222 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; { - dies_ok { + ok exception { Class::MOP::Class->initialize(); - } '... initialize requires a name parameter'; + }, '... initialize requires a name parameter'; - dies_ok { + ok exception { Class::MOP::Class->initialize(''); - } '... initialize requires a name valid parameter'; + }, '... initialize requires a name valid parameter'; - dies_ok { + ok exception { Class::MOP::Class->initialize(bless {} => 'Foo'); - } '... initialize requires an unblessed parameter' + }, '... initialize requires an unblessed parameter' } { - dies_ok { + ok exception { Class::MOP::Class->_construct_class_instance(); - } '... _construct_class_instance requires an :package parameter'; + }, '... _construct_class_instance requires an :package parameter'; - dies_ok { + ok exception { Class::MOP::Class->_construct_class_instance(':package' => undef); - } '... _construct_class_instance requires a defined :package parameter'; + }, '... _construct_class_instance requires a defined :package parameter'; - dies_ok { + ok exception { Class::MOP::Class->_construct_class_instance(':package' => ''); - } '... _construct_class_instance requires a valid :package parameter'; + }, '... _construct_class_instance requires a valid :package parameter'; } { - dies_ok { + ok exception { Class::MOP::Class->create(); - } '... create requires an package_name parameter'; + }, '... create requires an package_name parameter'; - dies_ok { + ok exception { Class::MOP::Class->create(undef); - } '... create requires a defined package_name parameter'; + }, '... create requires a defined package_name parameter'; - dies_ok { + ok exception { Class::MOP::Class->create(''); - } '... create requires a valid package_name parameter'; + }, '... 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 { + ok exception { Class::MOP::Class->clone_object(1); - } '... can only clone instances'; + }, '... can only clone instances'; } { - dies_ok { + ok exception { Class::MOP::Class->add_method(); - } '... add_method dies as expected'; + }, '... add_method dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->add_method(''); - } '... add_method dies as expected'; + }, '... add_method dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->add_method('foo' => 'foo'); - } '... add_method dies as expected'; + }, '... add_method dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->add_method('foo' => []); - } '... add_method dies as expected'; + }, '... add_method dies as expected'; } { - dies_ok { + ok exception { Class::MOP::Class->has_method(); - } '... has_method dies as expected'; + }, '... has_method dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->has_method(''); - } '... has_method dies as expected'; + }, '... has_method dies as expected'; } { - dies_ok { + ok exception { Class::MOP::Class->get_method(); - } '... get_method dies as expected'; + }, '... get_method dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->get_method(''); - } '... get_method dies as expected'; + }, '... get_method dies as expected'; } { - dies_ok { + ok exception { Class::MOP::Class->remove_method(); - } '... remove_method dies as expected'; + }, '... remove_method dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->remove_method(''); - } '... remove_method dies as expected'; + }, '... remove_method dies as expected'; } { - dies_ok { + ok exception { Class::MOP::Class->find_all_methods_by_name(); - } '... find_all_methods_by_name dies as expected'; + }, '... find_all_methods_by_name dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->find_all_methods_by_name(''); - } '... find_all_methods_by_name dies as expected'; + }, '... find_all_methods_by_name dies as expected'; } { - dies_ok { + ok exception { Class::MOP::Class->add_attribute(bless {} => 'Foo'); - } '... add_attribute dies as expected'; + }, '... add_attribute dies as expected'; } { - dies_ok { + ok exception { Class::MOP::Class->has_attribute(); - } '... has_attribute dies as expected'; + }, '... has_attribute dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->has_attribute(''); - } '... has_attribute dies as expected'; + }, '... has_attribute dies as expected'; } { - dies_ok { + ok exception { Class::MOP::Class->get_attribute(); - } '... get_attribute dies as expected'; + }, '... get_attribute dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->get_attribute(''); - } '... get_attribute dies as expected'; + }, '... get_attribute dies as expected'; } { - dies_ok { + ok exception { Class::MOP::Class->remove_attribute(); - } '... remove_attribute dies as expected'; + }, '... remove_attribute dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->remove_attribute(''); - } '... remove_attribute dies as expected'; + }, '... remove_attribute dies as expected'; } { - dies_ok { + ok exception { Class::MOP::Class->add_package_symbol(); - } '... add_package_symbol dies as expected'; + }, '... add_package_symbol dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->add_package_symbol(''); - } '... add_package_symbol dies as expected'; + }, '... add_package_symbol dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->add_package_symbol('foo'); - } '... add_package_symbol dies as expected'; + }, '... add_package_symbol dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->add_package_symbol('&foo'); - } '... add_package_symbol dies as expected'; + }, '... add_package_symbol dies as expected'; -# throws_ok { +# like exception { # Class::MOP::Class->meta->add_package_symbol('@-'); # } qr/^Could not create package variable \(\@\-\) because/, # '... add_package_symbol dies as expected'; } { - dies_ok { + ok exception { Class::MOP::Class->has_package_symbol(); - } '... has_package_symbol dies as expected'; + }, '... has_package_symbol dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->has_package_symbol(''); - } '... has_package_symbol dies as expected'; + }, '... has_package_symbol dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->has_package_symbol('foo'); - } '... has_package_symbol dies as expected'; + }, '... has_package_symbol dies as expected'; } { - dies_ok { + ok exception { Class::MOP::Class->get_package_symbol(); - } '... get_package_symbol dies as expected'; + }, '... get_package_symbol dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->get_package_symbol(''); - } '... get_package_symbol dies as expected'; + }, '... get_package_symbol dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->get_package_symbol('foo'); - } '... get_package_symbol dies as expected'; + }, '... get_package_symbol dies as expected'; } { - dies_ok { + ok exception { Class::MOP::Class->remove_package_symbol(); - } '... remove_package_symbol dies as expected'; + }, '... remove_package_symbol dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->remove_package_symbol(''); - } '... remove_package_symbol dies as expected'; + }, '... remove_package_symbol dies as expected'; - dies_ok { + ok exception { Class::MOP::Class->remove_package_symbol('foo'); - } '... remove_package_symbol dies as expected'; + }, '... 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..97e9a62 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( + ::like (::exception( sub { 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,15 +90,15 @@ my $savings_account = BankAccount->new( balance => 250 ); isa_ok( $savings_account, 'BankAccount' ); is( $savings_account->balance, 250, '... got the right savings balance' ); -lives_ok { +ok ! exception { $savings_account->withdraw(50); -} +}, '... withdrew from savings successfully'; is( $savings_account->balance, 200, '... got the right savings balance after withdrawal' ); -dies_ok { +ok exception { $savings_account->withdraw(250); -} +}, '... could not withdraw from savings successfully'; $savings_account->deposit(150); @@ -117,9 +117,9 @@ is( $checking_account->overdraft_account, $savings_account, is( $checking_account->balance, 100, '... got the right checkings balance' ); -lives_ok { +ok ! exception { $checking_account->withdraw(50); -} +}, '... withdrew from checking successfully'; is( $checking_account->balance, 50, '... got the right checkings balance after withdrawal' ); @@ -127,9 +127,9 @@ is( $savings_account->balance, 350, '... got the right savings balance after checking withdrawal (no overdraft)' ); -lives_ok { +ok ! exception { $checking_account->withdraw(200); -} +}, '... withdrew from checking successfully'; is( $checking_account->balance, 0, '... got the right checkings balance after withdrawal' ); diff --git a/t/018_anon_class.t b/t/018_anon_class.t index d314e7a..d7a0197 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 { + ok ! exception { $anon_class->superclasses('Foo'); - } '... can add a superclass to anon class'; + }, '... 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 { + ok ! exception { $anon_class->add_method('foo' => sub { "__ANON__::foo" }); - } '... added a method to my anon-class'; + }, '... 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..6ca4624 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}; +ok exception { Class::MOP::Attribute->name }, 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 { + ok ! exception { $attr->attach_to_class($class); - } '... attached a class successfully'; + }, '... 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 { + ok ! 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'; + }, '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..5958752 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 { + ok exception { Class::MOP::Attribute->new('$test' => ( default => qr/hello (.*)/ )); - } '... no refs for defaults'; + }, '... no refs for defaults'; - dies_ok { + ok exception { Class::MOP::Attribute->new('$test' => ( default => [] )); - } '... no refs for defaults'; + }, '... no refs for defaults'; - dies_ok { + ok exception { Class::MOP::Attribute->new('$test' => ( default => {} )); - } '... no refs for defaults'; + }, '... no refs for defaults'; - dies_ok { + ok exception { Class::MOP::Attribute->new('$test' => ( default => \(my $var) )); - } '... no refs for defaults'; + }, '... no refs for defaults'; - dies_ok { + ok exception { Class::MOP::Attribute->new('$test' => ( default => bless {} => 'Foo' )); - } '... no refs for defaults'; + }, '... no refs for defaults'; } { - dies_ok { + ok exception { Class::MOP::Attribute->new('$test' => ( builder => qr/hello (.*)/ )); - } '... no refs for builders'; + }, '... no refs for builders'; - dies_ok { + ok exception { Class::MOP::Attribute->new('$test' => ( builder => [] )); - } '... no refs for builders'; + }, '... no refs for builders'; - dies_ok { + ok exception { Class::MOP::Attribute->new('$test' => ( builder => {} )); - } '... no refs for builders'; + }, '... no refs for builders'; - dies_ok { + ok exception { Class::MOP::Attribute->new('$test' => ( builder => \(my $var) )); - } '... no refs for builders'; + }, '... no refs for builders'; - dies_ok { + ok exception { Class::MOP::Attribute->new('$test' => ( builder => bless {} => 'Foo' )); - } '... no refs for builders'; + }, '... no refs for builders'; - dies_ok { + ok exception { Class::MOP::Attribute->new('$test' => ( builder => 'Foo', default => 'Foo' )); - } '... no default AND builder'; + }, '... no default AND builder'; my $undef_attr; - lives_ok { + ok ! exception { $undef_attr = Class::MOP::Attribute->new('$test' => ( default => undef, predicate => 'has_test', )); - } '... undef as a default is okay'; + }, '... 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,7 +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 } + ok ! exception { Foo->meta->make_immutable }, '... and it can be inlined'; { my $obj = Foo->new; @@ -113,33 +113,33 @@ use Class::MOP::Attribute; { # bad construtor args - dies_ok { + ok exception { Class::MOP::Attribute->new(); - } '... no name argument'; + }, '... no name argument'; # These are no longer errors - lives_ok { + ok ! exception { Class::MOP::Attribute->new(''); - } '... bad name argument'; + }, '... bad name argument'; - lives_ok { + ok ! exception { Class::MOP::Attribute->new(0); - } '... bad name argument'; + }, '... bad name argument'; } { my $attr = Class::MOP::Attribute->new('$test'); - dies_ok { + ok exception { $attr->attach_to_class(); - } '... attach_to_class died as expected'; + }, '... attach_to_class died as expected'; - dies_ok { + ok exception { $attr->attach_to_class('Fail'); - } '... attach_to_class died as expected'; + }, '... attach_to_class died as expected'; - dies_ok { + ok exception { $attr->attach_to_class(bless {} => 'Fail'); - } '... attach_to_class died as expected'; + }, '... attach_to_class died as expected'; } { @@ -149,17 +149,17 @@ use Class::MOP::Attribute; $attr->attach_to_class(Class::MOP::Class->initialize('Foo')); - dies_ok { + ok exception { $attr->install_accessors; - } '... bad reader format'; + }, '... bad reader format'; } { my $attr = Class::MOP::Attribute->new('$test'); - dies_ok { + ok exception { $attr->_process_accessors('fail', 'my_failing_sub'); - } '... cannot find "fail" type generator'; + }, '... cannot find "fail" type generator'; } @@ -174,9 +174,9 @@ use Class::MOP::Attribute; reader => 'test' )); - dies_ok { + ok exception { $attr->install_accessors; - } '... failed to generate accessors correctly'; + }, '... failed to generate accessors correctly'; } { @@ -207,27 +207,27 @@ use Class::MOP::Attribute; # it works, which is kinda silly, but it # tests the API change, so I keep it. - lives_ok { + ok ! exception { Class::MOP::Attribute->new('$foo', ( accessor => 'foo', reader => 'get_foo', )); - } '... can create accessors with reader/writers'; + }, '... can create accessors with reader/writers'; - lives_ok { + ok ! exception { Class::MOP::Attribute->new('$foo', ( accessor => 'foo', writer => 'set_foo', )); - } '... can create accessors with reader/writers'; + }, '... can create accessors with reader/writers'; - lives_ok { + ok ! exception { Class::MOP::Attribute->new('$foo', ( accessor => 'foo', reader => 'get_foo', writer => 'set_foo', )); - } '... can create accessors with reader/writers'; + }, '... can create accessors with reader/writers'; } done_testing; diff --git a/t/030_method.t b/t/030_method.t index 89605f0..63889a9 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,20 +28,20 @@ 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 } +ok exception { Class::MOP::Method->wrap }, q{... can't call wrap() without some code}; -dies_ok { Class::MOP::Method->wrap( [] ) } +ok exception { Class::MOP::Method->wrap( [] ) }, q{... can't call wrap() without some code}; -dies_ok { Class::MOP::Method->wrap( bless {} => 'Fail' ) } +ok exception { Class::MOP::Method->wrap( bless {} => 'Fail' ) }, q{... can't call wrap() without some code}; -dies_ok { Class::MOP::Method->name } +ok exception { Class::MOP::Method->name }, q{... can't call name() as a class method}; -dies_ok { Class::MOP::Method->body } +ok exception { Class::MOP::Method->body }, q{... can't call body() as a class method}; -dies_ok { Class::MOP::Method->package_name } +ok exception { Class::MOP::Method->package_name }, q{... can't call package_name() as a class method}; -dies_ok { Class::MOP::Method->fully_qualified_name } +ok exception { Class::MOP::Method->fully_qualified_name }, q{... can't call fully_qualified_name() as a class method}; my $meta = Class::MOP::Method->meta; @@ -63,40 +63,40 @@ foreach my $method_name ( '... our sub name is "' . $method_name . '"' ); } -dies_ok { +ok exception { Class::MOP::Method->wrap(); -} +}, '... bad args for &wrap'; -dies_ok { +ok exception { Class::MOP::Method->wrap('Fail'); -} +}, '... bad args for &wrap'; -dies_ok { +ok exception { Class::MOP::Method->wrap( [] ); -} +}, '... bad args for &wrap'; -dies_ok { +ok exception { Class::MOP::Method->wrap( sub {'FAIL'} ); -} +}, '... bad args for &wrap'; -dies_ok { +ok exception { Class::MOP::Method->wrap( sub {'FAIL'}, package_name => 'main' ); -} +}, '... bad args for &wrap'; -dies_ok { +ok exception { Class::MOP::Method->wrap( sub {'FAIL'}, name => '__ANON__' ); -} +}, '... bad args for &wrap'; -lives_ok { +ok ! exception { Class::MOP::Method->wrap( bless( sub {'FAIL'}, "Foo" ), name => '__ANON__', package_name => 'Foo::Bar' ); -} +}, '... blessed coderef to &wrap'; my $clone = $method->clone( diff --git a/t/031_method_modifiers.t b/t/031_method_modifiers.t index ee5abf6..b509ee5 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,9 +31,9 @@ use Class::MOP::Method; '... got the right return value from the wrapped method' ); $trace = ''; - lives_ok { + ok ! exception { $wrapped->add_before_modifier( sub { $trace .= 'before -> ' } ); - } + }, '... added the before modifier okay'; $wrapped->(); @@ -42,9 +42,9 @@ use Class::MOP::Method; ); $trace = ''; - lives_ok { + ok ! exception { $wrapped->add_after_modifier( sub { $trace .= ' -> after' } ); - } + }, '... added the after modifier okay'; $wrapped->(); @@ -71,12 +71,12 @@ use Class::MOP::Method; is( $wrapped->(), 4, '... got the right value from the wrapped method' ); - lives_ok { + ok ! 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'; is_deeply( @@ -104,28 +104,28 @@ use Class::MOP::Method; isa_ok( $wrapped, 'Class::MOP::Method::Wrapped' ); isa_ok( $wrapped, 'Class::MOP::Method' ); - lives_ok { + ok ! 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'; - lives_ok { + ok ! 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'; - lives_ok { + ok ! 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'; $wrapped->(); diff --git a/t/041_metaclass_incompatibility.t b/t/041_metaclass_incompatibility.t index 5b0223f..84c45a0 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 { +ok ! exception { Foo::Meta::Class->create('Foo') -} '... Foo.meta => Foo::Meta::Class is compatible'; -lives_ok { +}, '... Foo.meta => Foo::Meta::Class is compatible'; +ok ! exception { Bar::Meta::Class->create('Bar') -} '... Bar.meta => Bar::Meta::Class is compatible'; +}, '... 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 { +ok ! exception { FooBar::Meta::Class->create('FooBar', superclasses => ['Foo']) -} '... FooBar.meta => FooBar::Meta::Class is compatible'; -lives_ok { +}, '... FooBar.meta => FooBar::Meta::Class is compatible'; +ok ! exception { FooBar::Meta::Class->create('FooBar2', superclasses => ['Bar']) -} '... FooBar2.meta => FooBar::Meta::Class is compatible'; +}, '... 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 { +ok ! exception { Class::MOP::Class->create('Foo::Foo::CMOP', superclasses => ['Foo']) -} 'metaclass fixing fixes a cmop metaclass, when the parent has a subclass'; +}, 'metaclass fixing fixes a cmop metaclass, when the parent has a subclass'; isa_ok(Foo::Foo::CMOP->meta, 'Foo::Meta::Class'); -lives_ok { +ok ! exception { Class::MOP::Class->create('Bar::Bar::CMOP', superclasses => ['Bar']) -} 'metaclass fixing fixes a cmop metaclass, when the parent has a subclass'; +}, 'metaclass fixing fixes a cmop metaclass, when the parent has a subclass'; isa_ok(Bar::Bar::CMOP->meta, 'Bar::Meta::Class'); -lives_ok { +ok ! 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'; +}, '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 { + ok ! 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"; + }, "$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,7 +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') } + like exception { $meta->superclasses('Foo::Unsafe') }, qr/compatibility.*pristine/, "can't switch out the attribute metaclass of a class that already has attributes"; } @@ -207,11 +207,11 @@ 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) } + ok ! exception { $bazmeta->superclasses($barmeta->name) }, "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"; + ok ! exception { $bazmeta->make_immutable }, "can still make immutable"; } # nonexistent metaclasses @@ -221,37 +221,37 @@ Class::MOP::Class->create( superclasses => ['Class::MOP::Method'], ); -lives_ok { +ok ! exception { Class::MOP::Class->create( 'Weird::Class', destructor_class => 'Weird::Meta::Method::Destructor', ); -} "defined metaclass in child with defined metaclass in parent is fine"; +}, "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 { +ok ! 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 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 { +ok ! exception { Class::MOP::Class->create( 'Weird::Class::Sub2', destructor_class => undef, ); -} "undef metaclass in child with defined metaclass in parent can be fixed"; +}, "undef metaclass in child with defined metaclass in parent can be fixed"; -lives_ok { +ok ! exception { Weird::Class::Sub2->meta->superclasses('Weird::Class'); -} "undef metaclass in child with defined metaclass in parent can be fixed"; +}, "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..49919d4 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"; +ok exception { $foo->child }, "Parent->child method doesn't exist"; Child->meta->rebless_instance($foo); is(blessed($foo), 'Child', 'rebless_instance really reblessed the instance'); @@ -41,22 +41,22 @@ 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) } +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) } +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"; +ok exception { $foo->child }, "Parent->child method doesn't exist"; -throws_ok { LeftField->meta->rebless_instance_back($foo) } +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) } +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 diff --git a/t/047_rebless_with_extra_params.t b/t/047_rebless_with_extra_params.t index 17af892..fc8d6b5 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 { + ok ! exception { Bar->meta->rebless_instance($foo) - } '... this works'; + }, '... 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 { + ok ! exception { Foo->meta->rebless_instance_back($foo) - } '... this works'; + }, '... 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 { + ok ! exception { Bar->meta->rebless_instance($foo, (baz => 'FOO-BAZ')) - } '... this works'; + }, '... 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 { + ok ! exception { Foo->meta->rebless_instance_back($foo) - } '... this works'; + }, '... 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 { + ok ! exception { Bar->meta->rebless_instance($foo, (bar => 'FOO-BAR', baz => 'FOO-BAZ')) - } '... this works'; + }, '... 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 { + ok ! exception { Foo->meta->rebless_instance_back($foo) - } '... this works'; + }, '... 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..089c775 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 { + ok ! exception { $bar_meta = $meta_name->initialize('Bar'); - } "we can use the name on its own"; + }, "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..76e742d 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 { +ok ! exception { $meta = $meta->reinitialize($meta->name); }; check_meta_sanity($meta, 'Foo'); -lives_ok { +ok ! exception { $meta = $meta->reinitialize($meta); }; 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,7 +67,7 @@ $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 { +ok ! exception { $meta = $meta->reinitialize('Bar'); }; check_meta_sanity($meta, 'Bar'); @@ -79,7 +79,7 @@ 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 { +ok ! exception { $meta = $meta->reinitialize('Bar'); }; is(Bar->meta->get_method('foo')->test, 'FOO'); @@ -107,7 +107,7 @@ $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 { +ok ! exception { $meta = $meta->reinitialize( 'Baz', attribute_metaclass => '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,7 +157,7 @@ throws_ok { $meta = Quuux->meta; check_meta_sanity($meta, 'Quuux'); ok($meta->has_method('bar')); -lives_ok { +ok ! exception { $meta = $meta->reinitialize( 'Quuux', attribute_metaclass => 'Quuux::Meta::Attribute', @@ -189,7 +189,7 @@ ok(!$meta->has_method('bar')); $meta = Class::MOP::class_of('Blah'); check_meta_sanity($meta, 'Blah'); -lives_ok { +ok ! exception { $meta = Class::MOP::Class->reinitialize( 'Blah', attribute_metaclass => 'Blah::Meta::Attribute', 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..0ec0c21 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,7 +45,7 @@ my $instance; } undef $instance; -lives_and { +ok ! exception { my $foo = Foo::Sub->new; isa_ok($foo, 'Foo'); isa_ok($foo, 'Foo::Sub'); @@ -53,7 +53,7 @@ lives_and { }; undef $instance; -lives_and { +ok ! exception { my $foo = Foo::Sub->new(foo => 'FOO'); isa_ok($foo, 'Foo'); isa_ok($foo, 'Foo::Sub'); @@ -62,7 +62,7 @@ lives_and { }; undef $instance; -lives_and { +ok ! exception { my $foo = Foo::Sub->new(bar => 'bar'); isa_ok($foo, 'Foo'); isa_ok($foo, 'Foo::Sub'); @@ -71,7 +71,7 @@ lives_and { }; undef $instance; -lives_and { +ok ! exception { my $foo = Foo::Sub->new(foo => 'FOO', bar => 'bar'); isa_ok($foo, 'Foo'); isa_ok($foo, 'Foo::Sub'); @@ -117,25 +117,25 @@ lives_and { ); } -throws_ok { BadFoo::Sub->new } +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..f926ad3 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,43 +83,43 @@ 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'; + ok exception { $meta->add_method() }, '... exception thrown as expected'; + ok exception { $meta->alias_method() }, '... exception thrown as expected'; + ok exception { $meta->remove_method() }, '... exception thrown as expected'; - dies_ok { $meta->add_attribute() } '... exception thrown as expected'; - dies_ok { $meta->remove_attribute() } '... exception thrown as expected'; + ok exception { $meta->add_attribute() }, '... exception thrown as expected'; + ok exception { $meta->remove_attribute() }, '... exception thrown as expected'; - dies_ok { $meta->add_package_symbol() } + ok exception { $meta->add_package_symbol() }, '... exception thrown as expected'; - dies_ok { $meta->remove_package_symbol() } + ok exception { $meta->remove_package_symbol() }, '... exception thrown as expected'; - lives_ok { $meta->identifier() } + ok ! exception { $meta->identifier() }, '... no exception for get_package_symbol special case'; my @supers; - lives_ok { + ok ! exception { @supers = $meta->superclasses; - } + }, '... got the superclasses okay'; - dies_ok { $meta->superclasses( ['UNIVERSAL'] ) } + ok exception { $meta->superclasses( ['UNIVERSAL'] ) }, '... but could not set the superclasses okay'; my $meta_instance; - lives_ok { + ok ! exception { $meta_instance = $meta->get_meta_instance; - } + }, '... 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 { + ok ! exception { @cpl = $meta->class_precedence_list; - } + }, '... got the class precedence list okay'; is_deeply( \@cpl, @@ -128,9 +128,9 @@ use Class::MOP; ); my @attributes; - lives_ok { + ok ! exception { @attributes = $meta->get_all_attributes; - } + }, '... got the attribute list okay'; is_deeply( \@attributes, @@ -146,9 +146,9 @@ use Class::MOP; ok( $meta->is_mutable, '... our class is mutable' ); ok( !$meta->is_immutable, '... our class is not immutable' ); - lives_ok { + ok ! exception { $meta->make_immutable(); - } + }, '... changed Bar to be immutable'; ok( !$meta->make_immutable, '... make immutable now returns nothing' ); @@ -158,40 +158,40 @@ 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'; + ok exception { $meta->add_method() }, '... exception thrown as expected'; + ok exception { $meta->alias_method() }, '... exception thrown as expected'; + ok exception { $meta->remove_method() }, '... exception thrown as expected'; - dies_ok { $meta->add_attribute() } '... exception thrown as expected'; - dies_ok { $meta->remove_attribute() } '... exception thrown as expected'; + ok exception { $meta->add_attribute() }, '... exception thrown as expected'; + ok exception { $meta->remove_attribute() }, '... exception thrown as expected'; - dies_ok { $meta->add_package_symbol() } + ok exception { $meta->add_package_symbol() }, '... exception thrown as expected'; - dies_ok { $meta->remove_package_symbol() } + ok exception { $meta->remove_package_symbol() }, '... exception thrown as expected'; my @supers; - lives_ok { + ok ! exception { @supers = $meta->superclasses; - } + }, '... got the superclasses okay'; - dies_ok { $meta->superclasses( ['UNIVERSAL'] ) } + ok exception { $meta->superclasses( ['UNIVERSAL'] ) }, '... but could not set the superclasses okay'; my $meta_instance; - lives_ok { + ok ! exception { $meta_instance = $meta->get_meta_instance; - } + }, '... 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 { + ok ! exception { @cpl = $meta->class_precedence_list; - } + }, '... got the class precedence list okay'; is_deeply( \@cpl, @@ -200,9 +200,9 @@ use Class::MOP; ); my @attributes; - lives_ok { + ok ! exception { @attributes = $meta->get_all_attributes; - } + }, '... got the attribute list okay'; is_deeply( [ sort { $a->name cmp $b->name } @attributes ], @@ -218,9 +218,9 @@ use Class::MOP; ok( $meta->is_mutable, '... our class is mutable' ); ok( !$meta->is_immutable, '... our class is not immutable' ); - lives_ok { + ok ! exception { $meta->make_immutable(); - } + }, '... changed Baz to be immutable'; ok( !$meta->make_immutable, '... make immutable now returns nothing' ); @@ -230,40 +230,40 @@ 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'; + ok exception { $meta->add_method() }, '... exception thrown as expected'; + ok exception { $meta->alias_method() }, '... exception thrown as expected'; + ok exception { $meta->remove_method() }, '... exception thrown as expected'; - dies_ok { $meta->add_attribute() } '... exception thrown as expected'; - dies_ok { $meta->remove_attribute() } '... exception thrown as expected'; + ok exception { $meta->add_attribute() }, '... exception thrown as expected'; + ok exception { $meta->remove_attribute() }, '... exception thrown as expected'; - dies_ok { $meta->add_package_symbol() } + ok exception { $meta->add_package_symbol() }, '... exception thrown as expected'; - dies_ok { $meta->remove_package_symbol() } + ok exception { $meta->remove_package_symbol() }, '... exception thrown as expected'; my @supers; - lives_ok { + ok ! exception { @supers = $meta->superclasses; - } + }, '... got the superclasses okay'; - dies_ok { $meta->superclasses( ['UNIVERSAL'] ) } + ok exception { $meta->superclasses( ['UNIVERSAL'] ) }, '... but could not set the superclasses okay'; my $meta_instance; - lives_ok { + ok ! exception { $meta_instance = $meta->get_meta_instance; - } + }, '... 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 { + ok ! exception { @cpl = $meta->class_precedence_list; - } + }, '... got the class precedence list okay'; is_deeply( \@cpl, @@ -272,9 +272,9 @@ use Class::MOP; ); my @attributes; - lives_ok { + ok ! exception { @attributes = $meta->get_all_attributes; - } + }, '... 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..fce35f4 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,7 +40,7 @@ use lib catdir( $FindBin::Bin, 'lib' ); shift->meta->mymetaclass_attributes; } - ::lives_ok{ Baz->meta->superclasses('Bar') } + ::ok ! ::exception { Baz->meta->superclasses('Bar') }, '... we survive the metaclass incompatibility test'; } @@ -58,7 +58,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"; + ok ! exception { $meta->make_immutable }, "Baz is now immutable"; ok( $meta->is_immutable, '... Baz is immutable' ); isa_ok( $meta, 'MyMetaClass', 'Baz->meta' ); ok( Baz->can('mymetaclass_attributes'), @@ -68,7 +68,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"; + ok ! exception { $meta->make_mutable }, "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..02613b3 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 { + ok ! exception { $meta->make_immutable( inline_constructor => 1, inline_accessors => 0, ); - } '... changed Foo to be immutable'; + }, '... 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 { + ok ! exception { $meta->make_immutable( inline_constructor => 1, inline_accessors => 1, ); - } '... changed Bar to be immutable'; + }, '... 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 { + ok ! exception { $meta->make_immutable( inline_constructor => 0, inline_accessors => 1, ); - } '... changed Bar to be immutable'; + }, '... 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'; + ::ok ! ::exception { $buzz = Buzz->meta->new_object }, '...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'; + ::ok ! ::exception { $buzz2 = Buzz->meta->new_object('bar' => 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'; + ::ok ! ::exception { $buzz = Buzz->meta->new_object }, '...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'; + ::ok ! ::exception { $buzz2 = Buzz->meta->new_object('bah' => 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..0ee9435 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'; + ok ! exception { $meta->make_immutable; }, '... 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'; + ok ! exception { $meta->make_mutable; }, '... 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'; + ok ! exception { $meta->remove_package_symbol('$ref') }, '... 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'; + ok ! exception { $meta->make_immutable; }, '... 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'; + ok ! exception { $meta->make_immutable() }, 'Changed Baz to be immutable'; + ok ! exception { $meta->make_mutable() }, '... changed Baz to be mutable'; + ok ! exception { $meta->make_immutable() }, '... changed Baz to be immutable'; - dies_ok{ $meta->add_method('xyz', sub{'xxx'}) } '... exception thrown as expected'; + ok exception { $meta->add_method('xyz', sub{'xxx'}) }, '... exception thrown as expected'; - dies_ok { + ok exception { $meta->add_attribute('fickle', accessor => 'fickle') - } '... exception thrown as expected'; - dies_ok { $meta->remove_attribute('fickle') } '... exception thrown as expected'; + }, '... exception thrown as expected'; + ok exception { $meta->remove_attribute('fickle') }, '... 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'; + ok exception { $meta->add_package_symbol('$ref', $reef) }, '... exception thrown as expected'; + ok exception { $meta->remove_package_symbol('$ref') }, '... exception thrown as expected'; ok( my @supers = $meta->superclasses, '... got the superclasses okay'); - dies_ok { $meta->superclasses('Foo') } '... set the superclasses'; + ok exception { $meta->superclasses('Foo') }, '... 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( + ok ! exception {$meta->make_immutable( inline_accessor => 1, inline_destructor => 0, inline_constructor => 1, ) - } '... changed class to be immutable'; + }, '... 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'; + ok ! exception { $meta->make_mutable }, '... 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'; + ok ! exception { $meta->remove_package_symbol('$ref') }, '... removed it'; isnt($meta->get_package_symbol('$ref'), $reef, '... values match'); ok( my @supers = $meta->superclasses, '... got the superclasses okay'); @@ -183,28 +183,29 @@ use Class::MOP; { my $meta = Baz->meta->create_anon_class(superclasses => ['Baz']); - lives_ok {$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'; + ok ! exception { + $meta->make_immutable( + inline_accessor => 1, + inline_destructor => 0, + inline_constructor => 1, + ) + }, '... changed class to be immutable'; + ok ! exception { $meta->make_mutable() }, '... changed class to be mutable'; + ok ! exception { $meta->make_immutable }, '... changed class to be immutable'; - dies_ok{ $meta->add_method('xyz', sub{'xxx'}) } '... exception thrown as expected'; + ok exception { $meta->add_method('xyz', sub{'xxx'}) }, '... exception thrown as expected'; - dies_ok { + ok exception { $meta->add_attribute('fickle', accessor => 'fickle') - } '... exception thrown as expected'; - dies_ok { $meta->remove_attribute('fickle') } '... exception thrown as expected'; + }, '... exception thrown as expected'; + ok exception { $meta->remove_attribute('fickle') }, '... 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'; + ok exception { $meta->add_package_symbol('$ref', $reef) }, '... exception thrown as expected'; + ok exception { $meta->remove_package_symbol('$ref') }, '... exception thrown as expected'; ok( my @supers = $meta->superclasses, '... got the superclasses okay'); - dies_ok { $meta->superclasses('Foo') } '... set the superclasses'; + ok exception { $meta->superclasses('Foo') }, '... 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..cbc75f1 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,7 +61,7 @@ use Class::MOP; __PACKAGE__->meta->add_attribute('bar'); - ::lives_ok { __PACKAGE__->meta->make_immutable } + ::ok ! ::exception { __PACKAGE__->meta->make_immutable }, '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..a06bb27 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}; +ok exception { Class::MOP::Package->get_all_package_symbols }, q{... can't call get_all_package_symbols() as a class method}; +ok exception { Class::MOP::Package->name }, 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 { +ok ! exception { Foo->meta->add_package_symbol('%foo' => { one => 1 }); -} '... created %Foo::foo successfully'; +}, '... 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 { +ok ! exception { Foo->meta->add_package_symbol('@bar' => [ 1, 2, 3 ]); -} '... created @Foo::bar successfully'; +}, '... 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 { +ok ! exception { Foo->meta->add_package_symbol('$baz' => 10); -} '... created $Foo::baz successfully'; +}, '... 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 { +ok ! exception { Foo->meta->add_package_symbol('&funk' => sub { "Foo::funk" }); -} '... created &Foo::funk successfully'; +}, '... 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 { +ok ! exception { Foo->meta->add_package_symbol('@foo' => $ARRAY); -} '... created @Foo::foo successfully'; +}, '... 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 { +ok ! exception { Foo->meta->add_package_symbol('&foo' => $CODE); -} '... created &Foo::foo successfully'; +}, '... 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 { +ok ! exception { Foo->meta->add_package_symbol('$foo' => 'Foo::foo'); -} '... created $Foo::foo successfully'; +}, '... 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 { +ok ! exception { Foo->meta->remove_package_symbol('%foo'); -} '... removed %Foo::foo successfully'; +}, '... 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 { +ok ! exception { Foo->meta->remove_package_symbol('&foo'); -} '... removed &Foo::foo successfully'; +}, '... 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 { +ok ! exception { Foo->meta->remove_package_symbol('$foo'); -} '... removed $Foo::foo successfully'; +}, '... 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..98a10a2 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 { +ok ! exception { $meta->add_package_symbol('%foo' => { one => 1 }); -} '... the %foo symbol is created succcessfully'; +}, '... 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 { +ok ! exception { $meta->add_package_symbol('@bar' => [ 1, 2, 3 ]); -} '... created @Foo::bar successfully'; +}, '... 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 { +ok ! exception { $meta->add_package_symbol('%baz'); -} '... created %Foo::baz successfully'; +}, '... 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..7ef2ebf 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 { +ok exception { Class::MOP::is_class_loaded() -} "is_class_loaded with no argument dies"; +}, "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,28 +43,28 @@ 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 /; -throws_ok { +like exception { Class::MOP::load_class('SyntaxError'); -} +}, 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'; -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'; @@ -73,9 +73,9 @@ qr{Can't locate This/Does/Not/Exist\.pm in \@INC}, use constant foo => "bar"; } -lives_ok { +ok ! exception { ok(Class::MOP::is_class_loaded("Other"), 'is_class_loaded(Other)'); -} +}, "a class with just constants is still a class"; { @@ -83,14 +83,14 @@ lives_ok { use metaclass; } -lives_ok { +ok ! 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'; +}, '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 +157,23 @@ 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/, + }, qr/Class::WithVersion version 42 required--this is only version 23/, 'load_first_existing_class gives correct exception on old version'; - lives_ok { + ok ! exception { Class::MOP::load_first_existing_class('Affe', 'Tiger', 'Class::WithVersion' => { -version => 13 }); - } 'loading class with required version with load_first_existing_class'; + }, '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/, + }, qr/Class::WithVersion version 42 required--this is only version 23/, 'load_class gives correct exception on old version'; - lives_ok { + ok ! exception { Class::MOP::load_class('Class::WithVersion' => { -version => 13 }); - } 'loading class with required version with load_class'; + }, '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..7a7faf8 100644 --- a/t/085_load_class_gvstash_detect_bug.t +++ b/t/085_load_class_gvstash_detect_bug.t @@ -1,22 +1,22 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Class::MOP; use lib 't/lib'; -lives_ok { +ok ! exception { Class::MOP::load_class('TestClassLoaded::Sub'); }; TestClassLoaded->can('a_method'); -lives_ok { +ok ! exception { Class::MOP::load_class('TestClassLoaded'); }; -lives_ok { +ok ! exception { TestClassLoaded->a_method; }; diff --git a/t/090_meta_method.t b/t/090_meta_method.t index 774b8b3..7a8a805 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"; + ok ! exception { $meta->find_method_by_name('meta') }, "can do meta-level stuff"; + ok ! exception { $meta->make_immutable }, "can do meta-level stuff"; + ok ! exception { $meta->class_precedence_list }, "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"; + ok ! exception { $meta->find_method_by_name('meta') }, "can do meta-level stuff"; + ok ! exception { $meta->make_immutable }, "can do meta-level stuff"; + ok ! exception { $meta->class_precedence_list }, "can do meta-level stuff"; } done_testing; diff --git a/t/100_BinaryTree_test.t b/t/100_BinaryTree_test.t index 285994f..339397f 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 { +ok ! exception { Class::MOP::load_class('BinaryTree'); -} '... loaded the BinaryTree class without dying'; +}, '... 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..e9dea6d 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 { +ok ! exception { Foo->meta->superclasses('Bar'); -} "regular subclass"; +}, "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..aeeb14c 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 }; + ok ! exception { $meta_method->execute },; } done_testing; diff --git a/t/313_before_after_dollar_under.t b/t/313_before_after_dollar_under.t index 01d8da1..1ebef2c 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,11 +29,11 @@ for my $wrap (qw(before after)) { %results = (); my $o = $meta->get_meta_instance->create_instance; isa_ok( $o, 'Base' ); - lives_ok { + ok ! 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'; is_deeply( \%results, { base => 2, wrapped => 2 }, @@ -57,11 +57,11 @@ for my $wrap (qw(before after)) { %results = (); my $o = $meta->get_meta_instance->create_instance; isa_ok( $o, 'Base' ); - lives_ok { + ok ! 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'; is_deeply( \%results, { base => 2, wrapped => 4 }, diff --git a/t/315_magic.t b/t/315_magic.t index 2259d6a..b417e48 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)'; + ok ! exception { Class::MOP::load_class($value) }, 'load_class(tied scalar)'; $value = undef; $x->STORE('Class::MOP'); # reset - lives_and{ + ok ! exception { ok Class::MOP::is_class_loaded($value); - } 'is_class_loaded(tied scalar)'; + }, 'is_class_loaded(tied scalar)'; $value = undef; $x->STORE(\&Class::MOP::get_code_info); # reset - lives_and{ + ok ! exception { is_deeply [Class::MOP::get_code_info($value)], [qw(Class::MOP get_code_info)], 'get_code_info(tied scalar)'; - } + }; } done_testing; diff --git a/t/500_deprecated.t b/t/500_deprecated.t index df0eaf5..b474992 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,9 +11,9 @@ $SIG{__WARN__} = \&croak; { package Foo; - ::throws_ok{ + ::like ::exception { Class::MOP::in_global_destruction(); - } qr/\b deprecated \b/xmsi, + }, qr/\b deprecated \b/xmsi, 'Class::MOP::in_global_destruction is deprecated'; } @@ -22,9 +22,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, + }, qr/\b deprecated \b/xmsi, 'Class::MOP::in_global_destruction is deprecated with 0.93 compatibility'; } @@ -33,9 +33,9 @@ $SIG{__WARN__} = \&croak; use Class::MOP::Deprecated -api_version => 0.92; - ::lives_ok{ + ::ok ! ::exception { Class::MOP::in_global_destruction(); - } + }, 'Class::MOP::in_global_destruction is not deprecated with 0.92 compatibility'; } @@ -44,7 +44,7 @@ $SIG{__WARN__} = \&croak; use metaclass; - ::throws_ok{ Foo2->meta->get_attribute_map } + ::like ::exception { Foo2->meta->get_attribute_map }, qr/\Qget_attribute_map method has been deprecated/, 'get_attribute_map is deprecated'; }