From: Dave Rolsky Date: Thu, 28 Oct 2010 21:49:43 +0000 (-0500) Subject: Revert "convert all uses of Test::Exception to Test::Fatal." X-Git-Tag: 1.11~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8371f3de4e9525ab751008dca4a89e6df65345a6;p=gitmo%2FClass-MOP.git Revert "convert all uses of Test::Exception to Test::Fatal." This reverts commit 13b8971fa6cc4edf7d55a2e5482820d62ba38f16. Conflicts: Makefile.PL --- diff --git a/t/001_basic.t b/t/001_basic.t index b782491..f45712d 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Fatal; +use Test::Exception; use Class::MOP; use Class::MOP::Class; diff --git a/t/003_methods.t b/t/003_methods.t index de128e4..5340b44 100644 --- a/t/003_methods.t +++ b/t/003_methods.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Fatal; +use Test::Exception; 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' ); -ok ! exception { +lives_ok { $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' ); -ok exception { Foo->foo }, '... cannot call Foo->foo because it is not there'; +dies_ok { 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' ); -ok ! exception { +lives_ok { $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 84aadb8..b67cdac 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::Fatal; +use Test::Exception; use Class::MOP; use Class::MOP::Class; diff --git a/t/005_attributes.t b/t/005_attributes.t index 036a5b8..fa10b41 100644 --- a/t/005_attributes.t +++ b/t/005_attributes.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Fatal; +use Test::Exception; use Class::MOP; @@ -31,17 +31,17 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); use metaclass; my $meta = Foo->meta; - ::ok ! ::exception { + ::lives_ok { $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'); - ::ok ! ::exception { + ::lives_ok { $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; - ::ok ! ::exception { + ::lives_ok { $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; - ::ok ! ::exception { + ::lives_ok { $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; - ok ! exception { + lives_ok { $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; - ok ! exception { + lives_ok { $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; - ok ! exception { + lives_ok { $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; - ::ok ! ::exception { + ::lives_ok { $meta->add_attribute($FOO_ATTR_2); - }, '... we added an attribute to Buzz successfully'; + } '... we added an attribute to Buzz successfully'; - ::ok ! ::exception { + ::lives_ok { $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'; - ::ok ! ::exception { + ::lives_ok { $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'; - ::ok ! ::exception { + ::lives_ok { $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; - ::ok ! ::exception { $buzz = Buzz->meta->new_object }, '...Buzz instantiated successfully'; + ::lives_ok { $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; - ::ok ! ::exception { $buzz2 = Buzz->meta->new_object('$bar' => undef) }, '...Buzz instantiated successfully'; + ::lives_ok { $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; - ::ok ! ::exception { $buzz3 = Buzz->meta->new_object }, '...Buzz instantiated successfully'; + ::lives_ok { $buzz3 = Buzz->meta->new_object } '...Buzz instantiated successfully'; ::ok($buzz3->has_bah, '...bah is set'); ::is($buzz3->bah, 'BAH', '...bah returns "BAH" '); my $buzz4; - ::ok ! ::exception { $buzz4 = Buzz->meta->new_object('$bah' => undef) }, '...Buzz instantiated successfully'; + ::lives_ok { $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 b91f25c..6c2a21d 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::Fatal; +use Test::Exception; use Class::MOP; @@ -100,9 +100,9 @@ isnt($cloned_foo, $foo, '... $cloned_foo is a new object different from $foo'); # check some errors -ok exception { +dies_ok { $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 d16e252..207f94f 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::Fatal; +use Test::Exception; use Class::MOP; use Class::MOP::Class; diff --git a/t/011_create_class.t b/t/011_create_class.t index 1770990..2267b5e 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::Fatal; +use Test::Exception; 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'); -ok exception { +dies_ok { $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 61c555d..98d62cf 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::Fatal; +use Test::Exception; 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'); -ok ! exception { +lives_ok { 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'); -ok ! exception { +lives_ok { 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'); -ok ! exception { +lives_ok { 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'); -ok ! exception { +lives_ok { 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" }; -ok ! exception { +lives_ok { 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'); -ok ! exception { +lives_ok { 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'); -ok ! exception { +lives_ok { 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'); } -ok ! exception { +lives_ok { 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'); } -ok ! exception { +lives_ok { 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'); } -ok ! exception { +lives_ok { 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 b40fc8f..4cfb338 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::Fatal; +use Test::Exception; 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'); -ok exception { +dies_ok { $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 112b9c0..7b77803 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::Fatal; +use Test::Exception; use Class::MOP; diff --git a/t/015_metaclass_inheritance.t b/t/015_metaclass_inheritance.t index 49a5298..fc784c5 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::Fatal; +use Test::Exception; use Class::MOP; diff --git a/t/016_class_errors_and_edge_cases.t b/t/016_class_errors_and_edge_cases.t index 20103d3..18429c5 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::Fatal; +use Test::Exception; use Class::MOP; { - ok exception { + dies_ok { Class::MOP::Class->initialize(); - }, '... initialize requires a name parameter'; + } '... initialize requires a name parameter'; - ok exception { + dies_ok { Class::MOP::Class->initialize(''); - }, '... initialize requires a name valid parameter'; + } '... initialize requires a name valid parameter'; - ok exception { + dies_ok { Class::MOP::Class->initialize(bless {} => 'Foo'); - }, '... initialize requires an unblessed parameter' + } '... initialize requires an unblessed parameter' } { - ok exception { + dies_ok { Class::MOP::Class->_construct_class_instance(); - }, '... _construct_class_instance requires an :package parameter'; + } '... _construct_class_instance requires an :package parameter'; - ok exception { + dies_ok { Class::MOP::Class->_construct_class_instance(':package' => undef); - }, '... _construct_class_instance requires a defined :package parameter'; + } '... _construct_class_instance requires a defined :package parameter'; - ok exception { + dies_ok { Class::MOP::Class->_construct_class_instance(':package' => ''); - }, '... _construct_class_instance requires a valid :package parameter'; + } '... _construct_class_instance requires a valid :package parameter'; } { - ok exception { + dies_ok { Class::MOP::Class->create(); - }, '... create requires an package_name parameter'; + } '... create requires an package_name parameter'; - ok exception { + dies_ok { Class::MOP::Class->create(undef); - }, '... create requires a defined package_name parameter'; + } '... create requires a defined package_name parameter'; - ok exception { + dies_ok { Class::MOP::Class->create(''); - }, '... create requires a valid package_name parameter'; + } '... create requires a valid package_name parameter'; - like exception { + throws_ok { 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'; } { - ok exception { + dies_ok { Class::MOP::Class->clone_object(1); - }, '... can only clone instances'; + } '... can only clone instances'; } { - ok exception { + dies_ok { Class::MOP::Class->add_method(); - }, '... add_method dies as expected'; + } '... add_method dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->add_method(''); - }, '... add_method dies as expected'; + } '... add_method dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->add_method('foo' => 'foo'); - }, '... add_method dies as expected'; + } '... add_method dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->add_method('foo' => []); - }, '... add_method dies as expected'; + } '... add_method dies as expected'; } { - ok exception { + dies_ok { Class::MOP::Class->has_method(); - }, '... has_method dies as expected'; + } '... has_method dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->has_method(''); - }, '... has_method dies as expected'; + } '... has_method dies as expected'; } { - ok exception { + dies_ok { Class::MOP::Class->get_method(); - }, '... get_method dies as expected'; + } '... get_method dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->get_method(''); - }, '... get_method dies as expected'; + } '... get_method dies as expected'; } { - ok exception { + dies_ok { Class::MOP::Class->remove_method(); - }, '... remove_method dies as expected'; + } '... remove_method dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->remove_method(''); - }, '... remove_method dies as expected'; + } '... remove_method dies as expected'; } { - ok exception { + dies_ok { Class::MOP::Class->find_all_methods_by_name(); - }, '... find_all_methods_by_name dies as expected'; + } '... find_all_methods_by_name dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->find_all_methods_by_name(''); - }, '... find_all_methods_by_name dies as expected'; + } '... find_all_methods_by_name dies as expected'; } { - ok exception { + dies_ok { Class::MOP::Class->add_attribute(bless {} => 'Foo'); - }, '... add_attribute dies as expected'; + } '... add_attribute dies as expected'; } { - ok exception { + dies_ok { Class::MOP::Class->has_attribute(); - }, '... has_attribute dies as expected'; + } '... has_attribute dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->has_attribute(''); - }, '... has_attribute dies as expected'; + } '... has_attribute dies as expected'; } { - ok exception { + dies_ok { Class::MOP::Class->get_attribute(); - }, '... get_attribute dies as expected'; + } '... get_attribute dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->get_attribute(''); - }, '... get_attribute dies as expected'; + } '... get_attribute dies as expected'; } { - ok exception { + dies_ok { Class::MOP::Class->remove_attribute(); - }, '... remove_attribute dies as expected'; + } '... remove_attribute dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->remove_attribute(''); - }, '... remove_attribute dies as expected'; + } '... remove_attribute dies as expected'; } { - ok exception { + dies_ok { Class::MOP::Class->add_package_symbol(); - }, '... add_package_symbol dies as expected'; + } '... add_package_symbol dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->add_package_symbol(''); - }, '... add_package_symbol dies as expected'; + } '... add_package_symbol dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->add_package_symbol('foo'); - }, '... add_package_symbol dies as expected'; + } '... add_package_symbol dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->add_package_symbol('&foo'); - }, '... add_package_symbol dies as expected'; + } '... add_package_symbol dies as expected'; -# like exception { +# throws_ok { # Class::MOP::Class->meta->add_package_symbol('@-'); # } qr/^Could not create package variable \(\@\-\) because/, # '... add_package_symbol dies as expected'; } { - ok exception { + dies_ok { Class::MOP::Class->has_package_symbol(); - }, '... has_package_symbol dies as expected'; + } '... has_package_symbol dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->has_package_symbol(''); - }, '... has_package_symbol dies as expected'; + } '... has_package_symbol dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->has_package_symbol('foo'); - }, '... has_package_symbol dies as expected'; + } '... has_package_symbol dies as expected'; } { - ok exception { + dies_ok { Class::MOP::Class->get_package_symbol(); - }, '... get_package_symbol dies as expected'; + } '... get_package_symbol dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->get_package_symbol(''); - }, '... get_package_symbol dies as expected'; + } '... get_package_symbol dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->get_package_symbol('foo'); - }, '... get_package_symbol dies as expected'; + } '... get_package_symbol dies as expected'; } { - ok exception { + dies_ok { Class::MOP::Class->remove_package_symbol(); - }, '... remove_package_symbol dies as expected'; + } '... remove_package_symbol dies as expected'; - ok exception { + dies_ok { Class::MOP::Class->remove_package_symbol(''); - }, '... remove_package_symbol dies as expected'; + } '... remove_package_symbol dies as expected'; - ok exception { + dies_ok { 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 97e9a62..a9c7945 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::Fatal; +use Test::Exception; use Class::MOP; @@ -65,11 +65,11 @@ use Class::MOP; } ); - ::like (::exception( + ::throws_ok( 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' ); -ok ! exception { +lives_ok { $savings_account->withdraw(50); -}, +} '... withdrew from savings successfully'; is( $savings_account->balance, 200, '... got the right savings balance after withdrawal' ); -ok exception { +dies_ok { $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' ); -ok ! exception { +lives_ok { $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)' ); -ok ! exception { +lives_ok { $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 d7a0197..d314e7a 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::Fatal; +use Test::Exception; use Class::MOP; @@ -31,18 +31,18 @@ my $anon_class_id; [$anon_class->superclasses], [], '... got an empty superclass list'); - ok ! exception { + lives_ok { $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'); - ok ! exception { + lives_ok { $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 4963a56..17aedac 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::Fatal; +use Test::Exception; use Class::MOP; diff --git a/t/020_attribute.t b/t/020_attribute.t index 6ca4624..48ddbf9 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::Fatal; +use Test::Exception; use Class::MOP; use Class::MOP::Attribute; use Class::MOP::Method; -ok exception { Class::MOP::Attribute->name }, q{... can't call name() as a class method}; +dies_ok { Class::MOP::Attribute->name } q{... can't call name() as a class method}; { @@ -42,9 +42,9 @@ ok exception { Class::MOP::Attribute->name }, q{... can't call name() as a class my $class = Class::MOP::Class->initialize('Foo'); isa_ok($class, 'Class::MOP::Class'); - ok ! exception { + lives_ok { $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 @@ ok exception { Class::MOP::Attribute->name }, q{... can't call name() as a class { for my $value ({}, bless({}, 'Foo')) { - like exception { + throws_ok { 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; - ok ! exception { + lives_ok { 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 5958752..d00d4c3 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::Fatal; +use Test::Exception; use Class::MOP; use Class::MOP::Attribute; @@ -10,84 +10,84 @@ use Class::MOP::Attribute; # most values are static { - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( default => qr/hello (.*)/ )); - }, '... no refs for defaults'; + } '... no refs for defaults'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( default => [] )); - }, '... no refs for defaults'; + } '... no refs for defaults'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( default => {} )); - }, '... no refs for defaults'; + } '... no refs for defaults'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( default => \(my $var) )); - }, '... no refs for defaults'; + } '... no refs for defaults'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( default => bless {} => 'Foo' )); - }, '... no refs for defaults'; + } '... no refs for defaults'; } { - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( builder => qr/hello (.*)/ )); - }, '... no refs for builders'; + } '... no refs for builders'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( builder => [] )); - }, '... no refs for builders'; + } '... no refs for builders'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( builder => {} )); - }, '... no refs for builders'; + } '... no refs for builders'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( builder => \(my $var) )); - }, '... no refs for builders'; + } '... no refs for builders'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( builder => bless {} => 'Foo' )); - }, '... no refs for builders'; + } '... no refs for builders'; - ok exception { + dies_ok { Class::MOP::Attribute->new('$test' => ( builder => 'Foo', default => 'Foo' )); - }, '... no default AND builder'; + } '... no default AND builder'; my $undef_attr; - ok ! exception { + lives_ok { $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'); } - ok ! exception { Foo->meta->make_immutable }, + lives_ok { Foo->meta->make_immutable } '... and it can be inlined'; { my $obj = Foo->new; @@ -113,33 +113,33 @@ use Class::MOP::Attribute; { # bad construtor args - ok exception { + dies_ok { Class::MOP::Attribute->new(); - }, '... no name argument'; + } '... no name argument'; # These are no longer errors - ok ! exception { + lives_ok { Class::MOP::Attribute->new(''); - }, '... bad name argument'; + } '... bad name argument'; - ok ! exception { + lives_ok { Class::MOP::Attribute->new(0); - }, '... bad name argument'; + } '... bad name argument'; } { my $attr = Class::MOP::Attribute->new('$test'); - ok exception { + dies_ok { $attr->attach_to_class(); - }, '... attach_to_class died as expected'; + } '... attach_to_class died as expected'; - ok exception { + dies_ok { $attr->attach_to_class('Fail'); - }, '... attach_to_class died as expected'; + } '... attach_to_class died as expected'; - ok exception { + dies_ok { $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')); - ok exception { + dies_ok { $attr->install_accessors; - }, '... bad reader format'; + } '... bad reader format'; } { my $attr = Class::MOP::Attribute->new('$test'); - ok exception { + dies_ok { $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' )); - ok exception { + dies_ok { $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. - ok ! exception { + lives_ok { Class::MOP::Attribute->new('$foo', ( accessor => 'foo', reader => 'get_foo', )); - }, '... can create accessors with reader/writers'; + } '... can create accessors with reader/writers'; - ok ! exception { + lives_ok { Class::MOP::Attribute->new('$foo', ( accessor => 'foo', writer => 'set_foo', )); - }, '... can create accessors with reader/writers'; + } '... can create accessors with reader/writers'; - ok ! exception { + lives_ok { 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 63889a9..89605f0 100644 --- a/t/030_method.t +++ b/t/030_method.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Fatal; +use Test::Exception; 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' ); -ok exception { Class::MOP::Method->wrap }, +dies_ok { Class::MOP::Method->wrap } q{... can't call wrap() without some code}; -ok exception { Class::MOP::Method->wrap( [] ) }, +dies_ok { Class::MOP::Method->wrap( [] ) } q{... can't call wrap() without some code}; -ok exception { Class::MOP::Method->wrap( bless {} => 'Fail' ) }, +dies_ok { Class::MOP::Method->wrap( bless {} => 'Fail' ) } q{... can't call wrap() without some code}; -ok exception { Class::MOP::Method->name }, +dies_ok { Class::MOP::Method->name } q{... can't call name() as a class method}; -ok exception { Class::MOP::Method->body }, +dies_ok { Class::MOP::Method->body } q{... can't call body() as a class method}; -ok exception { Class::MOP::Method->package_name }, +dies_ok { Class::MOP::Method->package_name } q{... can't call package_name() as a class method}; -ok exception { Class::MOP::Method->fully_qualified_name }, +dies_ok { 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 . '"' ); } -ok exception { +dies_ok { Class::MOP::Method->wrap(); -}, +} '... bad args for &wrap'; -ok exception { +dies_ok { Class::MOP::Method->wrap('Fail'); -}, +} '... bad args for &wrap'; -ok exception { +dies_ok { Class::MOP::Method->wrap( [] ); -}, +} '... bad args for &wrap'; -ok exception { +dies_ok { Class::MOP::Method->wrap( sub {'FAIL'} ); -}, +} '... bad args for &wrap'; -ok exception { +dies_ok { Class::MOP::Method->wrap( sub {'FAIL'}, package_name => 'main' ); -}, +} '... bad args for &wrap'; -ok exception { +dies_ok { Class::MOP::Method->wrap( sub {'FAIL'}, name => '__ANON__' ); -}, +} '... bad args for &wrap'; -ok ! exception { +lives_ok { 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 b509ee5..ee5abf6 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::Fatal; +use Test::Exception; 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 = ''; - ok ! exception { + lives_ok { $wrapped->add_before_modifier( sub { $trace .= 'before -> ' } ); - }, + } '... added the before modifier okay'; $wrapped->(); @@ -42,9 +42,9 @@ use Class::MOP::Method; ); $trace = ''; - ok ! exception { + lives_ok { $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' ); - ok ! exception { + lives_ok { $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' ); - ok ! exception { + lives_ok { $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'; - ok ! exception { + lives_ok { $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'; - ok ! exception { + lives_ok { $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 84c45a0..5b0223f 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::Fatal; +use Test::Exception; use metaclass; @@ -32,79 +32,79 @@ for my $suffix ('Class', keys %metaclass_attrs) { # checking... -ok ! exception { +lives_ok { Foo::Meta::Class->create('Foo') -}, '... Foo.meta => Foo::Meta::Class is compatible'; -ok ! exception { +} '... Foo.meta => Foo::Meta::Class is compatible'; +lives_ok { Bar::Meta::Class->create('Bar') -}, '... Bar.meta => Bar::Meta::Class is compatible'; +} '... Bar.meta => Bar::Meta::Class is compatible'; -like exception { +throws_ok { Bar::Meta::Class->create('Foo::Foo', superclasses => ['Foo']) -}, qr/compatible/, '... Foo::Foo.meta => Bar::Meta::Class is not compatible'; -like exception { +} qr/compatible/, '... Foo::Foo.meta => Bar::Meta::Class is not compatible'; +throws_ok { 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'; -ok ! exception { +lives_ok { FooBar::Meta::Class->create('FooBar', superclasses => ['Foo']) -}, '... FooBar.meta => FooBar::Meta::Class is compatible'; -ok ! exception { +} '... FooBar.meta => FooBar::Meta::Class is compatible'; +lives_ok { 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, ); -like exception { +throws_ok { 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) { - like exception { + throws_ok { 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... -ok ! exception { +lives_ok { 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'); -ok ! exception { +lives_ok { 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'); -ok ! exception { +lives_ok { 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) { - ok ! exception { + lives_ok { 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'); - like exception { $meta->superclasses('Foo::Unsafe') }, + throws_ok { $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); - ok ! exception { $bazmeta->superclasses($barmeta->name) }, + lives_ok { $bazmeta->superclasses($barmeta->name) } "can still set superclasses"; ok(!$bazmeta->is_immutable, "immutable superclass doesn't make this class immutable"); - ok ! exception { $bazmeta->make_immutable }, "can still make immutable"; + lives_ok { $bazmeta->make_immutable } "can still make immutable"; } # nonexistent metaclasses @@ -221,37 +221,37 @@ Class::MOP::Class->create( superclasses => ['Class::MOP::Method'], ); -ok ! exception { +lives_ok { 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"); -ok ! exception { +lives_ok { 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"); -ok ! exception { +lives_ok { 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"; -ok ! exception { +lives_ok { 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 49919d4..7eb0f68 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::Fatal; +use Test::Exception; 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'); -ok exception { $foo->child }, "Parent->child method doesn't exist"; +dies_ok { $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'); -like exception { LeftField->meta->rebless_instance($foo) }, +throws_ok { LeftField->meta->rebless_instance($foo) } qr/You may rebless only into a subclass of \(Child\), of which \(LeftField\) isn't\./; -like exception { Class::MOP::Class->initialize("NonExistent")->rebless_instance($foo) }, +throws_ok { Class::MOP::Class->initialize("NonExistent")->rebless_instance($foo) } qr/You may rebless only into a subclass of \(Child\), of which \(NonExistent\) isn't\./; 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'); -ok exception { $foo->child }, "Parent->child method doesn't exist"; +dies_ok { $foo->child } "Parent->child method doesn't exist"; -like exception { LeftField->meta->rebless_instance_back($foo) }, +throws_ok { LeftField->meta->rebless_instance_back($foo) } qr/You may rebless only into a superclass of \(Parent\), of which \(LeftField\) isn't\./; -like exception { Class::MOP::Class->initialize("NonExistent")->rebless_instance_back($foo) }, +throws_ok { Class::MOP::Class->initialize("NonExistent")->rebless_instance_back($foo) } qr/You may rebless only into a superclass of \(Parent\), of which \(NonExistent\) isn't\./; # 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 fc8d6b5..17af892 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::Fatal; +use Test::Exception; 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'); - ok ! exception { + lives_ok { 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'); - ok ! exception { + lives_ok { 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'); - ok ! exception { + lives_ok { 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'); - ok ! exception { + lives_ok { 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'); - ok ! exception { + lives_ok { 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'); - ok ! exception { + lives_ok { 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 089c775..b362eae 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::Fatal; +use Test::Exception; use Class::MOP; @@ -124,9 +124,9 @@ my $instance; ok(Class::MOP::class_of($meta_name), "metaclass still exists"); { my $bar_meta; - ok ! exception { + lives_ok { $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 76e742d..7d8dd50 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::Fatal; +use Test::Exception; { package Foo; @@ -26,23 +26,23 @@ can_ok('Foo', 'meta'); my $meta = Foo->meta; check_meta_sanity($meta, 'Foo'); -ok ! exception { +lives_ok { $meta = $meta->reinitialize($meta->name); }; check_meta_sanity($meta, 'Foo'); -ok ! exception { +lives_ok { $meta = $meta->reinitialize($meta); }; check_meta_sanity($meta, 'Foo'); -like exception { +throws_ok { $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/; -like exception { +throws_ok { $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'); -ok ! exception { +lives_ok { $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'); -ok ! exception { +lives_ok { $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')); -ok ! exception { +lives_ok { $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'); -like exception { +throws_ok { $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 @@ like exception { $meta = Quuux->meta; check_meta_sanity($meta, 'Quuux'); ok($meta->has_method('bar')); -ok ! exception { +lives_ok { $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'); -ok ! exception { +lives_ok { $meta = Class::MOP::Class->reinitialize( 'Blah', attribute_metaclass => 'Blah::Meta::Attribute', diff --git a/t/060_instance.t b/t/060_instance.t index 5ab6a55..d61e628 100644 --- a/t/060_instance.t +++ b/t/060_instance.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Fatal; +use Test::Exception; use Scalar::Util qw/isweak reftype/; diff --git a/t/061_instance_inline.t b/t/061_instance_inline.t index 7100c80..ec61805 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::Fatal; +use Test::Exception; use Class::MOP::Instance; diff --git a/t/062_custom_instance.t b/t/062_custom_instance.t index 0ec0c21..da03fdb 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::Fatal; +use Test::Exception; use Class::MOP; @@ -45,7 +45,7 @@ my $instance; } undef $instance; -ok ! exception { +lives_and { my $foo = Foo::Sub->new; isa_ok($foo, 'Foo'); isa_ok($foo, 'Foo::Sub'); @@ -53,7 +53,7 @@ ok ! exception { }; undef $instance; -ok ! exception { +lives_and { my $foo = Foo::Sub->new(foo => 'FOO'); isa_ok($foo, 'Foo'); isa_ok($foo, 'Foo::Sub'); @@ -62,7 +62,7 @@ ok ! exception { }; undef $instance; -ok ! exception { +lives_and { my $foo = Foo::Sub->new(bar => 'bar'); isa_ok($foo, 'Foo'); isa_ok($foo, 'Foo::Sub'); @@ -71,7 +71,7 @@ ok ! exception { }; undef $instance; -ok ! exception { +lives_and { my $foo = Foo::Sub->new(foo => 'FOO', bar => 'bar'); isa_ok($foo, 'Foo'); isa_ok($foo, 'Foo::Sub'); @@ -117,25 +117,25 @@ ok ! exception { ); } -like exception { BadFoo::Sub->new }, +throws_ok { BadFoo::Sub->new } qr/BadFoo=HASH.*is not a BadFoo::Sub/, "error with incorrect constructors"; { my $meta = Class::MOP::Class->create('Really::Bad::Foo'); - like exception { + throws_ok { $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, '') { - like exception { + throws_ok { $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 f926ad3..74d470a 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::Fatal; +use Test::Exception; use Class::MOP; @@ -83,43 +83,43 @@ use Class::MOP; isa_ok( $meta, 'Class::MOP::Class' ); - 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_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_attribute() }, '... exception thrown as expected'; - ok exception { $meta->remove_attribute() }, '... 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_package_symbol() }, + dies_ok { $meta->add_package_symbol() } '... exception thrown as expected'; - ok exception { $meta->remove_package_symbol() }, + dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected'; - ok ! exception { $meta->identifier() }, + lives_ok { $meta->identifier() } '... no exception for get_package_symbol special case'; my @supers; - ok ! exception { + lives_ok { @supers = $meta->superclasses; - }, + } '... got the superclasses okay'; - ok exception { $meta->superclasses( ['UNIVERSAL'] ) }, + dies_ok { $meta->superclasses( ['UNIVERSAL'] ) } '... but could not set the superclasses okay'; my $meta_instance; - ok ! exception { + lives_ok { $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; - ok ! exception { + lives_ok { @cpl = $meta->class_precedence_list; - }, + } '... got the class precedence list okay'; is_deeply( \@cpl, @@ -128,9 +128,9 @@ use Class::MOP; ); my @attributes; - ok ! exception { + lives_ok { @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' ); - ok ! exception { + lives_ok { $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' ); - 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_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_attribute() }, '... exception thrown as expected'; - ok exception { $meta->remove_attribute() }, '... 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_package_symbol() }, + dies_ok { $meta->add_package_symbol() } '... exception thrown as expected'; - ok exception { $meta->remove_package_symbol() }, + dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected'; my @supers; - ok ! exception { + lives_ok { @supers = $meta->superclasses; - }, + } '... got the superclasses okay'; - ok exception { $meta->superclasses( ['UNIVERSAL'] ) }, + dies_ok { $meta->superclasses( ['UNIVERSAL'] ) } '... but could not set the superclasses okay'; my $meta_instance; - ok ! exception { + lives_ok { $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; - ok ! exception { + lives_ok { @cpl = $meta->class_precedence_list; - }, + } '... got the class precedence list okay'; is_deeply( \@cpl, @@ -200,9 +200,9 @@ use Class::MOP; ); my @attributes; - ok ! exception { + lives_ok { @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' ); - ok ! exception { + lives_ok { $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' ); - 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_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_attribute() }, '... exception thrown as expected'; - ok exception { $meta->remove_attribute() }, '... 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_package_symbol() }, + dies_ok { $meta->add_package_symbol() } '... exception thrown as expected'; - ok exception { $meta->remove_package_symbol() }, + dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected'; my @supers; - ok ! exception { + lives_ok { @supers = $meta->superclasses; - }, + } '... got the superclasses okay'; - ok exception { $meta->superclasses( ['UNIVERSAL'] ) }, + dies_ok { $meta->superclasses( ['UNIVERSAL'] ) } '... but could not set the superclasses okay'; my $meta_instance; - ok ! exception { + lives_ok { $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; - ok ! exception { + lives_ok { @cpl = $meta->class_precedence_list; - }, + } '... got the class precedence list okay'; is_deeply( \@cpl, @@ -272,9 +272,9 @@ use Class::MOP; ); my @attributes; - ok ! exception { + lives_ok { @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 fce35f4..92c5f8a 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::Fatal; +use Test::Exception; use Scalar::Util; use Class::MOP; @@ -40,7 +40,7 @@ use lib catdir( $FindBin::Bin, 'lib' ); shift->meta->mymetaclass_attributes; } - ::ok ! ::exception { Baz->meta->superclasses('Bar') }, + ::lives_ok{ 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' ); - ok ! exception { $meta->make_immutable }, "Baz is now immutable"; + lives_ok { $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' ); - ok ! exception { $meta->make_mutable }, "Baz is now mutable"; + lives_ok { $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 02613b3..21b2ce8 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::Fatal; +use Test::Exception; use Class::MOP; @@ -81,12 +81,12 @@ use Class::MOP; ok(!$meta->is_immutable, '... our class is not immutable'); - ok ! exception { + lives_ok { $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'); - ok ! exception { + lives_ok { $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'); - ok ! exception { + lives_ok { $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; - ::ok ! ::exception { $buzz = Buzz->meta->new_object }, '...Buzz instantiated successfully'; + ::lives_ok { $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; - ::ok ! ::exception { $buzz2 = Buzz->meta->new_object('bar' => undef) }, '...Buzz instantiated successfully'; + ::lives_ok { $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; - ::ok ! ::exception { $buzz = Buzz->meta->new_object }, '...Buzz instantiated successfully'; + ::lives_ok { $buzz = Buzz->meta->new_object } '...Buzz instantiated successfully'; ::ok($buzz->has_bah, '...bah is set'); ::is($buzz->bah, 'BAH', '...bah returns "BAH"' ); my $buzz2; - ::ok ! ::exception { $buzz2 = Buzz->meta->new_object('bah' => undef) }, '...Buzz instantiated successfully'; + ::lives_ok { $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 0ee9435..4070b5c 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::Fatal; +use Test::Exception; 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. - ok ! exception { $meta->make_immutable; }, '... changed Baz to be immutable'; + lives_ok {$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'); - ok ! exception { $meta->make_mutable; }, '... changed Baz to be mutable'; + lives_ok { $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'); - ok ! exception { $meta->remove_package_symbol('$ref') }, '... removed it'; + lives_ok { $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 ); - ok ! exception { $meta->make_immutable; }, '... changed Baz to be immutable again'; + lives_ok {$meta->make_immutable; } '... changed Baz to be immutable again'; ok($meta->get_method('new'), '... inlined constructor recreated'); } { my $meta = Baz->meta; - 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'; + 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->add_method('xyz', sub{'xxx'}) }, '... exception thrown as expected'; + dies_ok{ $meta->add_method('xyz', sub{'xxx'}) } '... exception thrown as expected'; - ok exception { + dies_ok { $meta->add_attribute('fickle', accessor => 'fickle') - }, '... exception thrown as expected'; - ok exception { $meta->remove_attribute('fickle') }, '... exception thrown as expected'; + } '... exception thrown as expected'; + dies_ok { $meta->remove_attribute('fickle') } '... exception thrown as expected'; my $reef = \ 'reef'; - ok exception { $meta->add_package_symbol('$ref', $reef) }, '... exception thrown as expected'; - ok exception { $meta->remove_package_symbol('$ref') }, '... exception thrown as expected'; + dies_ok { $meta->add_package_symbol('$ref', $reef) } '... exception thrown as expected'; + dies_ok { $meta->remove_package_symbol('$ref') } '... exception thrown as expected'; ok( my @supers = $meta->superclasses, '... got the superclasses okay'); - ok exception { $meta->superclasses('Foo') }, '... set the superclasses'; + dies_ok { $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'); - ok ! exception {$meta->make_immutable( + lives_ok {$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'); - ok ! exception { $meta->make_mutable }, '... changed Baz to be mutable'; + lives_ok { $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'); - ok ! exception { $meta->remove_package_symbol('$ref') }, '... removed it'; + lives_ok { $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,29 +183,28 @@ use Class::MOP; { my $meta = Baz->meta->create_anon_class(superclasses => ['Baz']); - 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'; + 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->add_method('xyz', sub{'xxx'}) }, '... exception thrown as expected'; + dies_ok{ $meta->add_method('xyz', sub{'xxx'}) } '... exception thrown as expected'; - ok exception { + dies_ok { $meta->add_attribute('fickle', accessor => 'fickle') - }, '... exception thrown as expected'; - ok exception { $meta->remove_attribute('fickle') }, '... exception thrown as expected'; + } '... exception thrown as expected'; + dies_ok { $meta->remove_attribute('fickle') } '... exception thrown as expected'; my $reef = \ 'reef'; - ok exception { $meta->add_package_symbol('$ref', $reef) }, '... exception thrown as expected'; - ok exception { $meta->remove_package_symbol('$ref') }, '... exception thrown as expected'; + dies_ok { $meta->add_package_symbol('$ref', $reef) } '... exception thrown as expected'; + dies_ok { $meta->remove_package_symbol('$ref') } '... exception thrown as expected'; ok( my @supers = $meta->superclasses, '... got the superclasses okay'); - ok exception { $meta->superclasses('Foo') }, '... set the superclasses'; + dies_ok { $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 cbc75f1..0139317 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::Fatal; +use Test::Exception; use Class::MOP; @@ -61,7 +61,7 @@ use Class::MOP; __PACKAGE__->meta->add_attribute('bar'); - ::ok ! ::exception { __PACKAGE__->meta->make_immutable }, + ::lives_ok { __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 a06bb27..a5d55fa 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::Fatal; +use Test::Exception; use Class::MOP; use Class::MOP::Package; -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}; +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}; { 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'); -ok ! exception { +lives_ok { 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'); -ok ! exception { +lives_ok { 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'); -ok ! exception { +lives_ok { 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'); -ok ! exception { +lives_ok { 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" }; -ok ! exception { +lives_ok { 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'); -ok ! exception { +lives_ok { 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'); -ok ! exception { +lives_ok { 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'); } -ok ! exception { +lives_ok { 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'); } -ok ! exception { +lives_ok { 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'); } -ok ! exception { +lives_ok { 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 98a10a2..c8b2735 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::Fatal; +use Test::Exception; 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'); -ok ! exception { +lives_ok { $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'); -ok ! exception { +lives_ok { $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'); -ok ! exception { +lives_ok { $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 7ef2ebf..b2a41ef 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::Fatal; +use Test::Exception; require Class::MOP; use lib 't/lib'; -ok exception { +dies_ok { 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}); -like exception { Class::MOP::load_class('bogus name') }, qr/Invalid class name \(bogus name\)/; +throws_ok { Class::MOP::load_class('bogus name') } qr/Invalid class name \(bogus name\)/; -like exception { +throws_ok { 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" ); -like exception { +throws_ok { Class::MOP::load_class('FakeClassOhNo'); -}, +} qr/Can't locate /; -like exception { +throws_ok { Class::MOP::load_class('SyntaxError'); -}, +} qr/Missing right curly/; -like exception { +throws_ok { 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'; -like exception { +throws_ok { 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"; } -ok ! exception { +lives_ok { ok(Class::MOP::is_class_loaded("Other"), 'is_class_loaded(Other)'); -}, +} "a class with just constants is still a class"; { @@ -83,14 +83,14 @@ ok ! exception { use metaclass; } -ok ! exception { +lives_ok { 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'; -like exception { +throws_ok { 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 @@ like exception { ok( !Class::MOP::is_class_loaded('Class::WithVersion', { -version => 42 }), 'version 23 does not satisfy version requirement 42' ); - like exception { + throws_ok { 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'; - ok ! exception { + lives_ok { 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'; - like exception { + throws_ok { 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'; - ok ! exception { + lives_ok { 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 7a7faf8..91e6171 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::Fatal; +use Test::Exception; use Class::MOP; use lib 't/lib'; -ok ! exception { +lives_ok { Class::MOP::load_class('TestClassLoaded::Sub'); }; TestClassLoaded->can('a_method'); -ok ! exception { +lives_ok { Class::MOP::load_class('TestClassLoaded'); }; -ok ! exception { +lives_ok { TestClassLoaded->a_method; }; diff --git a/t/090_meta_method.t b/t/090_meta_method.t index 7a8a805..774b8b3 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::Fatal; +use Test::Exception; 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' }); - 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"; + 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"; } { 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' }); - 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"; + 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"; } done_testing; diff --git a/t/100_BinaryTree_test.t b/t/100_BinaryTree_test.t index 339397f..285994f 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::Fatal; +use Test::Exception; 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'); -ok ! exception { +lives_ok { 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 2373453..c52f1a8 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::Fatal; +use Test::Exception; use Class::MOP; diff --git a/t/303_RT_39001_fix.t b/t/303_RT_39001_fix.t index e9dea6d..210d715 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::Fatal; +use Test::Exception; use Class::MOP; @@ -16,9 +16,9 @@ This tests a bug sent via RT #39001 use metaclass; } -like exception { +throws_ok { 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 @@ like exception { # if DEBUG_NO_META is set) @Foo::ISA = (); -ok ! exception { +lives_ok { Foo->meta->superclasses('Bar'); -}, "regular subclass"; +} "regular subclass"; -like exception { +throws_ok { 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 aeeb14c..15e5c43 100644 --- a/t/305_RT_41255.t +++ b/t/305_RT_41255.t @@ -1,6 +1,6 @@ use strict; use Test::More; -use Test::Fatal; +use Test::Exception; 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}"; - like exception { $meta_method->execute }, qr/Undefined subroutine .* called at/; + throws_ok { $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}"; - ok ! exception { $meta_method->execute },; + lives_ok { $meta_method->execute }; } done_testing; diff --git a/t/313_before_after_dollar_under.t b/t/313_before_after_dollar_under.t index 1ebef2c..01d8da1 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::Fatal; +use Test::Exception; 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' ); - ok ! exception { + lives_ok { $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' ); - ok ! exception { + lives_ok { $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 b417e48..2259d6a 100755 --- a/t/315_magic.t +++ b/t/315_magic.t @@ -5,7 +5,7 @@ use strict; use warnings; use Test::More; -use Test::Fatal; +use Test::Exception; use Class::MOP; @@ -55,21 +55,21 @@ use Tie::Scalar; { my $x = tie my $value, 'Tie::StdScalar', 'Class::MOP'; - ok ! exception { Class::MOP::load_class($value) }, 'load_class(tied scalar)'; + lives_ok{ Class::MOP::load_class($value) } 'load_class(tied scalar)'; $value = undef; $x->STORE('Class::MOP'); # reset - ok ! exception { + lives_and{ 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 - ok ! exception { + lives_and{ 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 b474992..df0eaf5 100755 --- a/t/500_deprecated.t +++ b/t/500_deprecated.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Fatal; +use Test::Exception; use Carp; @@ -11,9 +11,9 @@ $SIG{__WARN__} = \&croak; { package Foo; - ::like ::exception { + ::throws_ok{ 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; - ::like ::exception { + ::throws_ok{ 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; - ::ok ! ::exception { + ::lives_ok{ 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; - ::like ::exception { Foo2->meta->get_attribute_map }, + ::throws_ok{ Foo2->meta->get_attribute_map } qr/\Qget_attribute_map method has been deprecated/, 'get_attribute_map is deprecated'; }