From: Dave Rolsky Date: Thu, 28 Oct 2010 21:47:42 +0000 (-0500) Subject: Redid conversion to Test::Fatal X-Git-Tag: 1.18~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b10dde3a27c11623547417c599ccbd4f92e42651;p=gitmo%2FMoose.git Redid conversion to Test::Fatal Also checking in the tool I used to do the conversion. --- diff --git a/author/convert-to-test-fatal b/author/convert-to-test-fatal new file mode 100755 index 0000000..f829d21 --- /dev/null +++ b/author/convert-to-test-fatal @@ -0,0 +1,128 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use File::Slurp qw( write_file ); +use PPI; + +rewrite_doc($_) for grep { -w } @ARGV; + +sub rewrite_doc { + my $file = shift; + + my $doc = PPI::Document->new($file); + + return unless $doc =~ /Test::Exception/; + + print $file, "\n"; + + my $pattern = sub { + my $elt = $_[1]; + + return 1 + if $elt->isa('PPI::Statement') + && $elt->content() + =~ /^\s*(?:::)?(?:lives_|throws_|dies_)(?:ok|and)/; + + return 0; + }; + + for my $elt ( @{ $doc->find($pattern) || [] } ) { + transform_statement($elt); + } + + my $content = $doc->content(); + $content =~ s/Test::Exception/Test::Fatal/g; + + write_file( $file, $content ); +} + +sub transform_statement { + my $stmt = shift; + + my @children = $stmt->schildren; + + my $func = shift @children; + + my $colons = $func =~ /^::/ ? '::' : q{}; + + my $code; + if ( $func =~ /lives_/ ) { + $code = function( + $colons . 'is', + $children[0], + 'undef', + $children[1] + ); + } + elsif ( $func =~ /dies_/ ) { + $code = function( + $colons . 'isnt', + $children[0], + 'undef', + $children[1] + ); + } + elsif ( $func =~ /throws_/ ) { + + # $children[2] is always a comma if it exists + if ( $children[1]->isa('PPI::Token::QuoteLike::Regexp') ) { + $code = function( + $colons . 'like', + $children[0], + $children[1], + $children[3] + ); + } + else { + $code = function( + $colons . 'is', + $children[0], + $children[1], + $children[3] + ); + } + } + + $stmt->insert_before($code); + $stmt->remove; +} + +sub function { + my $func = shift; + my $exception = shift; + my $expect = shift; + my $desc = shift; + + my $exc_func = $func =~ /^::/ ? '::exception' : 'exception'; + + my @code; + + push @code, + PPI::Token::Word->new($func), + PPI::Token::Structure->new('('), + PPI::Token::Whitespace->new(q{ }), + PPI::Token::Word->new($exc_func), + PPI::Token::Whitespace->new(q{ }), + $exception->clone, + PPI::Token::Operator->new(','), + PPI::Token::Whitespace->new(q{ }), + ( ref $expect ? $expect->clone : PPI::Token::Word->new($expect) ); + + if ( $desc && $desc->isa('PPI::Token::Quote') ) { + push @code, PPI::Token::Operator->new(','), + PPI::Token::Whitespace->new(q{ }), + $desc->clone; + } + + push @code, + PPI::Token::Whitespace->new(q{ }), + PPI::Token::Structure->new(')'), + PPI::Token::Structure->new(';'); + + my $stmt = PPI::Statement->new; + $stmt->add_element($_) for @code; + + return $stmt; +} diff --git a/author/extract-inline-tests b/author/extract-inline-tests index 77fb246..8cdb4cc 100755 --- a/author/extract-inline-tests +++ b/author/extract-inline-tests @@ -76,7 +76,7 @@ use warnings; my $base = $self->SUPER::process(@_); - $base =~ s/(\$\| = 1;)/use Test::Exception;\n$1/; + $base =~ s/(\$\| = 1;)/use Test::Fatal;\n$1/; return $base; } diff --git a/lib/Moose/Cookbook/Basics/Recipe1.pod b/lib/Moose/Cookbook/Basics/Recipe1.pod index 8fe4a8c..367a000 100644 --- a/lib/Moose/Cookbook/Basics/Recipe1.pod +++ b/lib/Moose/Cookbook/Basics/Recipe1.pod @@ -250,15 +250,21 @@ is( $point->y, 2, '... got the right value for y' ); $point->y(10); is( $point->y, 10, '... got the right (changed) value for y' ); -dies_ok { - $point->y('Foo'); -} -'... cannot assign a non-Int to y'; +isnt( + exception { + $point->y('Foo'); + }, + undef, + '... cannot assign a non-Int to y' +); -dies_ok { - Point->new(); -} -'... must provide required attributes to new'; +isnt( + exception { + Point->new(); + }, + undef, + '... must provide required attributes to new' +); $point->clear(); @@ -267,20 +273,29 @@ is( $point->y, 0, '... got the right (cleared) value for y' ); # check the type constraints on the constructor -lives_ok { - Point->new( x => 0, y => 0 ); -} -'... can assign a 0 to x and y'; +is( + exception { + Point->new( x => 0, y => 0 ); + }, + undef, + '... can assign a 0 to x and y' +); -dies_ok { - Point->new( x => 10, y => 'Foo' ); -} -'... cannot assign a non-Int to y'; +isnt( + exception { + Point->new( x => 10, y => 'Foo' ); + }, + undef, + '... cannot assign a non-Int to y' +); -dies_ok { - Point->new( x => 'Foo', y => 10 ); -} -'... cannot assign a non-Int to x'; +isnt( + exception { + Point->new( x => 'Foo', y => 10 ); + }, + undef, + '... cannot assign a non-Int to x' +); # Point3D @@ -299,25 +314,37 @@ is( $point3d->x, 0, '... got the right (cleared) value for x' ); is( $point3d->y, 0, '... got the right (cleared) value for y' ); is( $point3d->z, 0, '... got the right (cleared) value for z' ); -dies_ok { - Point3D->new( x => 10, y => 'Foo', z => 3 ); -} -'... cannot assign a non-Int to y'; +isnt( + exception { + Point3D->new( x => 10, y => 'Foo', z => 3 ); + }, + undef, + '... cannot assign a non-Int to y' +); -dies_ok { - Point3D->new( x => 'Foo', y => 10, z => 3 ); -} -'... cannot assign a non-Int to x'; +isnt( + exception { + Point3D->new( x => 'Foo', y => 10, z => 3 ); + }, + undef, + '... cannot assign a non-Int to x' +); -dies_ok { - Point3D->new( x => 0, y => 10, z => 'Bar' ); -} -'... cannot assign a non-Int to z'; +isnt( + exception { + Point3D->new( x => 0, y => 10, z => 'Bar' ); + }, + undef, + '... cannot assign a non-Int to z' +); -dies_ok { - Point3D->new( x => 10, y => 3 ); -} -'... z is a required attribute for Point3D'; +isnt( + exception { + Point3D->new( x => 10, y => 3 ); + }, + undef, + '... z is a required attribute for Point3D' +); # test some class introspection @@ -327,8 +354,10 @@ isa_ok( Point->meta, 'Moose::Meta::Class' ); can_ok( 'Point3D', 'meta' ); isa_ok( Point3D->meta, 'Moose::Meta::Class' ); -isnt( Point->meta, Point3D->meta, - '... they are different metaclasses as well' ); +isnt( + Point->meta, Point3D->meta, + '... they are different metaclasses as well' +); # poke at Point diff --git a/lib/Moose/Cookbook/Basics/Recipe2.pod b/lib/Moose/Cookbook/Basics/Recipe2.pod index 9f1a4dd..abb50ec 100644 --- a/lib/Moose/Cookbook/Basics/Recipe2.pod +++ b/lib/Moose/Cookbook/Basics/Recipe2.pod @@ -236,10 +236,13 @@ my $savings_account; isa_ok( $savings_account, 'BankAccount' ); is( $savings_account->balance, 250, '... got the right savings balance' ); - lives_ok { - $savings_account->withdraw(50); - } - '... withdrew from savings successfully'; + is( + exception { + $savings_account->withdraw(50); + }, + undef, + '... withdrew from savings successfully' + ); is( $savings_account->balance, 200, '... got the right savings balance after withdrawl' ); @@ -262,20 +265,26 @@ my $savings_account; is( $checking_account->balance, 100, '... got the right checkings balance' ); - lives_ok { - $checking_account->withdraw(50); - } - '... withdrew from checking successfully'; + is( + exception { + $checking_account->withdraw(50); + }, + undef, + '... withdrew from checking successfully' + ); is( $checking_account->balance, 50, '... got the right checkings balance after withdrawl' ); is( $savings_account->balance, 350, '... got the right savings balance after checking withdrawl (no overdraft)' ); - lives_ok { - $checking_account->withdraw(200); - } - '... withdrew from checking successfully'; + is( + exception { + $checking_account->withdraw(200); + }, + undef, + '... withdrew from checking successfully' + ); is( $checking_account->balance, 0, '... got the right checkings balance after withdrawl' ); is( $savings_account->balance, 200, @@ -297,17 +306,23 @@ my $savings_account; is( $checking_account->balance, 100, '... got the right checkings balance' ); - lives_ok { - $checking_account->withdraw(50); - } - '... withdrew from checking successfully'; + is( + exception { + $checking_account->withdraw(50); + }, + undef, + '... withdrew from checking successfully' + ); is( $checking_account->balance, 50, '... got the right checkings balance after withdrawl' ); - dies_ok { - $checking_account->withdraw(200); - } - '... withdrawl failed due to attempted overdraft'; + isnt( + exception { + $checking_account->withdraw(200); + }, + undef, + '... withdrawal failed due to attempted overdraft' + ); is( $checking_account->balance, 50, '... got the right checkings balance after withdrawl failure' ); } diff --git a/lib/Moose/Cookbook/Basics/Recipe3.pod b/lib/Moose/Cookbook/Basics/Recipe3.pod index 1028ecd..84e7da5 100644 --- a/lib/Moose/Cookbook/Basics/Recipe3.pod +++ b/lib/Moose/Cookbook/Basics/Recipe3.pod @@ -261,9 +261,13 @@ ok(!$left->has_right, '... $left no right node yet'); is($left->node, undef, '... left has got no node value'); -lives_ok { - $left->node('left') -} '... assign to lefts node'; +is( + exception { + $left->node('left'); + }, + undef, + '... assign to lefts node' +); is($left->node, 'left', '... left now has a node value'); @@ -278,9 +282,13 @@ ok($root->has_right, '... now we have a right node'); my $right = $root->right; isa_ok($right, 'BinaryTree'); -lives_ok { - $right->node('right') -} '... assign to rights node'; +is( + exception { + $right->node('right'); + }, + undef, + '... assign to rights node' +); is($right->node, 'right', '... left now has a node value'); @@ -310,9 +318,13 @@ ok(isweak($left_left->{parent}), '... parent is a weakened ref'); my $left_right = BinaryTree->new; isa_ok($left_right, 'BinaryTree'); -lives_ok { - $left->right($left_right) -} '... assign to rights node'; +is( + exception { + $left->right($left_right); + }, + undef, + '... assign to rights node' +); ok($left_right->has_parent, '... left does have a parent'); @@ -324,9 +336,13 @@ ok(isweak($left_right->{parent}), '... parent is a weakened ref'); # and check the error -dies_ok { - $left_right->right($left_left) -} '... cant assign a node which already has a parent'; +isnt( + exception { + $left_right->right($left_left); + }, + undef, + '... cannot assign a node which already has a parent' +); =end testing diff --git a/lib/Moose/Cookbook/Basics/Recipe4.pod b/lib/Moose/Cookbook/Basics/Recipe4.pod index 325b43b..0a10695 100644 --- a/lib/Moose/Cookbook/Basics/Recipe4.pod +++ b/lib/Moose/Cookbook/Basics/Recipe4.pod @@ -315,44 +315,49 @@ it under the same terms as Perl itself. use Scalar::Util 'isweak'; my $ii; -lives_ok { - $ii = Company->new( - { - name => 'Infinity Interactive', - address => Address->new( - street => '565 Plandome Rd., Suite 307', - city => 'Manhasset', - state => 'NY', - zip_code => '11030' - ), - employees => [ - Employee->new( - first_name => 'Jeremy', - last_name => 'Shao', - title => 'President / Senior Consultant', - address => - Address->new( city => 'Manhasset', state => 'NY' ) +is( + exception { + $ii = Company->new( + { + name => 'Infinity Interactive', + address => Address->new( + street => '565 Plandome Rd., Suite 307', + city => 'Manhasset', + state => 'NY', + zip_code => '11030' ), - Employee->new( - first_name => 'Tommy', - last_name => 'Lee', - title => 'Vice President / Senior Developer', - address => - Address->new( city => 'New York', state => 'NY' ) - ), - Employee->new( - first_name => 'Stevan', - middle_initial => 'C', - last_name => 'Little', - title => 'Senior Developer', - address => - Address->new( city => 'Madison', state => 'CT' ) - ), - ] - } - ); -} -'... created the entire company successfully'; + employees => [ + Employee->new( + first_name => 'Jeremy', + last_name => 'Shao', + title => 'President / Senior Consultant', + address => Address->new( + city => 'Manhasset', state => 'NY' + ) + ), + Employee->new( + first_name => 'Tommy', + last_name => 'Lee', + title => 'Vice President / Senior Developer', + address => + Address->new( city => 'New York', state => 'NY' ) + ), + Employee->new( + first_name => 'Stevan', + middle_initial => 'C', + last_name => 'Little', + title => 'Senior Developer', + address => + Address->new( city => 'Madison', state => 'CT' ) + ), + ] + } + ); + }, + undef, + '... created the entire company successfully' +); + isa_ok( $ii, 'Company' ); is( $ii->name, 'Infinity Interactive', @@ -460,55 +465,85 @@ foreach my $employee ( @{ $new_company->employees } ) { ## check some error conditions for the subtypes -dies_ok { - Address->new( street => {} ),; -} -'... we die correctly with bad args'; - -dies_ok { - Address->new( city => {} ),; -} -'... we die correctly with bad args'; - -dies_ok { - Address->new( state => 'British Columbia' ),; -} -'... we die correctly with bad args'; - -lives_ok { - Address->new( state => 'Connecticut' ),; -} -'... we live correctly with good args'; - -dies_ok { - Address->new( zip_code => 'AF5J6$' ),; -} -'... we die correctly with bad args'; - -lives_ok { - Address->new( zip_code => '06443' ),; -} -'... we live correctly with good args'; - -dies_ok { - Company->new(),; -} -'... we die correctly without good args'; - -lives_ok { - Company->new( name => 'Foo' ),; -} -'... we live correctly without good args'; - -dies_ok { - Company->new( name => 'Foo', employees => [ Person->new ] ),; -} -'... we die correctly with good args'; - -lives_ok { - Company->new( name => 'Foo', employees => [] ),; -} -'... we live correctly with good args'; +isnt( + exception { + Address->new( street => {} ),; + }, + undef, + '... we die correctly with bad args' +); + +isnt( + exception { + Address->new( city => {} ),; + }, + undef, + '... we die correctly with bad args' +); + +isnt( + exception { + Address->new( state => 'British Columbia' ),; + }, + undef, + '... we die correctly with bad args' +); + +is( + exception { + Address->new( state => 'Connecticut' ),; + }, + undef, + '... we live correctly with good args' +); + +isnt( + exception { + Address->new( zip_code => 'AF5J6$' ),; + }, + undef, + '... we die correctly with bad args' +); + +is( + exception { + Address->new( zip_code => '06443' ),; + }, + undef, + '... we live correctly with good args' +); + +isnt( + exception { + Company->new(),; + }, + undef, + '... we die correctly without good args' +); + +is( + exception { + Company->new( name => 'Foo' ),; + }, + undef, + '... we live correctly without good args' +); + +isnt( + exception { + Company->new( name => 'Foo', employees => [ Person->new ] ),; + }, + undef, + '... we die correctly with good args' +); + +is( + exception { + Company->new( name => 'Foo', employees => [] ),; + }, + undef, + '... we live correctly with good args' +); =end testing diff --git a/lib/Moose/Cookbook/Basics/Recipe5.pod b/lib/Moose/Cookbook/Basics/Recipe5.pod index d901d57..7a6f3ed 100644 --- a/lib/Moose/Cookbook/Basics/Recipe5.pod +++ b/lib/Moose/Cookbook/Basics/Recipe5.pod @@ -257,25 +257,35 @@ isa_ok( $r, 'Request' ); is( $header4->content_type, 'application/pdf', '... got the right content type in the header' ); - dies_ok { - $r->headers('Foo'); - } - '... dies when it gets bad params'; + isnt( + exception { + $r->headers('Foo'); + }, + undef, + '... dies when it gets bad params' + ); } { is( $r->protocol, undef, '... got nothing by default' ); - lives_ok { - $r->protocol('HTTP/1.0'); - } - '... set the protocol correctly'; + is( + exception { + $r->protocol('HTTP/1.0'); + }, + undef, + '... set the protocol correctly' + ); + is( $r->protocol, 'HTTP/1.0', '... got nothing by default' ); - dies_ok { - $r->protocol('http/1.0'); - } - '... the protocol died with bar params correctly'; + isnt( + exception { + $r->protocol('http/1.0'); + }, + undef, + '... the protocol died with bar params correctly' + ); } { diff --git a/t/010_basics/001_basic_class_setup.t b/t/010_basics/001_basic_class_setup.t index b8130f9..03db813 100644 --- a/t/010_basics/001_basic_class_setup.t +++ b/t/010_basics/001_basic_class_setup.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -19,9 +19,9 @@ isa_ok(Foo->meta, 'Moose::Meta::Class'); ok(Foo->meta->has_method('meta'), '... we got the &meta method'); ok(Foo->isa('Moose::Object'), '... Foo is automagically a Moose::Object'); -dies_ok { +isnt( exception { Foo->meta->has_method() -} '... has_method requires an arg'; +}, undef, '... has_method requires an arg' ); can_ok('Foo', 'does'); diff --git a/t/010_basics/002_require_superclasses.t b/t/010_basics/002_require_superclasses.t index ad09165..e025e0b 100644 --- a/t/010_basics/002_require_superclasses.t +++ b/t/010_basics/002_require_superclasses.t @@ -6,7 +6,7 @@ use warnings; use lib 't/lib', 'lib'; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -14,7 +14,7 @@ use Test::Exception; package Bar; use Moose; - ::lives_ok { extends 'Foo' } 'loaded Foo superclass correctly'; + ::is( ::exception { extends 'Foo' }, undef, 'loaded Foo superclass correctly' ); } { @@ -22,7 +22,7 @@ use Test::Exception; package Baz; use Moose; - ::lives_ok { extends 'Bar' } 'loaded (inline) Bar superclass correctly'; + ::is( ::exception { extends 'Bar' }, undef, 'loaded (inline) Bar superclass correctly' ); } { @@ -30,8 +30,7 @@ use Test::Exception; package Foo::Bar; use Moose; - ::lives_ok { extends 'Foo', 'Bar' } - 'loaded Foo and (inline) Bar superclass correctly'; + ::is( ::exception { extends 'Foo', 'Bar' }, undef, 'loaded Foo and (inline) Bar superclass correctly' ); } { @@ -39,9 +38,7 @@ use Test::Exception; package Bling; use Moose; - ::throws_ok { extends 'No::Class' } - qr{Can't locate No/Class\.pm in \@INC}, - 'correct error when superclass could not be found'; + ::like( ::exception { extends 'No::Class' }, qr{Can't locate No/Class\.pm in \@INC}, 'correct error when superclass could not be found' ); } { @@ -53,17 +50,14 @@ use Test::Exception; package Tiger; use Moose; - ::lives_ok { extends 'Foo', Affe => { -version => 13 } } - 'extends with version requirement'; + ::is( ::exception { extends 'Foo', Affe => { -version => 13 } }, undef, 'extends with version requirement' ); } { package Birne; use Moose; - ::throws_ok { extends 'Foo', Affe => { -version => 42 } } - qr/Affe version 42 required--this is only version 23/, - 'extends with unsatisfied version requirement'; + ::like( ::exception { extends 'Foo', Affe => { -version => 42 } }, qr/Affe version 42 required--this is only version 23/, 'extends with unsatisfied version requirement' ); } done_testing; diff --git a/t/010_basics/003_super_and_override.t b/t/010_basics/003_super_and_override.t index 7ea63ea..9e2cc1d 100644 --- a/t/010_basics/003_super_and_override.t +++ b/t/010_basics/003_super_and_override.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -72,9 +72,9 @@ is($foo->baz(), 'Foo::baz', '... got the right value from &baz'); sub bling { 'Bling::bling' } - ::dies_ok { + ::isnt( ::exception { override 'bling' => sub {}; - } '... cannot override a method which has a local equivalent'; + }, undef, '... cannot override a method which has a local equivalent' ); } diff --git a/t/010_basics/004_inner_and_augment.t b/t/010_basics/004_inner_and_augment.t index eecd547..cbe96f5 100644 --- a/t/010_basics/004_inner_and_augment.t +++ b/t/010_basics/004_inner_and_augment.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -77,9 +77,9 @@ is($foo->baz(), 'Foo::baz()', '... got the right value from &baz'); sub bling { 'Bling::bling' } - ::dies_ok { + ::isnt( ::exception { augment 'bling' => sub {}; - } '... cannot augment a method which has a local equivalent'; + }, undef, '... cannot augment a method which has a local equivalent' ); } diff --git a/t/010_basics/010_method_modifier_with_regexp.t b/t/010_basics/010_method_modifier_with_regexp.t index bc51d34..2cc2776 100644 --- a/t/010_basics/010_method_modifier_with_regexp.t +++ b/t/010_basics/010_method_modifier_with_regexp.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -69,17 +69,17 @@ is( $Cat::AFTER_BARK_COUNTER, 2, 'after modifier is called twice' ); package Dog::Role; use Moose::Role; - ::dies_ok { + ::isnt( ::exception { before qr/bark.*/ => sub {}; - } '... this is not currently supported'; + }, undef, '... this is not currently supported' ); - ::dies_ok { + ::isnt( ::exception { around qr/bark.*/ => sub {}; - } '... this is not currently supported'; + }, undef, '... this is not currently supported' ); - ::dies_ok { + ::isnt( ::exception { after qr/bark.*/ => sub {}; - } '... this is not currently supported'; + }, undef, '... this is not currently supported' ); } diff --git a/t/010_basics/011_moose_respects_type_constraints.t b/t/010_basics/011_moose_respects_type_constraints.t index 3e0997a..3485a00 100644 --- a/t/010_basics/011_moose_respects_type_constraints.t +++ b/t/010_basics/011_moose_respects_type_constraints.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Util::TypeConstraints; @@ -50,12 +50,12 @@ ok(!$foo_constraint->check('Bar'), '... my constraint failed correctly'); my $bar = Bar->new; isa_ok($bar, 'Bar'); -lives_ok { +is( exception { $bar->foo('Foo'); -} '... checked the type constraint correctly'; +}, undef, '... checked the type constraint correctly' ); -dies_ok { +isnt( exception { $bar->foo(Foo->new); -} '... checked the type constraint correctly'; +}, undef, '... checked the type constraint correctly' ); done_testing; diff --git a/t/010_basics/012_rebless.t b/t/010_basics/012_rebless.t index b35cd7f..e15a5e5 100644 --- a/t/010_basics/012_rebless.t +++ b/t/010_basics/012_rebless.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Scalar::Util 'blessed'; use Moose::Util::TypeConstraints; @@ -58,15 +58,11 @@ my $bar = Parent->new; is(blessed($foo), 'Parent', 'Parent->new gives a Parent object'); is($foo->name, undef, 'No name yet'); is($foo->lazy_classname, 'Parent', "lazy attribute initialized"); -lives_ok { $foo->type_constrained(10.5) } "Num type constraint for now.."; +is( exception { $foo->type_constrained(10.5) }, undef, "Num type constraint for now.." ); # try to rebless, except it will fail due to Child's stricter type constraint -throws_ok { Child->meta->rebless_instance($foo) } -qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/, -'... this failed cause of type check'; -throws_ok { Child->meta->rebless_instance($bar) } -qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 5\.5/, -'... this failed cause of type check'; +like( exception { Child->meta->rebless_instance($foo) }, qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/, '... this failed cause of type check' ); +like( exception { Child->meta->rebless_instance($bar) }, qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 5\.5/, '... this failed cause of type check' ); $foo->type_constrained(10); $bar->type_constrained(5); @@ -80,8 +76,6 @@ is($foo->name, 'Junior', "Child->name's default came through"); is($foo->lazy_classname, 'Parent', "lazy attribute was already initialized"); is($bar->lazy_classname, 'Child', "lazy attribute just now initialized"); -throws_ok { $foo->type_constrained(10.5) } -qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/, -'... this failed cause of type check'; +like( exception { $foo->type_constrained(10.5) }, qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/, '... this failed cause of type check' ); done_testing; diff --git a/t/010_basics/013_create.t b/t/010_basics/013_create.t index 1c8003b..e3bdb3a 100644 --- a/t/010_basics/013_create.t +++ b/t/010_basics/013_create.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { package Class; @@ -24,13 +24,13 @@ use Test::Exception; my $new_class; -lives_ok { +is( exception { $new_class = Moose::Meta::Class->create( 'Class::WithFoo', superclasses => ['Class'], roles => ['Foo'], ); -} 'creating lives'; +}, undef, 'creating lives' ); ok $new_class; my $with_foo = Class::WithFoo->new; @@ -38,23 +38,23 @@ my $with_foo = Class::WithFoo->new; ok $with_foo->foo_role_applied; isa_ok $with_foo, 'Class', '$with_foo'; -throws_ok { +like( exception { Moose::Meta::Class->create( 'Made::Of::Fail', superclasses => ['Class'], roles => 'Foo', # "oops" ); -} qr/You must pass an ARRAY ref of roles/; +}, qr/You must pass an ARRAY ref of roles/ ); ok !Made::Of::Fail->isa('UNIVERSAL'), "did not create Made::Of::Fail"; -dies_ok { +isnt( exception { Moose::Meta::Class->create( 'Continuing::To::Fail', superclasses => ['Class'], roles => ['Foo', 'Conflicts::With::Foo'], ); -} 'conflicting roles == death'; +}, undef, 'conflicting roles == death' ); # XXX: Continuing::To::Fail gets created anyway diff --git a/t/010_basics/016_load_into_main.t b/t/010_basics/016_load_into_main.t index 4198721..5ed7754 100644 --- a/t/010_basics/016_load_into_main.t +++ b/t/010_basics/016_load_into_main.t @@ -4,11 +4,11 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; -lives_ok { +is( exception { eval 'use Moose'; -} "export to main"; +}, undef, "export to main" ); isa_ok( main->meta, "Moose::Meta::Class" ); diff --git a/t/010_basics/017_error_handling.t b/t/010_basics/017_error_handling.t index 542c79c..5400327 100644 --- a/t/010_basics/017_error_handling.t +++ b/t/010_basics/017_error_handling.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; # This tests the error handling in Moose::Object only @@ -13,12 +13,9 @@ use Test::Exception; use Moose; } -throws_ok { Foo->new('bad') } qr/^\QSingle parameters to new() must be a HASH ref/, - 'A single non-hashref arg to a constructor throws an error'; -throws_ok { Foo->new(undef) } qr/^\QSingle parameters to new() must be a HASH ref/, - 'A single non-hashref arg to a constructor throws an error'; +like( exception { Foo->new('bad') }, qr/^\QSingle parameters to new() must be a HASH ref/, 'A single non-hashref arg to a constructor throws an error' ); +like( exception { Foo->new(undef) }, qr/^\QSingle parameters to new() must be a HASH ref/, 'A single non-hashref arg to a constructor throws an error' ); -throws_ok { Foo->does() } qr/^\QYou must supply a role name to does()/, - 'Cannot call does() without a role name'; +like( exception { Foo->does() }, qr/^\QYou must supply a role name to does()/, 'Cannot call does() without a role name' ); done_testing; diff --git a/t/010_basics/022_buildargs_warning.t b/t/010_basics/022_buildargs_warning.t index 7c99849..978800a 100644 --- a/t/010_basics/022_buildargs_warning.t +++ b/t/010_basics/022_buildargs_warning.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::Exception; +use Test::Fatal; use Test::More; use Test::Moose qw( with_immutable ); @@ -17,7 +17,7 @@ use Test::Requires { } with_immutable { - lives_and { + is( exception { stderr_like { Baz->new( x => 42, 'y' ) } qr{\QThe new() method for Baz expects a hash reference or a key/value list. You passed an odd number of arguments at t/010_basics/022_buildargs_warning.t line \E\d+}, 'warning when passing an odd number of args to new()'; @@ -29,7 +29,7 @@ with_immutable { stderr_is { Baz->new( { x => 42 } ) } q{}, 'we handle a single hashref to new without errors'; - }; + }, undef ); } 'Baz'; diff --git a/t/010_basics/030_deprecations.t b/t/010_basics/030_deprecations.t index 7a601a7..90880c6 100644 --- a/t/010_basics/030_deprecations.t +++ b/t/010_basics/030_deprecations.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::Exception; +use Test::Fatal; use Test::More; use Test::Requires { @@ -24,7 +24,7 @@ use Test::Requires { use Moose; - ::lives_and( + ::is( ::exception ( sub { ::stderr_like{ has foo => ( traits => ['String'], @@ -60,7 +60,7 @@ use Test::Requires { 'thing2 method is created as alias in role application' ); } - ); + ), undef ); } { @@ -68,7 +68,7 @@ use Test::Requires { use Moose; - ::lives_and( + ::is( ::exception ( sub { ::stderr_is{ has foo => ( traits => ['String'], @@ -94,7 +94,7 @@ use Test::Requires { ::stderr_is{ Pack1->new->_bar } q{}, 'Providing a reader for a String trait avoids default is warning'; } - ); + ), undef ); sub _build_foo { q{} } } @@ -104,7 +104,7 @@ use Test::Requires { use Moose; - ::lives_and( + ::is( ::exception ( sub { ::stderr_is{ has foo => ( traits => ['String'], @@ -131,7 +131,7 @@ use Test::Requires { q{}, 'Providing a writer for a String trait avoids default is warning'; } - ); + ), undef ); } { @@ -139,7 +139,7 @@ use Test::Requires { use Moose; - ::lives_and( + ::is( ::exception ( sub { ::stderr_is{ has foo => ( traits => ['String'], @@ -166,7 +166,7 @@ use Test::Requires { q{}, 'Providing a accessor for a String trait avoids default is warning'; } - ); + ), undef ); sub _build_foo { q{} } } diff --git a/t/020_attributes/001_attribute_reader_generation.t b/t/020_attributes/001_attribute_reader_generation.t index f51140b..5c625e8 100644 --- a/t/020_attributes/001_attribute_reader_generation.t +++ b/t/020_attributes/001_attribute_reader_generation.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -44,17 +44,17 @@ use Test::Exception; can_ok($foo, 'get_foo'); is($foo->get_foo(), undef, '... got an undefined value'); - dies_ok { + isnt( exception { $foo->get_foo(100); - } '... get_foo is a read-only'; + }, undef, '... get_foo is a read-only' ); ok(!exists($foo->{lazy_foo}), '... no value in get_lazy_foo slot'); can_ok($foo, 'get_lazy_foo'); is($foo->get_lazy_foo(), 10, '... got an deferred value'); - dies_ok { + isnt( exception { $foo->get_lazy_foo(100); - } '... get_lazy_foo is a read-only'; + }, undef, '... get_lazy_foo is a read-only' ); } { diff --git a/t/020_attributes/002_attribute_writer_generation.t b/t/020_attributes/002_attribute_writer_generation.t index f166150..db3279d 100644 --- a/t/020_attributes/002_attribute_writer_generation.t +++ b/t/020_attributes/002_attribute_writer_generation.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Scalar::Util 'isweak'; @@ -57,33 +57,33 @@ use Scalar::Util 'isweak'; can_ok($foo, 'set_foo'); is($foo->get_foo(), undef, '... got an unset value'); - lives_ok { + is( exception { $foo->set_foo(100); - } '... set_foo wrote successfully'; + }, undef, '... set_foo wrote successfully' ); is($foo->get_foo(), 100, '... got the correct set value'); ok(!isweak($foo->{foo}), '... it is not a weak reference'); # required writer - dies_ok { + isnt( exception { Foo->new; - } '... cannot create without the required attribute'; + }, undef, '... cannot create without the required attribute' ); can_ok($foo, 'set_foo_required'); is($foo->get_foo_required(), 'required', '... got an unset value'); - lives_ok { + is( exception { $foo->set_foo_required(100); - } '... set_foo_required wrote successfully'; + }, undef, '... set_foo_required wrote successfully' ); is($foo->get_foo_required(), 100, '... got the correct set value'); - dies_ok { + isnt( exception { $foo->set_foo_required(); - } '... set_foo_required died successfully with no value'; + }, undef, '... set_foo_required died successfully with no value' ); - lives_ok { + is( exception { $foo->set_foo_required(undef); - } '... set_foo_required did accept undef'; + }, undef, '... set_foo_required did accept undef' ); ok(!isweak($foo->{foo_required}), '... it is not a weak reference'); @@ -91,14 +91,14 @@ use Scalar::Util 'isweak'; can_ok($foo, 'set_foo_int'); is($foo->get_foo_int(), undef, '... got an unset value'); - lives_ok { + is( exception { $foo->set_foo_int(100); - } '... set_foo_int wrote successfully'; + }, undef, '... set_foo_int wrote successfully' ); is($foo->get_foo_int(), 100, '... got the correct set value'); - dies_ok { + isnt( exception { $foo->set_foo_int("Foo"); - } '... set_foo_int died successfully'; + }, undef, '... set_foo_int died successfully' ); ok(!isweak($foo->{foo_int}), '... it is not a weak reference'); @@ -108,9 +108,9 @@ use Scalar::Util 'isweak'; can_ok($foo, 'set_foo_weak'); is($foo->get_foo_weak(), undef, '... got an unset value'); - lives_ok { + is( exception { $foo->set_foo_weak($test); - } '... set_foo_weak wrote successfully'; + }, undef, '... set_foo_weak wrote successfully' ); is($foo->get_foo_weak(), $test, '... got the correct set value'); ok(isweak($foo->{foo_weak}), '... it is a weak reference'); diff --git a/t/020_attributes/003_attribute_accessor_generation.t b/t/020_attributes/003_attribute_accessor_generation.t index 0603f95..a0f8742 100644 --- a/t/020_attributes/003_attribute_accessor_generation.t +++ b/t/020_attributes/003_attribute_accessor_generation.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Scalar::Util 'isweak'; @@ -90,29 +90,29 @@ use Scalar::Util 'isweak'; can_ok($foo, 'foo'); is($foo->foo(), undef, '... got an unset value'); - lives_ok { + is( exception { $foo->foo(100); - } '... foo wrote successfully'; + }, undef, '... foo wrote successfully' ); is($foo->foo(), 100, '... got the correct set value'); ok(!isweak($foo->{foo}), '... it is not a weak reference'); # required writer - dies_ok { + isnt( exception { Foo->new; - } '... cannot create without the required attribute'; + }, undef, '... cannot create without the required attribute' ); can_ok($foo, 'foo_required'); is($foo->foo_required(), 'required', '... got an unset value'); - lives_ok { + is( exception { $foo->foo_required(100); - } '... foo_required wrote successfully'; + }, undef, '... foo_required wrote successfully' ); is($foo->foo_required(), 100, '... got the correct set value'); - lives_ok { + is( exception { $foo->foo_required(undef); - } '... foo_required did not die with undef'; + }, undef, '... foo_required did not die with undef' ); is($foo->foo_required, undef, "value is undef"); @@ -129,14 +129,14 @@ use Scalar::Util 'isweak'; can_ok($foo, 'foo_int'); is($foo->foo_int(), undef, '... got an unset value'); - lives_ok { + is( exception { $foo->foo_int(100); - } '... foo_int wrote successfully'; + }, undef, '... foo_int wrote successfully' ); is($foo->foo_int(), 100, '... got the correct set value'); - dies_ok { + isnt( exception { $foo->foo_int("Foo"); - } '... foo_int died successfully'; + }, undef, '... foo_int died successfully' ); ok(!isweak($foo->{foo_int}), '... it is not a weak reference'); @@ -146,9 +146,9 @@ use Scalar::Util 'isweak'; can_ok($foo, 'foo_weak'); is($foo->foo_weak(), undef, '... got an unset value'); - lives_ok { + is( exception { $foo->foo_weak($test); - } '... foo_weak wrote successfully'; + }, undef, '... foo_weak wrote successfully' ); is($foo->foo_weak(), $test, '... got the correct set value'); ok(isweak($foo->{foo_weak}), '... it is a weak reference'); @@ -156,14 +156,14 @@ use Scalar::Util 'isweak'; can_ok( $foo, 'foo_deref'); is_deeply( [$foo->foo_deref()], [], '... default default value'); my @list; - lives_ok { + is( exception { @list = $foo->foo_deref(); - } "... doesn't deref undef value"; + }, undef, "... doesn't deref undef value" ); is_deeply( \@list, [], "returns empty list in list context"); - lives_ok { + is( exception { $foo->foo_deref( [ qw/foo bar gorch/ ] ); - } '... foo_deref wrote successfully'; + }, undef, '... foo_deref wrote successfully' ); is( Scalar::Util::reftype( scalar $foo->foo_deref() ), "ARRAY", "returns an array reference in scalar context" ); is_deeply( scalar($foo->foo_deref()), [ qw/foo bar gorch/ ], "correct array" ); @@ -175,9 +175,9 @@ use Scalar::Util 'isweak'; can_ok( $foo, 'foo_deref' ); is_deeply( [$foo->foo_deref_ro()], [], "... default default value" ); - dies_ok { + isnt( exception { $foo->foo_deref_ro( [] ); - } "... read only"; + }, undef, "... read only" ); $foo->{foo_deref_ro} = [qw/la la la/]; @@ -188,14 +188,14 @@ use Scalar::Util 'isweak'; is_deeply( { $foo->foo_deref_hash() }, {}, "... default default value" ); my %hash; - lives_ok { + is( exception { %hash = $foo->foo_deref_hash(); - } "... doesn't deref undef value"; + }, undef, "... doesn't deref undef value" ); is_deeply( \%hash, {}, "returns empty list in list context"); - lives_ok { + is( exception { $foo->foo_deref_hash( { foo => 1, bar => 2 } ); - } '... foo_deref_hash wrote successfully'; + }, undef, '... foo_deref_hash wrote successfully' ); is_deeply( scalar($foo->foo_deref_hash), { foo => 1, bar => 2 }, "scalar context" ); diff --git a/t/020_attributes/004_attribute_triggers.t b/t/020_attributes/004_attribute_triggers.t index b8ec580..7fb4b31 100644 --- a/t/020_attributes/004_attribute_triggers.t +++ b/t/020_attributes/004_attribute_triggers.t @@ -6,7 +6,7 @@ use warnings; use Scalar::Util 'isweak'; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -50,27 +50,27 @@ use Test::Exception; my $baz = Baz->new; isa_ok($baz, 'Baz'); - lives_ok { + is( exception { $foo->bar($bar); - } '... did not die setting bar'; + }, undef, '... did not die setting bar' ); is($foo->bar, $bar, '... set the value foo.bar correctly'); is($bar->foo, $foo, '... which in turn set the value bar.foo correctly'); ok(isweak($bar->{foo}), '... bar.foo is a weak reference'); - lives_ok { + is( exception { $foo->bar(undef); - } '... did not die un-setting bar'; + }, undef, '... did not die un-setting bar' ); is($foo->bar, undef, '... set the value foo.bar correctly'); is($bar->foo, $foo, '... which in turn set the value bar.foo correctly'); # test the writer - lives_ok { + is( exception { $foo->set_baz($baz); - } '... did not die setting baz'; + }, undef, '... did not die setting baz' ); is($foo->get_baz, $baz, '... set the value foo.baz correctly'); is($baz->foo, $foo, '... which in turn set the value baz.foo correctly'); @@ -105,13 +105,13 @@ use Test::Exception; package Bling; use Moose; - ::dies_ok { + ::isnt( ::exception { has('bling' => (is => 'rw', trigger => 'Fail')); - } '... a trigger must be a CODE ref'; + }, undef, '... a trigger must be a CODE ref' ); - ::dies_ok { + ::isnt( ::exception { has('bling' => (is => 'rw', trigger => [])); - } '... a trigger must be a CODE ref'; + }, undef, '... a trigger must be a CODE ref' ); } # Triggers do not fire on built values @@ -140,7 +140,7 @@ use Test::Exception; { my $blarg; - lives_ok { $blarg = Blarg->new; } 'Blarg->new() lives'; + is( exception { $blarg = Blarg->new; }, undef, 'Blarg->new() lives' ); ok($blarg, 'Have a $blarg'); foreach my $attr (qw/foo bar baz/) { is($blarg->$attr(), "default $attr value", "$attr has default value"); @@ -152,7 +152,7 @@ use Test::Exception; is_deeply(\%Blarg::trigger_calls, { map { $_ => 1 } qw/foo bar baz/ }, 'All triggers fired once on assign'); is_deeply(\%Blarg::trigger_vals, { map { $_ => "Different $_ value" } qw/foo bar baz/ }, 'All triggers given assigned values'); - lives_ok { $blarg => Blarg->new( map { $_ => "Yet another $_ value" } qw/foo bar baz/ ) } '->new() with parameters'; + is( exception { $blarg => Blarg->new( map { $_ => "Yet another $_ value" } qw/foo bar baz/ ) }, undef, '->new() with parameters' ); is_deeply(\%Blarg::trigger_calls, { map { $_ => 2 } qw/foo bar baz/ }, 'All triggers fired once on construct'); is_deeply(\%Blarg::trigger_vals, { map { $_ => "Yet another $_ value" } qw/foo bar baz/ }, 'All triggers given assigned values'); } diff --git a/t/020_attributes/005_attribute_does.t b/t/020_attributes/005_attribute_does.t index 945717b..43deb4b 100644 --- a/t/020_attributes/005_attribute_does.t +++ b/t/020_attributes/005_attribute_does.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -46,25 +46,25 @@ isa_ok($foo, 'Foo::Class'); my $bar = Bar::Class->new; isa_ok($bar, 'Bar::Class'); -lives_ok { +is( exception { $foo->bar($bar); -} '... bar passed the type constraint okay'; +}, undef, '... bar passed the type constraint okay' ); -dies_ok { +isnt( exception { $foo->bar($foo); -} '... foo did not pass the type constraint okay'; +}, undef, '... foo did not pass the type constraint okay' ); -lives_ok { +is( exception { $foo->baz($bar); -} '... baz passed the type constraint okay'; +}, undef, '... baz passed the type constraint okay' ); -dies_ok { +isnt( exception { $foo->baz($foo); -} '... foo did not pass the type constraint okay'; +}, undef, '... foo did not pass the type constraint okay' ); -lives_ok { +is( exception { $bar->foo($foo); -} '... foo passed the type constraint okay'; +}, undef, '... foo passed the type constraint okay' ); @@ -76,9 +76,9 @@ lives_ok { # if isa and does appear together, then see if Class->does(Role) # if it does not,.. we have a conflict... so we die loudly - ::dies_ok { + ::isnt( ::exception { has 'foo' => (isa => 'Foo::Class', does => 'Bar::Class'); - } '... cannot have a does() which is not done by the isa()'; + }, undef, '... cannot have a does() which is not done by the isa()' ); } { @@ -93,9 +93,9 @@ lives_ok { # if isa and does appear together, then see if Class->does(Role) # if it does not,.. we have a conflict... so we die loudly - ::dies_ok { + ::isnt( ::exception { has 'foo' => (isa => 'Bling', does => 'Bar::Class'); - } '... cannot have a isa() which is cannot does()'; + }, undef, '... cannot have a isa() which is cannot does()' ); } done_testing; diff --git a/t/020_attributes/006_attribute_required.t b/t/020_attributes/006_attribute_required.t index 5df07cc..95ba4dc 100644 --- a/t/020_attributes/006_attribute_required.t +++ b/t/020_attributes/006_attribute_required.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -52,17 +52,17 @@ use Test::Exception; # Foo->new(bar => 10, boo => undef); #} qr/^Attribute \(boo\) is required and cannot be undef/, '... must supply all the required attribute'; -lives_ok { +is( exception { Foo->new(bar => 10, baz => undef); -} '... undef is a valid attribute value'; +}, undef, '... undef is a valid attribute value' ); -lives_ok { +is( exception { Foo->new(bar => 10, boo => undef); -} '... undef is a valid attribute value'; +}, undef, '... undef is a valid attribute value' ); -throws_ok { +like( exception { Foo->new; -} qr/^Attribute \(bar\) is required/, '... must supply all the required attribute'; +}, qr/^Attribute \(bar\) is required/, '... must supply all the required attribute' ); done_testing; diff --git a/t/020_attributes/007_attribute_custom_metaclass.t b/t/020_attributes/007_attribute_custom_metaclass.t index 58c1ec1..6985c10 100644 --- a/t/020_attributes/007_attribute_custom_metaclass.t +++ b/t/020_attributes/007_attribute_custom_metaclass.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -53,9 +53,9 @@ use Test::Exception; package Bar; use Moose; - ::lives_ok { + ::is( ::exception { has 'bar' => (metaclass => 'Bar::Meta::Attribute'); - } '... the attribute metaclass need not be a Moose::Meta::Attribute as long as it behaves'; + }, undef, '... the attribute metaclass need not be a Moose::Meta::Attribute as long as it behaves' ); } { @@ -70,13 +70,13 @@ use Test::Exception; package Another::Foo; use Moose; - ::lives_ok { + ::is( ::exception { has 'foo' => (metaclass => 'Foo'); - } '... the attribute metaclass alias worked correctly'; + }, undef, '... the attribute metaclass alias worked correctly' ); - ::lives_ok { + ::is( ::exception { has 'bar' => (metaclass => 'Bar', is => 'bare'); - } '... the attribute metaclass alias worked correctly'; + }, undef, '... the attribute metaclass alias worked correctly' ); } { diff --git a/t/020_attributes/008_attribute_type_unions.t b/t/020_attributes/008_attribute_type_unions.t index f2ad610..a453bcd 100644 --- a/t/020_attributes/008_attribute_type_unions.t +++ b/t/020_attributes/008_attribute_type_unions.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -17,39 +17,39 @@ use Test::Exception; my $foo = Foo->new; isa_ok($foo, 'Foo'); -lives_ok { +is( exception { $foo->bar([]) -} '... set bar successfully with an ARRAY ref'; +}, undef, '... set bar successfully with an ARRAY ref' ); -lives_ok { +is( exception { $foo->bar({}) -} '... set bar successfully with a HASH ref'; +}, undef, '... set bar successfully with a HASH ref' ); -dies_ok { +isnt( exception { $foo->bar(100) -} '... couldnt set bar successfully with a number'; +}, undef, '... couldnt set bar successfully with a number' ); -dies_ok { +isnt( exception { $foo->bar(sub {}) -} '... couldnt set bar successfully with a CODE ref'; +}, undef, '... couldnt set bar successfully with a CODE ref' ); # check the constructor -lives_ok { +is( exception { Foo->new(bar => []) -} '... created new Foo with bar successfully set with an ARRAY ref'; +}, undef, '... created new Foo with bar successfully set with an ARRAY ref' ); -lives_ok { +is( exception { Foo->new(bar => {}) -} '... created new Foo with bar successfully set with a HASH ref'; +}, undef, '... created new Foo with bar successfully set with a HASH ref' ); -dies_ok { +isnt( exception { Foo->new(bar => 50) -} '... didnt create a new Foo with bar as a number'; +}, undef, '... didnt create a new Foo with bar as a number' ); -dies_ok { +isnt( exception { Foo->new(bar => sub {}) -} '... didnt create a new Foo with bar as a CODE ref'; +}, undef, '... didnt create a new Foo with bar as a CODE ref' ); { package Bar; @@ -61,38 +61,38 @@ dies_ok { my $bar = Bar->new; isa_ok($bar, 'Bar'); -lives_ok { +is( exception { $bar->baz('a string') -} '... set baz successfully with a string'; +}, undef, '... set baz successfully with a string' ); -lives_ok { +is( exception { $bar->baz(sub { 'a sub' }) -} '... set baz successfully with a CODE ref'; +}, undef, '... set baz successfully with a CODE ref' ); -dies_ok { +isnt( exception { $bar->baz(\(my $var1)) -} '... couldnt set baz successfully with a SCALAR ref'; +}, undef, '... couldnt set baz successfully with a SCALAR ref' ); -dies_ok { +isnt( exception { $bar->baz({}) -} '... couldnt set bar successfully with a HASH ref'; +}, undef, '... couldnt set bar successfully with a HASH ref' ); # check the constructor -lives_ok { +is( exception { Bar->new(baz => 'a string') -} '... created new Bar with baz successfully set with a string'; +}, undef, '... created new Bar with baz successfully set with a string' ); -lives_ok { +is( exception { Bar->new(baz => sub { 'a sub' }) -} '... created new Bar with baz successfully set with a CODE ref'; +}, undef, '... created new Bar with baz successfully set with a CODE ref' ); -dies_ok { +isnt( exception { Bar->new(baz => \(my $var2)) -} '... didnt create a new Bar with baz as a number'; +}, undef, '... didnt create a new Bar with baz as a number' ); -dies_ok { +isnt( exception { Bar->new(baz => {}) -} '... didnt create a new Bar with baz as a HASH ref'; +}, undef, '... didnt create a new Bar with baz as a HASH ref' ); done_testing; diff --git a/t/020_attributes/009_attribute_inherited_slot_specs.t b/t/020_attributes/009_attribute_inherited_slot_specs.t index e745ebe..ef0f3d9 100644 --- a/t/020_attributes/009_attribute_inherited_slot_specs.t +++ b/t/020_attributes/009_attribute_inherited_slot_specs.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -59,138 +59,138 @@ use Test::Exception; extends 'Foo'; - ::lives_ok { + ::is( ::exception { has '+bar' => (default => 'Bar::bar'); - } '... we can change the default attribute option'; + }, undef, '... we can change the default attribute option' ); - ::lives_ok { + ::is( ::exception { has '+baz' => (isa => 'ArrayRef'); - } '... we can add change the isa as long as it is a subtype'; + }, undef, '... we can add change the isa as long as it is a subtype' ); - ::lives_ok { + ::is( ::exception { has '+foo' => (coerce => 1); - } '... we can change/add coerce as an attribute option'; + }, undef, '... we can change/add coerce as an attribute option' ); - ::lives_ok { + ::is( ::exception { has '+gorch' => (required => 1); - } '... we can change/add required as an attribute option'; + }, undef, '... we can change/add required as an attribute option' ); - ::lives_ok { + ::is( ::exception { has '+gloum' => (lazy => 1); - } '... we can change/add lazy as an attribute option'; + }, undef, '... we can change/add lazy as an attribute option' ); - ::lives_ok { + ::is( ::exception { has '+fleem' => (lazy_build => 1); - } '... we can add lazy_build as an attribute option'; + }, undef, '... we can add lazy_build as an attribute option' ); - ::lives_ok { + ::is( ::exception { has '+bunch_of_stuff' => (isa => 'ArrayRef[Int]'); - } '... extend an attribute with parameterized type'; + }, undef, '... extend an attribute with parameterized type' ); - ::lives_ok { + ::is( ::exception { has '+one_last_one' => (isa => subtype('Ref', where { blessed $_ eq 'CODE' })); - } '... extend an attribute with anon-subtype'; + }, undef, '... extend an attribute with anon-subtype' ); - ::lives_ok { + ::is( ::exception { has '+one_last_one' => (isa => 'Value'); - } '... now can extend an attribute with a non-subtype'; + }, undef, '... now can extend an attribute with a non-subtype' ); - ::lives_ok { + ::is( ::exception { has '+fleem' => (weak_ref => 1); - } '... now allowed to add the weak_ref option via inheritance'; + }, undef, '... now allowed to add the weak_ref option via inheritance' ); - ::lives_ok { + ::is( ::exception { has '+bling' => (handles => ['hello']); - } '... we can add the handles attribute option'; + }, undef, '... we can add the handles attribute option' ); # this one will *not* work here .... - ::dies_ok { + ::isnt( ::exception { has '+blang' => (handles => ['hello']); - } '... we can not alter the handles attribute option'; - ::lives_ok { + }, undef, '... we can not alter the handles attribute option' ); + ::is( ::exception { has '+fail' => (isa => 'Ref'); - } '... can now create an attribute with an improper subtype relation'; - ::dies_ok { + }, undef, '... can now create an attribute with an improper subtype relation' ); + ::isnt( ::exception { has '+other_fail' => (trigger => sub {}); - } '... cannot create an attribute with an illegal option'; - ::throws_ok { + }, undef, '... cannot create an attribute with an illegal option' ); + ::like( ::exception { has '+does_not_exist' => (isa => 'Str'); - } qr/in Bar/, '... cannot extend a non-existing attribute'; + }, qr/in Bar/, '... cannot extend a non-existing attribute' ); } my $foo = Foo->new; isa_ok($foo, 'Foo'); is($foo->foo, undef, '... got the right undef default value'); -lives_ok { $foo->foo('FooString') } '... assigned foo correctly'; +is( exception { $foo->foo('FooString') }, undef, '... assigned foo correctly' ); is($foo->foo, 'FooString', '... got the right value for foo'); -dies_ok { $foo->foo([]) } '... foo is not coercing (as expected)'; +isnt( exception { $foo->foo([]) }, undef, '... foo is not coercing (as expected)' ); is($foo->bar, 'Foo::bar', '... got the right default value'); -dies_ok { $foo->bar(10) } '... Foo::bar is a read/only attr'; +isnt( exception { $foo->bar(10) }, undef, '... Foo::bar is a read/only attr' ); is($foo->baz, undef, '... got the right undef default value'); { my $hash_ref = {}; - lives_ok { $foo->baz($hash_ref) } '... Foo::baz accepts hash refs'; + is( exception { $foo->baz($hash_ref) }, undef, '... Foo::baz accepts hash refs' ); is($foo->baz, $hash_ref, '... got the right value assigned to baz'); my $array_ref = []; - lives_ok { $foo->baz($array_ref) } '... Foo::baz accepts an array ref'; + is( exception { $foo->baz($array_ref) }, undef, '... Foo::baz accepts an array ref' ); is($foo->baz, $array_ref, '... got the right value assigned to baz'); my $scalar_ref = \(my $var); - lives_ok { $foo->baz($scalar_ref) } '... Foo::baz accepts scalar ref'; + is( exception { $foo->baz($scalar_ref) }, undef, '... Foo::baz accepts scalar ref' ); is($foo->baz, $scalar_ref, '... got the right value assigned to baz'); - lives_ok { $foo->bunch_of_stuff([qw[one two three]]) } '... Foo::bunch_of_stuff accepts an array of strings'; + is( exception { $foo->bunch_of_stuff([qw[one two three]]) }, undef, '... Foo::bunch_of_stuff accepts an array of strings' ); - lives_ok { $foo->one_last_one(sub { 'Hello World'}) } '... Foo::one_last_one accepts a code ref'; + is( exception { $foo->one_last_one(sub { 'Hello World'}) }, undef, '... Foo::one_last_one accepts a code ref' ); my $code_ref = sub { 1 }; - lives_ok { $foo->baz($code_ref) } '... Foo::baz accepts a code ref'; + is( exception { $foo->baz($code_ref) }, undef, '... Foo::baz accepts a code ref' ); is($foo->baz, $code_ref, '... got the right value assigned to baz'); } -dies_ok { +isnt( exception { Bar->new; -} '... cannot create Bar without required gorch param'; +}, undef, '... cannot create Bar without required gorch param' ); my $bar = Bar->new(gorch => 'Bar::gorch'); isa_ok($bar, 'Bar'); isa_ok($bar, 'Foo'); is($bar->foo, undef, '... got the right undef default value'); -lives_ok { $bar->foo('FooString') } '... assigned foo correctly'; +is( exception { $bar->foo('FooString') }, undef, '... assigned foo correctly' ); is($bar->foo, 'FooString', '... got the right value for foo'); -lives_ok { $bar->foo([]) } '... assigned foo correctly'; +is( exception { $bar->foo([]) }, undef, '... assigned foo correctly' ); is($bar->foo, 'FooArrayRef', '... got the right value for foo'); is($bar->gorch, 'Bar::gorch', '... got the right default value'); is($bar->bar, 'Bar::bar', '... got the right default value'); -dies_ok { $bar->bar(10) } '... Bar::bar is a read/only attr'; +isnt( exception { $bar->bar(10) }, undef, '... Bar::bar is a read/only attr' ); is($bar->baz, undef, '... got the right undef default value'); { my $hash_ref = {}; - dies_ok { $bar->baz($hash_ref) } '... Bar::baz does not accept hash refs'; + isnt( exception { $bar->baz($hash_ref) }, undef, '... Bar::baz does not accept hash refs' ); my $array_ref = []; - lives_ok { $bar->baz($array_ref) } '... Bar::baz can accept an array ref'; + is( exception { $bar->baz($array_ref) }, undef, '... Bar::baz can accept an array ref' ); is($bar->baz, $array_ref, '... got the right value assigned to baz'); my $scalar_ref = \(my $var); - dies_ok { $bar->baz($scalar_ref) } '... Bar::baz does not accept a scalar ref'; + isnt( exception { $bar->baz($scalar_ref) }, undef, '... Bar::baz does not accept a scalar ref' ); - lives_ok { $bar->bunch_of_stuff([1, 2, 3]) } '... Bar::bunch_of_stuff accepts an array of ints'; - dies_ok { $bar->bunch_of_stuff([qw[one two three]]) } '... Bar::bunch_of_stuff does not accept an array of strings'; + is( exception { $bar->bunch_of_stuff([1, 2, 3]) }, undef, '... Bar::bunch_of_stuff accepts an array of ints' ); + isnt( exception { $bar->bunch_of_stuff([qw[one two three]]) }, undef, '... Bar::bunch_of_stuff does not accept an array of strings' ); my $code_ref = sub { 1 }; - dies_ok { $bar->baz($code_ref) } '... Bar::baz does not accept a code ref'; + isnt( exception { $bar->baz($code_ref) }, undef, '... Bar::baz does not accept a code ref' ); } # check some meta-stuff diff --git a/t/020_attributes/010_attribute_delegation.t b/t/020_attributes/010_attribute_delegation.t index bcd4cc7..18b9048 100644 --- a/t/020_attributes/010_attribute_delegation.t +++ b/t/020_attributes/010_attribute_delegation.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; # ------------------------------------------------------------------- @@ -77,9 +77,9 @@ isa_ok($foo, 'Foo'); is($foo->bar, 25, '... got the right foo->bar'); -lives_ok { +is( exception { $bar->foo($foo); -} '... assigned the new Foo to Bar->foo'; +}, undef, '... assigned the new Foo to Bar->foo' ); is($bar->foo, $foo, '... assigned bar->foo with the new Foo'); @@ -323,13 +323,13 @@ is($car->stop, 'Engine::stop', '... got the right value from ->stop'); package Goorch::Autoloaded; use Moose; - ::dies_ok { + ::isnt( ::exception { has 'foo' => ( is => 'rw', default => sub { Foo::Autoloaded->new }, handles => qr/bar/ ); - } '... you cannot delegate to AUTOLOADED class with regexp'; + }, undef, '... you cannot delegate to AUTOLOADED class with regexp' ); } # check HASH based delegation w/ AUTOLOAD @@ -368,9 +368,9 @@ is($car->stop, 'Engine::stop', '... got the right value from ->stop'); is($foo->bar, 25, '... got the right foo->bar'); - lives_ok { + is( exception { $bar->foo($foo); - } '... assigned the new Foo to Bar->foo'; + }, undef, '... assigned the new Foo to Bar->foo' ); is($bar->foo, $foo, '... assigned bar->foo with the new Foo'); @@ -414,9 +414,9 @@ is($car->stop, 'Engine::stop', '... got the right value from ->stop'); is($foo->bar, 25, '... got the right foo->bar'); - lives_ok { + is( exception { $baz->foo($foo); - } '... assigned the new Foo to Baz->foo'; + }, undef, '... assigned the new Foo to Baz->foo' ); is($baz->foo, $foo, '... assigned baz->foo with the new Foo'); @@ -445,15 +445,13 @@ is($car->stop, 'Engine::stop', '... got the right value from ->stop'); # not an object { my $i = Bar->new(foo => undef); - throws_ok { $i->foo_bar } qr/is not defined/, - 'useful error from unblessed reference'; + like( exception { $i->foo_bar }, qr/is not defined/, 'useful error from unblessed reference' ); my $j = Bar->new(foo => []); - throws_ok { $j->foo_bar } qr/is not an object \(got 'ARRAY/, - 'useful error from unblessed reference'; + like( exception { $j->foo_bar }, qr/is not an object \(got 'ARRAY/, 'useful error from unblessed reference' ); my $k = Bar->new(foo => "Foo"); - lives_ok { $k->foo_baz } "but not for class name"; + is( exception { $k->foo_baz }, undef, "but not for class name" ); } done_testing; diff --git a/t/020_attributes/011_more_attr_delegation.t b/t/020_attributes/011_more_attr_delegation.t index 18b8fc1..050ec3d 100644 --- a/t/020_attributes/011_more_attr_delegation.t +++ b/t/020_attributes/011_more_attr_delegation.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; =pod @@ -94,41 +94,41 @@ do not fail at compile time. sub parent_method_1 { "parent_1" } ::can_ok('Parent', 'parent_method_1'); - ::dies_ok { + ::isnt( ::exception { has child_a => ( is => "ro", default => sub { ChildA->new }, handles => qr/.*/, ); - } "all_methods requires explicit isa"; + }, undef, "all_methods requires explicit isa" ); - ::lives_ok { + ::is( ::exception { has child_a => ( isa => "ChildA", is => "ro", default => sub { ChildA->new }, handles => qr/.*/, ); - } "allow all_methods with explicit isa"; + }, undef, "allow all_methods with explicit isa" ); - ::lives_ok { + ::is( ::exception { has child_b => ( is => 'ro', default => sub { ChildB->new }, handles => [qw/child_b_method_1/], ); - } "don't need to declare isa if method list is predefined"; + }, undef, "don't need to declare isa if method list is predefined" ); - ::lives_ok { + ::is( ::exception { has child_c => ( isa => "ChildC", is => "ro", default => sub { ChildC->new }, handles => qr/_la$/, ); - } "can declare regex collector"; + }, undef, "can declare regex collector" ); - ::dies_ok { + ::isnt( ::exception { has child_d => ( is => "ro", default => sub { ChildD->new }, @@ -136,9 +136,9 @@ do not fail at compile time. my ( $class, $delegate_class ) = @_; } ); - } "can't create attr with generative handles parameter and no isa"; + }, undef, "can't create attr with generative handles parameter and no isa" ); - ::lives_ok { + ::is( ::exception { has child_d => ( isa => "ChildD", is => "ro", @@ -148,19 +148,19 @@ do not fail at compile time. return; } ); - } "can't create attr with generative handles parameter and no isa"; + }, undef, "can't create attr with generative handles parameter and no isa" ); - ::lives_ok { + ::is( ::exception { has child_e => ( isa => "ChildE", is => "ro", default => sub { ChildE->new }, handles => ["child_e_method_2"], ); - } "can delegate to non moose class using explicit method list"; + }, undef, "can delegate to non moose class using explicit method list" ); my $delegate_class; - ::lives_ok { + ::is( ::exception { has child_f => ( isa => "ChildF", is => "ro", @@ -170,30 +170,30 @@ do not fail at compile time. return; }, ); - } "subrefs on non moose class give no meta"; + }, undef, "subrefs on non moose class give no meta" ); ::is( $delegate_class, "ChildF", "plain classes are handed down to subs" ); - ::lives_ok { + ::is( ::exception { has child_g => ( isa => "ChildG", default => sub { ChildG->new }, handles => ["child_g_method_1"], ); - } "can delegate to object even without explicit reader"; + }, undef, "can delegate to object even without explicit reader" ); ::can_ok('Parent', 'parent_method_1'); - ::dies_ok { + ::isnt( ::exception { has child_h => ( isa => "ChildH", is => "ro", default => sub { ChildH->new }, handles => sub { map { $_, $_ } $_[1]->get_all_method_names }, ); - } "Can't override exisiting class method in delegate"; + }, undef, "Can't override exisiting class method in delegate" ); ::can_ok('Parent', 'parent_method_1'); - ::lives_ok { + ::is( ::exception { has child_i => ( isa => "ChildI", is => "ro", @@ -203,7 +203,7 @@ do not fail at compile time. $_[1]->get_all_method_names; }, ); - } "Test handles code ref for skipping predefined methods"; + }, undef, "Test handles code ref for skipping predefined methods" ); sub parent_method { "p" } diff --git a/t/020_attributes/012_misc_attribute_tests.t b/t/020_attributes/012_misc_attribute_tests.t index 7f855a3..ac532c6 100644 --- a/t/020_attributes/012_misc_attribute_tests.t +++ b/t/020_attributes/012_misc_attribute_tests.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -57,13 +57,13 @@ use Test::Exception; my $test = Test::For::Lazy::TypeConstraint->new; isa_ok($test, 'Test::For::Lazy::TypeConstraint'); - dies_ok { + isnt( exception { $test->bad_lazy_attr; - } '... this does not work'; + }, undef, '... this does not work' ); - lives_ok { + is( exception { $test->good_lazy_attr; - } '... this does not work'; + }, undef, '... this does not work' ); } { @@ -118,9 +118,9 @@ use Test::Exception; } - dies_ok { + isnt( exception { Test::UndefDefault::Attributes->new; - } '... default must return a value which passes the type constraint'; + }, undef, '... default must return a value which passes the type constraint' ); } @@ -138,10 +138,9 @@ use Test::Exception; is($moose_obj->a_str( 'foobar' ), 'foobar', 'setter took string'); ok($moose_obj, 'this is a *not* a string'); - throws_ok { + like( exception { $moose_obj->a_str( $moose_obj ) - } qr/Attribute \(a_str\) does not pass the type constraint because\: Validation failed for 'Str' with value OverloadedStr=HASH\(0x.+?\)/, - '... dies without overloading the string'; + }, qr/Attribute \(a_str\) does not pass the type constraint because\: Validation failed for 'Str' with value OverloadedStr=HASH\(0x.+?\)/, '... dies without overloading the string' ); } @@ -153,14 +152,13 @@ use Test::Exception; has 'a_num' => ( isa => 'Int' , is => 'rw', default => 7.5 ); } - throws_ok { + like( exception { OverloadBreaker->new; - } qr/Attribute \(a_num\) does not pass the type constraint because\: Validation failed for 'Int' with value 7\.5/, - '... this doesnt trip overload to break anymore '; + }, qr/Attribute \(a_num\) does not pass the type constraint because\: Validation failed for 'Int' with value 7\.5/, '... this doesnt trip overload to break anymore ' ); - lives_ok { + is( exception { OverloadBreaker->new(a_num => 5); - } '... this works fine though'; + }, undef, '... this works fine though' ); } @@ -192,9 +190,9 @@ use Test::Exception; has 'foo' => ( required => 1, builder => 'build_foo', is => 'ro'); } - dies_ok { + isnt( exception { Test::Builder::Attribute::Broken->new; - } '... no builder, wtf'; + }, undef, '... no builder, wtf' ); } @@ -244,9 +242,7 @@ use Test::Exception; ok(!$instance->_has_foo, "noo _foo value yet"); is($instance->foo, 'works', "foo builder works"); is($instance->_foo, 'works too', "foo builder works too"); - throws_ok { $instance->fool } - qr/Test::LazyBuild::Attribute does not support builder method \'_build_fool\' for attribute \'fool\'/, - "Correct error when a builder method is not present"; + like( exception { $instance->fool }, qr/Test::LazyBuild::Attribute does not support builder method \'_build_fool\' for attribute \'fool\'/, "Correct error when a builder method is not present" ); } @@ -256,8 +252,8 @@ use Test::Exception; use Moose; } -lives_ok { OutOfClassTest::has('foo', is => 'bare'); } 'create attr via direct sub call'; -lives_ok { OutOfClassTest->can('has')->('bar', is => 'bare'); } 'create attr via can'; +is( exception { OutOfClassTest::has('foo', is => 'bare'); }, undef, 'create attr via direct sub call' ); +is( exception { OutOfClassTest->can('has')->('bar', is => 'bare'); }, undef, 'create attr via can' ); ok(OutOfClassTest->meta->get_attribute('foo'), 'attr created from sub call'); ok(OutOfClassTest->meta->get_attribute('bar'), 'attr created from can'); @@ -268,8 +264,7 @@ ok(OutOfClassTest->meta->get_attribute('bar'), 'attr created from can'); package Foo; use Moose; - ::throws_ok { has 'foo' => ( 'ro', isa => 'Str' ) } - qr/^Usage/, 'has throws error with odd number of attribute options'; + ::like( ::exception { has 'foo' => ( 'ro', isa => 'Str' ) }, qr/^Usage/, 'has throws error with odd number of attribute options' ); } } diff --git a/t/020_attributes/013_attr_dereference_test.t b/t/020_attributes/013_attr_dereference_test.t index fa78897..3e852fa 100644 --- a/t/020_attributes/013_attr_dereference_test.t +++ b/t/020_attributes/013_attr_dereference_test.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -15,14 +15,14 @@ use Test::Exception; use Moose; use Moose::Util::TypeConstraints; - ::lives_ok { + ::is( ::exception { has 'customers' => ( is => 'ro', isa => subtype('ArrayRef' => where { (blessed($_) && $_->isa('Customer') || return) for @$_; 1 }), auto_deref => 1, ); - } '... successfully created attr'; + }, undef, '... successfully created attr' ); } { @@ -68,13 +68,13 @@ use Test::Exception; { my $autoderef = AutoDeref->new; - dies_ok { + isnt( exception { $autoderef->bar(1, 2, 3); - } '... its auto-de-ref-ing, not auto-en-ref-ing'; + }, undef, '... its auto-de-ref-ing, not auto-en-ref-ing' ); - lives_ok { + is( exception { $autoderef->bar([ 1, 2, 3 ]) - } '... set the results of bar correctly'; + }, undef, '... set the results of bar correctly' ); is_deeply [ $autoderef->bar ], [ 1, 2, 3 ], '... auto-dereffed correctly'; } diff --git a/t/020_attributes/014_misc_attribute_coerce_lazy.t b/t/020_attributes/014_misc_attribute_coerce_lazy.t index fe61494..57429c1 100644 --- a/t/020_attributes/014_misc_attribute_coerce_lazy.t +++ b/t/020_attributes/014_misc_attribute_coerce_lazy.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; @@ -43,8 +43,8 @@ use Test::Exception; my $r = Request->new; isa_ok($r, 'Request'); -lives_ok { +is( exception { $r->headers; -} '... this coerces and passes the type constraint even with lazy'; +}, undef, '... this coerces and passes the type constraint even with lazy' ); done_testing; diff --git a/t/020_attributes/019_attribute_lazy_initializer.t b/t/020_attributes/019_attribute_lazy_initializer.t index 3ac82d8..80e4e0b 100644 --- a/t/020_attributes/019_attribute_lazy_initializer.t +++ b/t/020_attributes/019_attribute_lazy_initializer.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -143,8 +143,8 @@ use Test::Exception; __PACKAGE__->meta->make_immutable; } -dies_ok { +isnt( exception { Fail::Bar->new(foo => 10) -} '... this fails, because initializer returns a bad type'; +}, undef, '... this fails, because initializer returns a bad type' ); done_testing; diff --git a/t/020_attributes/021_method_generation_rules.t b/t/020_attributes/021_method_generation_rules.t index 646e572..89992d4 100644 --- a/t/020_attributes/021_method_generation_rules.t +++ b/t/020_attributes/021_method_generation_rules.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; =pod @@ -33,9 +33,9 @@ ok($class, "Can define attr with rw + writer"); $obj = $class->new(); can_ok($obj, qw/foo _foo/); -lives_ok {$obj->_foo(1)} "$class->_foo is writer"; +is( exception {$obj->_foo(1)}, undef, "$class->_foo is writer" ); is($obj->foo(), 1, "$class->foo is reader"); -dies_ok {$obj->foo(2)} "$class->foo is not writer"; # this should fail +isnt( exception {$obj->foo(2)}, undef, "$class->foo is not writer" ); # this should fail ok(!defined $obj->_foo(), "$class->_foo is not reader"); $class = make_class('ro', 'writer', 'Test::Class::WriterRO'); @@ -44,9 +44,9 @@ ok($class, "Can define attr with ro + writer"); $obj = $class->new(); can_ok($obj, qw/foo _foo/); -lives_ok {$obj->_foo(1)} "$class->_foo is writer"; +is( exception {$obj->_foo(1)}, undef, "$class->_foo is writer" ); is($obj->foo(), 1, "$class->foo is reader"); -dies_ok {$obj->foo(1)} "$class->foo is not writer"; +isnt( exception {$obj->foo(1)}, undef, "$class->foo is not writer" ); isnt($obj->_foo(), 1, "$class->_foo is not reader"); $class = make_class('rw', 'accessor', 'Test::Class::AccessorRW'); @@ -55,9 +55,9 @@ ok($class, "Can define attr with rw + accessor"); $obj = $class->new(); can_ok($obj, qw/_foo/); -lives_ok {$obj->_foo(1)} "$class->_foo is writer"; +is( exception {$obj->_foo(1)}, undef, "$class->_foo is writer" ); is($obj->_foo(), 1, "$class->foo is reader"); -dies_ok { make_class('ro', 'accessor', "Test::Class::AccessorRO"); } "Cant define attr with ro + accessor"; +isnt( exception { make_class('ro', 'accessor', "Test::Class::AccessorRO"); }, undef, "Cant define attr with ro + accessor" ); done_testing; diff --git a/t/020_attributes/022_illegal_options_for_inheritance.t b/t/020_attributes/022_illegal_options_for_inheritance.t index fdf6276..9f83475 100644 --- a/t/020_attributes/022_illegal_options_for_inheritance.t +++ b/t/020_attributes/022_illegal_options_for_inheritance.t @@ -3,7 +3,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { package Foo; @@ -24,12 +24,12 @@ use Test::Exception; extends 'Foo'; - ::lives_ok { has '+foo' => (is => 'rw') } "can override is"; - ::throws_ok { has '+foo' => (reader => 'bar') } qr/illegal/, "can't override reader"; - ::lives_ok { has '+foo' => (clearer => 'baz') } "can override unspecified things"; + ::is( ::exception { has '+foo' => (is => 'rw') }, undef, "can override is" ); + ::like( ::exception { has '+foo' => (reader => 'bar') }, qr/illegal/, "can't override reader" ); + ::is( ::exception { has '+foo' => (clearer => 'baz') }, undef, "can override unspecified things" ); - ::throws_ok { has '+bar' => (clearer => 'quux') } qr/illegal/, "can't override clearer"; - ::lives_ok { has '+bar' => (predicate => 'has_bar') } "can override unspecified things"; + ::like( ::exception { has '+bar' => (clearer => 'quux') }, qr/illegal/, "can't override clearer" ); + ::is( ::exception { has '+bar' => (predicate => 'has_bar') }, undef, "can override unspecified things" ); } { @@ -47,13 +47,13 @@ use Test::Exception; package Bar; use Moose; - ::lives_ok { + ::is( ::exception { has bar => ( traits => ['Bar::Meta::Attribute'], my_illegal_option => 'FOO', is => 'bare', ); - } "can use illegal options"; + }, undef, "can use illegal options" ); has baz => ( traits => ['Bar::Meta::Attribute'], @@ -67,11 +67,8 @@ use Test::Exception; extends 'Bar'; - ::throws_ok { has '+bar' => (my_illegal_option => 'BAR') } - qr/illegal/, - "can't override illegal attribute"; - ::lives_ok { has '+baz' => (my_illegal_option => 'BAR') } - "can add illegal option if superclass doesn't set it"; + ::like( ::exception { has '+bar' => (my_illegal_option => 'BAR') }, qr/illegal/, "can't override illegal attribute" ); + ::is( ::exception { has '+baz' => (my_illegal_option => 'BAR') }, undef, "can add illegal option if superclass doesn't set it" ); } my $bar_attr = Bar->meta->get_attribute('bar'); diff --git a/t/020_attributes/023_attribute_names.t b/t/020_attributes/023_attribute_names.t index ebcfd09..2a10043 100644 --- a/t/020_attributes/023_attribute_names.t +++ b/t/020_attributes/023_attribute_names.t @@ -3,57 +3,57 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; my $exception_regex = qr/You must provide a name for the attribute/; { package My::Role; use Moose::Role; - ::throws_ok { + ::like( ::exception { has; - } $exception_regex, 'has; fails'; + }, $exception_regex, 'has; fails' ); - ::throws_ok { + ::like( ::exception { has undef; - } $exception_regex, 'has undef; fails'; + }, $exception_regex, 'has undef; fails' ); - ::lives_ok { + ::is( ::exception { has "" => ( is => 'bare', ); - } 'has ""; works now'; + }, undef, 'has ""; works now' ); - ::lives_ok { + ::is( ::exception { has 0 => ( is => 'bare', ); - } 'has 0; works now'; + }, undef, 'has 0; works now' ); } { package My::Class; use Moose; - ::throws_ok { + ::like( ::exception { has; - } $exception_regex, 'has; fails'; + }, $exception_regex, 'has; fails' ); - ::throws_ok { + ::like( ::exception { has undef; - } $exception_regex, 'has undef; fails'; + }, $exception_regex, 'has undef; fails' ); - ::lives_ok { + ::is( ::exception { has "" => ( is => 'bare', ); - } 'has ""; works now'; + }, undef, 'has ""; works now' ); - ::lives_ok { + ::is( ::exception { has 0 => ( is => 'bare', ); - } 'has 0; works now'; + }, undef, 'has 0; works now' ); } done_testing; diff --git a/t/020_attributes/028_no_slot_access.t b/t/020_attributes/028_no_slot_access.t index d9a5eca..8819db3 100644 --- a/t/020_attributes/028_no_slot_access.t +++ b/t/020_attributes/028_no_slot_access.t @@ -61,32 +61,29 @@ use warnings; use Moose::Util::MetaRole; use Test::More; - use Test::Exception; + use Test::Fatal; Moose::Util::MetaRole::apply_metaroles( for => __PACKAGE__, class_metaroles => { instance => ['MooseX::SomeAwesomeDBFields'] }, ); - lives_ok { + is( exception { has lazy_attr => ( is => 'ro', isa => 'Bool', lazy => 1, default => sub {0}, ); - } - "Adding lazy accessor does not use inline_slot_access"; + }, undef, "Adding lazy accessor does not use inline_slot_access" ); - lives_ok { + is( exception { has rw_attr => ( is => 'rw', ); - } - "Adding read-write accessor does not use inline_slot_access"; + }, undef, "Adding read-write accessor does not use inline_slot_access" ); - lives_ok { __PACKAGE__->meta->make_immutable; } - "Inling constructor does not use inline_slot_access"; + is( exception { __PACKAGE__->meta->make_immutable; }, undef, "Inling constructor does not use inline_slot_access" ); done_testing; } diff --git a/t/020_attributes/029_accessor_context.t b/t/020_attributes/029_accessor_context.t index b13a594..108f995 100644 --- a/t/020_attributes/029_accessor_context.t +++ b/t/020_attributes/029_accessor_context.t @@ -3,9 +3,9 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; -lives_ok { +is( exception { package My::Class; use Moose; @@ -44,9 +44,9 @@ lives_ok { auto_deref => 1, ); -} 'class definition'; +}, undef, 'class definition' ); -lives_ok { +is( exception { my $o = My::Class->new(); is_deeply [scalar $o->s_rw], [undef], 'uninitialized scalar attribute/rw in scalar context'; @@ -65,6 +65,6 @@ lives_ok { is_deeply [scalar $o->h_ro], [undef], 'uninitialized HashRef attribute/ro in scalar context'; is_deeply [$o->h_ro], [], 'uninitialized HashRef attribute/ro in list context'; -} 'testing'; +}, undef, 'testing' ); done_testing; diff --git a/t/030_roles/001_meta_role.t b/t/030_roles/001_meta_role.t index 2a040f3..b31ca63 100644 --- a/t/030_roles/001_meta_role.t +++ b/t/030_roles/001_meta_role.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Meta::Role; use Moose::Util::TypeConstraints (); @@ -45,9 +45,9 @@ is_deeply( ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute'); -lives_ok { +is( exception { $foo_role->add_attribute('bar' => (is => 'rw', isa => 'Foo')); -} '... added the bar attribute okay'; +}, undef, '... added the bar attribute okay' ); is_deeply( [ $foo_role->get_attribute_list() ], @@ -66,9 +66,9 @@ is( 'bar has a Foo class type' ); -lives_ok { +is( exception { $foo_role->add_attribute('baz' => (is => 'ro')); -} '... added the baz attribute okay'; +}, undef, '... added the baz attribute okay' ); is_deeply( [ sort $foo_role->get_attribute_list() ], @@ -81,9 +81,9 @@ my $baz = $foo_role->get_attribute('baz'); is_deeply( $baz->original_options, { is => 'ro' }, 'original options for baz attribute' ); -lives_ok { +is( exception { $foo_role->remove_attribute('bar'); -} '... removed the bar attribute okay'; +}, undef, '... removed the bar attribute okay' ); is_deeply( [ $foo_role->get_attribute_list() ], @@ -98,9 +98,9 @@ ok($foo_role->has_attribute('baz'), '... FooRole does still have the baz attribu ok(!$foo_role->has_before_method_modifiers('boo'), '... no boo:before modifier'); my $method = sub { "FooRole::boo:before" }; -lives_ok { +is( exception { $foo_role->add_before_method_modifier('boo' => $method); -} '... added a method modifier okay'; +}, undef, '... added a method modifier okay' ); ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier'); is(($foo_role->get_before_method_modifiers('boo'))[0], $method, '... got the right method back'); diff --git a/t/030_roles/002_role.t b/t/030_roles/002_role.t index 778cd5d..cdd4bfb 100644 --- a/t/030_roles/002_role.t +++ b/t/030_roles/002_role.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; =pod @@ -38,9 +38,9 @@ words, should 'has_method' return true for them? override 'bling' => sub { "FooRole::bling:override" }; override 'fling' => sub { "FooRole::fling:override" }; - ::dies_ok { extends() } '... extends() is not supported'; - ::dies_ok { augment() } '... augment() is not supported'; - ::dies_ok { inner() } '... inner() is not supported'; + ::isnt( ::exception { extends() }, undef, '... extends() is not supported' ); + ::isnt( ::exception { augment() }, undef, '... augment() is not supported' ); + ::isnt( ::exception { inner() }, undef, '... inner() is not supported' ); no Moose::Role; } diff --git a/t/030_roles/003_apply_role.t b/t/030_roles/003_apply_role.t index e58c0e2..05722b0 100644 --- a/t/030_roles/003_apply_role.t +++ b/t/030_roles/003_apply_role.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { package FooRole; @@ -46,12 +46,9 @@ use Test::Exception; extends 'BarClass'; - ::throws_ok { with 'FooRole' => { -version => 42 } } - qr/FooRole version 42 required--this is only version 23/, - 'applying role with unsatisfied version requirement'; + ::like( ::exception { with 'FooRole' => { -version => 42 } }, qr/FooRole version 42 required--this is only version 23/, 'applying role with unsatisfied version requirement' ); - ::lives_ok { with 'FooRole' => { -version => 13 } } - 'applying role with satisfied version requirement'; + ::is( ::exception { with 'FooRole' => { -version => 13 } }, undef, 'applying role with satisfied version requirement' ); sub blau {'FooClass::blau'} # << the role wraps this ... @@ -72,20 +69,17 @@ isa_ok( $foo_class_meta, 'Moose::Meta::Class' ); my $foobar_class_meta = FooBarClass->meta; isa_ok( $foobar_class_meta, 'Moose::Meta::Class' ); -dies_ok { +isnt( exception { $foo_class_meta->does_role(); -} -'... does_role requires a role name'; +}, undef, '... does_role requires a role name' ); -dies_ok { +isnt( exception { $foo_class_meta->add_role(); -} -'... apply_role requires a role'; +}, undef, '... apply_role requires a role' ); -dies_ok { +isnt( exception { $foo_class_meta->add_role( bless( {} => 'Fail' ) ); -} -'... apply_role requires a role'; +}, undef, '... apply_role requires a role' ); ok( $foo_class_meta->does_role('FooRole'), '... the FooClass->meta does_role FooRole' ); @@ -171,23 +165,20 @@ foreach my $foo ( $foo, $foobar ) { ok( !defined( $foo->baz ), '... $foo->baz is undefined' ); ok( !defined( $foo->bar ), '... $foo->bar is undefined' ); - dies_ok { + isnt( exception { $foo->baz(1); - } - '... baz is a read-only accessor'; + }, undef, '... baz is a read-only accessor' ); - dies_ok { + isnt( exception { $foo->bar(1); - } - '... bar is a read-write accessor with a type constraint'; + }, undef, '... bar is a read-write accessor with a type constraint' ); my $foo2 = FooClass->new(); isa_ok( $foo2, 'FooClass' ); - lives_ok { + is( exception { $foo->bar($foo2); - } - '... bar is a read-write accessor with a type constraint'; + }, undef, '... bar is a read-write accessor with a type constraint' ); is( $foo->bar, $foo2, '... got the right value for bar now' ); } diff --git a/t/030_roles/004_role_composition_errors.t b/t/030_roles/004_role_composition_errors.t index b2c58f4..e9036af 100644 --- a/t/030_roles/004_role_composition_errors.t +++ b/t/030_roles/004_role_composition_errors.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -27,8 +27,7 @@ is_deeply( package Foo::Class; use Moose; - ::dies_ok { with('Foo::Role') } - '... no foo method implemented by Foo::Class'; + ::isnt( ::exception { with('Foo::Role') }, undef, '... no foo method implemented by Foo::Class' ); } # class which does implement required method @@ -37,10 +36,8 @@ is_deeply( package Bar::Class; use Moose; - ::dies_ok { with('Foo::Class') } - '... cannot consume a class, it must be a role'; - ::lives_ok { with('Foo::Role') } - '... has a foo method implemented by Bar::Class'; + ::isnt( ::exception { with('Foo::Class') }, undef, '... cannot consume a class, it must be a role' ); + ::is( ::exception { with('Foo::Role') }, undef, '... has a foo method implemented by Bar::Class' ); sub foo {'Bar::Class::foo'} } @@ -51,8 +48,7 @@ is_deeply( package Bar::Role; use Moose::Role; - ::lives_ok { with('Foo::Role') } - '... has a foo method implemented by Bar::Role'; + ::is( ::exception { with('Foo::Role') }, undef, '... has a foo method implemented by Bar::Role' ); sub foo {'Bar::Role::foo'} } @@ -69,8 +65,7 @@ is_deeply( package Baz::Role; use Moose::Role; - ::lives_ok { with('Foo::Role') } - '... no foo method implemented by Baz::Role'; + ::is( ::exception { with('Foo::Role') }, undef, '... no foo method implemented by Baz::Role' ); } is_deeply( @@ -85,8 +80,7 @@ is_deeply( package Baz::Class; use Moose; - ::dies_ok { with('Baz::Role') } - '... no foo method implemented by Baz::Class2'; + ::isnt( ::exception { with('Baz::Role') }, undef, '... no foo method implemented by Baz::Class2' ); } # class which does implement required method @@ -95,8 +89,7 @@ is_deeply( package Baz::Class2; use Moose; - ::lives_ok { with('Baz::Role') } - '... has a foo method implemented by Baz::Class2'; + ::is( ::exception { with('Baz::Role') }, undef, '... has a foo method implemented by Baz::Class2' ); sub foo {'Baz::Class2::foo'} } @@ -115,9 +108,7 @@ is_deeply( package Quux::Class; use Moose; - ::throws_ok { with('Quux::Role') } - qr/\Q'Quux::Role' requires the methods 'meth1', 'meth2', 'meth3', and 'meth4' to be implemented by 'Quux::Class'/, - 'exception mentions all the missing required methods at once'; + ::like( ::exception { with('Quux::Role') }, qr/\Q'Quux::Role' requires the methods 'meth1', 'meth2', 'meth3', and 'meth4' to be implemented by 'Quux::Class'/, 'exception mentions all the missing required methods at once' ); } { @@ -126,9 +117,7 @@ is_deeply( sub meth1 { } - ::throws_ok { with('Quux::Role') } - qr/'Quux::Role' requires the methods 'meth2', 'meth3', and 'meth4' to be implemented by 'Quux::Class2'/, - 'exception mentions all the missing required methods at once, but not the one that exists'; + ::like( ::exception { with('Quux::Role') }, qr/'Quux::Role' requires the methods 'meth2', 'meth3', and 'meth4' to be implemented by 'Quux::Class2'/, 'exception mentions all the missing required methods at once, but not the one that exists' ); } { @@ -138,9 +127,7 @@ is_deeply( has 'meth1' => ( is => 'ro' ); has 'meth2' => ( is => 'ro' ); - ::throws_ok { with('Quux::Role') } - qr/'Quux::Role' requires the methods 'meth3' and 'meth4' to be implemented by 'Quux::Class3'/, - 'exception mentions all the missing methods at once, but not the accessors'; + ::like( ::exception { with('Quux::Role') }, qr/'Quux::Role' requires the methods 'meth3' and 'meth4' to be implemented by 'Quux::Class3'/, 'exception mentions all the missing methods at once, but not the accessors' ); } { @@ -150,9 +137,7 @@ is_deeply( sub meth1 { } has 'meth2' => ( is => 'ro' ); - ::throws_ok { with('Quux::Role') } - qr/'Quux::Role' requires the methods 'meth3' and 'meth4' to be implemented by 'Quux::Class4'/, - 'exception mentions all the require methods that are accessors at once, as well as missing methods, but not the one that exists'; + ::like( ::exception { with('Quux::Role') }, qr/'Quux::Role' requires the methods 'meth3' and 'meth4' to be implemented by 'Quux::Class4'/, 'exception mentions all the require methods that are accessors at once, as well as missing methods, but not the one that exists' ); } done_testing; diff --git a/t/030_roles/005_role_conflict_detection.t b/t/030_roles/005_role_conflict_detection.t index 063af64..de640a3 100644 --- a/t/030_roles/005_role_conflict_detection.t +++ b/t/030_roles/005_role_conflict_detection.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; =pod @@ -32,16 +32,16 @@ Mutually recursive roles. package My::Test1; use Moose; - ::lives_ok { + ::is( ::exception { with 'Role::Foo', 'Role::Bar'; - } '... our mutually recursive roles combine okay'; + }, undef, '... our mutually recursive roles combine okay' ); package My::Test2; use Moose; - ::lives_ok { + ::is( ::exception { with 'Role::Bar', 'Role::Foo'; - } '... our mutually recursive roles combine okay (no matter what order)'; + }, undef, '... our mutually recursive roles combine okay (no matter what order)' ); } my $test1 = My::Test1->new; @@ -98,32 +98,32 @@ Role method conflicts package My::Test3; use Moose; - ::throws_ok { + ::like( ::exception { with 'Role::Bling', 'Role::Bling::Bling'; - } qr/Due to a method name conflict in roles 'Role::Bling' and 'Role::Bling::Bling', the method 'bling' must be implemented or excluded by 'My::Test3'/, '... role methods conflict and method was required'; + }, qr/Due to a method name conflict in roles 'Role::Bling' and 'Role::Bling::Bling', the method 'bling' must be implemented or excluded by 'My::Test3'/, '... role methods conflict and method was required' ); package My::Test4; use Moose; - ::lives_ok { + ::is( ::exception { with 'Role::Bling'; with 'Role::Bling::Bling'; - } '... role methods didnt conflict when manually combined'; + }, undef, '... role methods didnt conflict when manually combined' ); package My::Test5; use Moose; - ::lives_ok { + ::is( ::exception { with 'Role::Bling::Bling'; with 'Role::Bling'; - } '... role methods didnt conflict when manually combined (in opposite order)'; + }, undef, '... role methods didnt conflict when manually combined (in opposite order)' ); package My::Test6; use Moose; - ::lives_ok { + ::is( ::exception { with 'Role::Bling::Bling', 'Role::Bling'; - } '... role methods didnt conflict when manually resolved'; + }, undef, '... role methods didnt conflict when manually resolved' ); sub bling { 'My::Test6::bling' } } @@ -187,35 +187,34 @@ Role attribute conflicts package My::Test7; use Moose; - ::throws_ok { + ::like( ::exception { with 'Role::Boo', 'Role::Boo::Hoo'; - } qr/We have encountered an attribute conflict.+ghost/; + }, qr/We have encountered an attribute conflict.+ghost/ ); package My::Test8; use Moose; - ::lives_ok { + ::is( ::exception { with 'Role::Boo'; with 'Role::Boo::Hoo'; - } '... role attrs didnt conflict when manually combined'; + }, undef, '... role attrs didnt conflict when manually combined' ); package My::Test9; use Moose; - ::lives_ok { + ::is( ::exception { with 'Role::Boo::Hoo'; with 'Role::Boo'; - } '... role attrs didnt conflict when manually combined'; + }, undef, '... role attrs didnt conflict when manually combined' ); package My::Test10; use Moose; has 'ghost' => (is => 'ro', default => 'My::Test10::ghost'); - ::throws_ok { + ::like( ::exception { with 'Role::Boo', 'Role::Boo::Hoo'; - } qr/We have encountered an attribute conflict/, - '... role attrs conflict and cannot be manually disambiguted'; + }, qr/We have encountered an attribute conflict/, '... role attrs conflict and cannot be manually disambiguted' ); } @@ -274,35 +273,34 @@ Role override method conflicts extends 'My::Test::Base'; - ::lives_ok { + ::is( ::exception { with 'Role::Truth'; - } '... composed the role with override okay'; + }, undef, '... composed the role with override okay' ); package My::Test12; use Moose; extends 'My::Test::Base'; - ::lives_ok { + ::is( ::exception { with 'Role::Plot'; - } '... composed the role with override okay'; + }, undef, '... composed the role with override okay' ); package My::Test13; use Moose; - ::dies_ok { + ::isnt( ::exception { with 'Role::Plot'; - } '... cannot compose it because we have no superclass'; + }, undef, '... cannot compose it because we have no superclass' ); package My::Test14; use Moose; extends 'My::Test::Base'; - ::throws_ok { + ::like( ::exception { with 'Role::Plot', 'Role::Truth'; - } qr/Two \'override\' methods of the same name encountered/, - '... cannot compose it because we have no superclass'; + }, qr/Two \'override\' methods of the same name encountered/, '... cannot compose it because we have no superclass' ); } ok(My::Test11->meta->has_method('twist'), '... the twist method has been added'); @@ -327,10 +325,9 @@ is(My::Test14->twist(), 'My::Test::Base::twist', '... got the right method retur package Role::Reality; use Moose::Role; - ::throws_ok { + ::like( ::exception { with 'Role::Plot'; - } qr/A local method of the same name as been found/, - '... could not compose roles here, it dies'; + }, qr/A local method of the same name as been found/, '... could not compose roles here, it dies' ); sub twist { 'Role::Reality::twist'; @@ -360,9 +357,9 @@ is(Role::Reality->meta->get_method('twist')->(), package Conflicts; use Moose; - ::throws_ok { + ::like( ::exception { with qw(Role1 Role2); - } qr/Due to a method name conflict in roles 'Role1' and 'Role2', the method 'foo' must be implemented or excluded by 'Conflicts'/; + }, qr/Due to a method name conflict in roles 'Role1' and 'Role2', the method 'foo' must be implemented or excluded by 'Conflicts'/ ); } =pod diff --git a/t/030_roles/006_role_exclusion.t b/t/030_roles/006_role_exclusion.t index 1d80e84..b4ab026 100644 --- a/t/030_roles/006_role_exclusion.t +++ b/t/030_roles/006_role_exclusion.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; =pod @@ -53,29 +53,27 @@ the roles into the same class package My::Test1; use Moose; - ::lives_ok { + ::is( ::exception { with 'Molecule::Organic'; - } '... adding the role (w/ excluded roles) okay'; + }, undef, '... adding the role (w/ excluded roles) okay' ); package My::Test2; use Moose; - ::throws_ok { + ::like( ::exception { with 'Molecule::Organic', 'Molecule::Inorganic'; - } qr/Conflict detected: Role Molecule::Organic excludes role 'Molecule::Inorganic'/, - '... adding the role w/ excluded role conflict dies okay'; + }, qr/Conflict detected: Role Molecule::Organic excludes role 'Molecule::Inorganic'/, '... adding the role w/ excluded role conflict dies okay' ); package My::Test3; use Moose; - ::lives_ok { + ::is( ::exception { with 'Molecule::Organic'; - } '... adding the role (w/ excluded roles) okay'; + }, undef, '... adding the role (w/ excluded roles) okay' ); - ::throws_ok { + ::like( ::exception { with 'Molecule::Inorganic'; - } qr/Conflict detected: My::Test3 excludes role 'Molecule::Inorganic'/, - '... adding the role w/ excluded role conflict dies okay'; + }, qr/Conflict detected: My::Test3 excludes role 'Molecule::Inorganic'/, '... adding the role w/ excluded role conflict dies okay' ); } ok(My::Test1->does('Molecule::Organic'), '... My::Test1 does Molecule::Organic'); @@ -108,10 +106,9 @@ the roles into the a superclass extends 'Methane'; - ::throws_ok { + ::like( ::exception { with 'Molecule::Inorganic'; - } qr/Conflict detected: My::Test4 excludes role \'Molecule::Inorganic\'/, - '... cannot add exculded role into class which extends Methane'; + }, qr/Conflict detected: My::Test4 excludes role \'Molecule::Inorganic\'/, '... cannot add exculded role into class which extends Methane' ); } ok(Methane->does('Molecule::Organic'), '... Methane does Molecule::Organic'); diff --git a/t/030_roles/007_roles_and_req_method_edge_cases.t b/t/030_roles/007_roles_and_req_method_edge_cases.t index bdbcf45..79c3e33 100644 --- a/t/030_roles/007_roles_and_req_method_edge_cases.t +++ b/t/030_roles/007_roles_and_req_method_edge_cases.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; =pod @@ -35,9 +35,9 @@ not remove the requirement) use warnings; use Moose::Role; - ::lives_ok { + ::is( ::exception { with 'Role::RequireFoo'; - } '... the required "foo" method will not exist yet (but we will live)'; + }, undef, '... the required "foo" method will not exist yet (but we will live)' ); override 'foo' => sub { 'Role::ProvideFoo::foo' }; } @@ -67,9 +67,9 @@ second class citizens. extends 'Class::ProvideFoo::Base'; - ::lives_ok { + ::is( ::exception { with 'Role::RequireFoo'; - } '... the required "foo" method will be found in the superclass'; + }, undef, '... the required "foo" method will be found in the superclass' ); override 'foo' => sub { 'Class::ProvideFoo::foo' }; @@ -80,9 +80,9 @@ second class citizens. override 'foo' => sub { 'Class::ProvideFoo::foo' }; - ::lives_ok { + ::is( ::exception { with 'Role::RequireFoo'; - } '... the required "foo" method exists, although it is overriden locally'; + }, undef, '... the required "foo" method exists, although it is overriden locally' ); } @@ -99,9 +99,9 @@ method modifier. extends 'Class::ProvideFoo::Base'; - ::lives_ok { + ::is( ::exception { with 'Role::RequireFoo'; - } '... the required "foo" method will be found in the superclass'; + }, undef, '... the required "foo" method will be found in the superclass' ); before 'foo' => sub { 'Class::ProvideFoo::foo:before' }; @@ -112,9 +112,9 @@ method modifier. before 'foo' => sub { 'Class::ProvideFoo::foo:before' }; - ::lives_ok { + ::is( ::exception { with 'Role::RequireFoo'; - } '... the required "foo" method exists, although it is a before modifier locally'; + }, undef, '... the required "foo" method exists, although it is a before modifier locally' ); package Class::ProvideFoo::Before3; use Moose; @@ -124,9 +124,9 @@ method modifier. sub foo { 'Class::ProvideFoo::foo' } before 'foo' => sub { 'Class::ProvideFoo::foo:before' }; - ::lives_ok { + ::is( ::exception { with 'Role::RequireFoo'; - } '... the required "foo" method exists locally, and it is modified locally'; + }, undef, '... the required "foo" method exists locally, and it is modified locally' ); package Class::ProvideFoo::Before4; use Moose; @@ -140,9 +140,9 @@ method modifier. ::is(__PACKAGE__->meta->get_method('foo')->get_original_method->package_name, __PACKAGE__, '... but the original method is from our package'); - ::lives_ok { + ::is( ::exception { with 'Role::RequireFoo'; - } '... the required "foo" method exists in the symbol table (and we will live)'; + }, undef, '... the required "foo" method exists in the symbol table (and we will live)' ); } @@ -160,9 +160,9 @@ method modifier. extends 'Class::ProvideFoo::Base'; - ::lives_ok { + ::is( ::exception { with 'Role::RequireFoo'; - } '... the required "foo" method will be found in the superclass (but then overriden)'; + }, undef, '... the required "foo" method will be found in the superclass (but then overriden)' ); has 'foo' => (is => 'ro'); @@ -173,9 +173,9 @@ method modifier. has 'foo' => (is => 'ro'); - ::lives_ok { + ::is( ::exception { with 'Role::RequireFoo'; - } '... the required "foo" method exists, and is an accessor'; + }, undef, '... the required "foo" method exists, and is an accessor' ); } # ... @@ -211,9 +211,9 @@ method modifier. use Moose; extends 'Foo::Class::Base'; - ::lives_ok { + ::is( ::exception { with 'Foo::Role'; - } '... our role combined successfully'; + }, undef, '... our role combined successfully' ); } # a method required in a role and implemented in a superclass, with a method @@ -243,9 +243,9 @@ method modifier. package Bar::Class::Grandchild; use Moose; extends 'Bar::Class::Child'; - ::lives_ok { + ::is( ::exception { with 'Bar::Role'; - } 'required method exists in superclass as non-modifier, so we live'; + }, undef, 'required method exists in superclass as non-modifier, so we live' ); } { @@ -271,9 +271,9 @@ method modifier. package Bar2::Class::Grandchild; use Moose; extends 'Bar2::Class::Child'; - ::lives_ok { + ::is( ::exception { with 'Bar2::Role'; - } 'required method exists in superclass as non-modifier, so we live'; + }, undef, 'required method exists in superclass as non-modifier, so we live' ); } done_testing; diff --git a/t/030_roles/008_role_conflict_edge_cases.t b/t/030_roles/008_role_conflict_edge_cases.t index aff9bd9..4a6cee7 100644 --- a/t/030_roles/008_role_conflict_edge_cases.t +++ b/t/030_roles/008_role_conflict_edge_cases.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; =pod @@ -33,9 +33,9 @@ a conflict) package My::Test::Class1; use Moose; - ::lives_ok { + ::is( ::exception { with 'Role::Derived1', 'Role::Derived2'; - } '... roles composed okay (no conflicts)'; + }, undef, '... roles composed okay (no conflicts)' ); } ok(Role::Base->meta->has_method('foo'), '... have the method foo as expected'); @@ -79,9 +79,9 @@ a method conflict with method modifiers extends 'My::Test::Class2::Base'; - ::lives_ok { + ::is( ::exception { with 'Role::Derived3', 'Role::Derived4'; - } '... roles composed okay (no conflicts)'; + }, undef, '... roles composed okay (no conflicts)' ); } ok(Role::Base2->meta->has_override_method_modifier('foo'), '... have the method foo as expected'); @@ -132,9 +132,9 @@ same for before/afters as well extends 'My::Test::Class3::Base'; - ::lives_ok { + ::is( ::exception { with 'Role::Derived5', 'Role::Derived6'; - } '... roles composed okay (no conflicts)'; + }, undef, '... roles composed okay (no conflicts)' ); } ok(Role::Base3->meta->has_around_method_modifiers('foo'), '... have the method foo as expected'); @@ -175,9 +175,9 @@ a conflict) package My::Test::Class4; use Moose; - ::lives_ok { + ::is( ::exception { with 'Role::Derived7', 'Role::Derived8'; - } '... roles composed okay (no conflicts)'; + }, undef, '... roles composed okay (no conflicts)' ); } ok(Role::Base4->meta->has_attribute('foo'), '... have the attribute foo as expected'); diff --git a/t/030_roles/009_more_role_edge_cases.t b/t/030_roles/009_more_role_edge_cases.t index 4a4fde0..dc53dc6 100644 --- a/t/030_roles/009_more_role_edge_cases.t +++ b/t/030_roles/009_more_role_edge_cases.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -30,9 +30,9 @@ use Test::Exception; package SubAB; use Moose; - ::lives_ok { + ::is( ::exception { with "SubAA", "RootA"; - } '... role was composed as expected'; + }, undef, '... role was composed as expected' ); } ok( SubAB->does("SubAA"), "does SubAA"); @@ -45,9 +45,9 @@ use Test::Exception; can_ok( $i, "foo" ); my $foo_rv; - lives_ok { + is( exception { $foo_rv = $i->foo; - } '... called foo successfully'; + }, undef, '... called foo successfully' ); is($foo_rv, "RootA::foo", "... got the right foo rv"); } @@ -94,9 +94,9 @@ use Test::Exception; package SubBB; use Moose; - ::lives_ok { + ::is( ::exception { with "SubBA"; - } '... composed the role successfully'; + }, undef, '... composed the role successfully' ); } ok( SubBB->does("SubBA"), "BB does SubBA" ); @@ -107,13 +107,13 @@ use Test::Exception; can_ok( $i, "foo" ); my $foo_rv; - lives_ok { + is( exception { $foo_rv = $i->foo - } '... called foo successfully'; + }, undef, '... called foo successfully' ); is( $foo_rv, "RootB::foo", "foo rv" ); is( $i->counter, 1, "after hook called" ); - lives_ok { $i->foo } '... called foo successfully (again)'; + is( exception { $i->foo }, undef, '... called foo successfully (again)' ); is( $i->counter, 2, "after hook called (again)" ); ok(SubBA->meta->has_method('foo'), '... this has the foo method'); @@ -143,9 +143,9 @@ use Test::Exception; with "RootC"; - ::dies_ok { + ::isnt( ::exception { override foo => sub { "overridden" }; - } '... cannot compose an override over a local method'; + }, undef, '... cannot compose an override over a local method' ); } } diff --git a/t/030_roles/011_overriding.t b/t/030_roles/011_overriding.t index 300a39f..6f7d11b 100644 --- a/t/030_roles/011_overriding.t +++ b/t/030_roles/011_overriding.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -22,9 +22,9 @@ use Test::Exception; package Role::C; use Moose::Role; - ::lives_ok { + ::is( ::exception { with qw(Role::A Role::B); # no conflict here - } "define role C"; + }, undef, "define role C" ); sub foo { 'Role::C::foo' } sub zot { 'Role::C::zot' } @@ -32,9 +32,9 @@ use Test::Exception; package Class::A; use Moose; - ::lives_ok { + ::is( ::exception { with qw(Role::C); - } "define class A"; + }, undef, "define class A" ); sub zot { 'Class::A::zot' } } @@ -61,16 +61,16 @@ is( Class::A->new->xxy, "Role::B::xxy", "... got the right xxy method" ); package Class::A::Conflict; use Moose; - ::throws_ok { + ::like( ::exception { with 'Role::A::Conflict'; - } qr/Due to a method name conflict in roles 'Role::A' and 'Role::A::Conflict', the method 'bar' must be implemented or excluded by 'Class::A::Conflict'/, '... did not fufill the requirement of &bar method'; + }, qr/Due to a method name conflict in roles 'Role::A' and 'Role::A::Conflict', the method 'bar' must be implemented or excluded by 'Class::A::Conflict'/, '... did not fufill the requirement of &bar method' ); package Class::A::Resolved; use Moose; - ::lives_ok { + ::is( ::exception { with 'Role::A::Conflict'; - } '... did fufill the requirement of &bar method'; + }, undef, '... did fufill the requirement of &bar method' ); sub bar { 'Class::A::Resolved::bar' } } @@ -100,9 +100,9 @@ is( Class::A::Resolved->new->bar, 'Class::A::Resolved::bar', "... got the right package Role::F; use Moose::Role; - ::lives_ok { + ::is( ::exception { with qw(Role::D Role::E); # conflict between 'foo's here - } "define role Role::F"; + }, undef, "define role Role::F" ); sub foo { 'Role::F::foo' } sub zot { 'Role::F::zot' } @@ -110,9 +110,9 @@ is( Class::A::Resolved->new->bar, 'Class::A::Resolved::bar', "... got the right package Class::B; use Moose; - ::lives_ok { + ::is( ::exception { with qw(Role::F); - } "define class Class::B"; + }, undef, "define class Class::B" ); sub zot { 'Class::B::zot' } } @@ -134,9 +134,9 @@ ok(!Role::F->meta->requires_method('foo'), '... Role::F fufilled the &foo requir package Role::D::And::E::Conflict; use Moose::Role; - ::lives_ok { + ::is( ::exception { with qw(Role::D Role::E); # conflict between 'foo's here - } "... define role Role::D::And::E::Conflict"; + }, undef, "... define role Role::D::And::E::Conflict" ); sub foo { 'Role::D::And::E::Conflict::foo' } # this overrides ... @@ -168,9 +168,9 @@ ok(Role::D::And::E::Conflict->meta->requires_method('bar'), '... Role::D::And::E package Role::I; use Moose::Role; - ::lives_ok { + ::is( ::exception { with qw(Role::J Role::H); # conflict between 'foo's here - } "define role Role::I"; + }, undef, "define role Role::I" ); sub zot { 'Role::I::zot' } sub zzy { 'Role::I::zzy' } @@ -178,18 +178,18 @@ ok(Role::D::And::E::Conflict->meta->requires_method('bar'), '... Role::D::And::E package Class::C; use Moose; - ::throws_ok { + ::like( ::exception { with qw(Role::I); - } qr/Due to a method name conflict in roles 'Role::H' and 'Role::J', the method 'foo' must be implemented or excluded by 'Class::C'/, "defining class Class::C fails"; + }, qr/Due to a method name conflict in roles 'Role::H' and 'Role::J', the method 'foo' must be implemented or excluded by 'Class::C'/, "defining class Class::C fails" ); sub zot { 'Class::C::zot' } package Class::E; use Moose; - ::lives_ok { + ::is( ::exception { with qw(Role::I); - } "resolved with method"; + }, undef, "resolved with method" ); sub foo { 'Class::E::foo' } sub zot { 'Class::E::zot' } @@ -205,7 +205,7 @@ is( Class::E->new->xxy, "Role::J::xxy", "... got the right &xxy method" ); ok(Role::I->meta->requires_method('foo'), '... Role::I still have the &foo requirement'); { - lives_ok { + is( exception { package Class::D; use Moose; @@ -215,7 +215,7 @@ ok(Role::I->meta->requires_method('foo'), '... Role::I still have the &foo requi with qw(Role::I); - } "resolved with attr"; + }, undef, "resolved with attr" ); can_ok( Class::D->new, qw(foo bar xxy zot) ); is( eval { Class::D->new->bar }, "Role::H::bar", "bar" ); diff --git a/t/030_roles/012_method_exclusion_in_composition.t b/t/030_roles/012_method_exclusion_in_composition.t index fa74523..64c3605 100644 --- a/t/030_roles/012_method_exclusion_in_composition.t +++ b/t/030_roles/012_method_exclusion_in_composition.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -58,21 +58,20 @@ ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is requ package My::Foo::Class; use Moose; - ::lives_ok { + ::is( ::exception { with 'Foo::Role' => { -excludes => 'foo' }, 'Bar::Role' => { -excludes => 'foo' }, 'Baz::Role'; - } '... composed our roles correctly'; + }, undef, '... composed our roles correctly' ); package My::Foo::Class::Broken; use Moose; - ::throws_ok { + ::like( ::exception { with 'Foo::Role', 'Bar::Role' => { -excludes => 'foo' }, 'Baz::Role'; - } qr/Due to a method name conflict in roles 'Baz::Role' and 'Foo::Role', the method 'foo' must be implemented or excluded by 'My::Foo::Class::Broken'/, - '... composed our roles correctly'; + }, qr/Due to a method name conflict in roles 'Baz::Role' and 'Foo::Role', the method 'foo' must be implemented or excluded by 'My::Foo::Class::Broken'/, '... composed our roles correctly' ); } { @@ -86,11 +85,11 @@ ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is requ package My::Foo::Role; use Moose::Role; - ::lives_ok { + ::is( ::exception { with 'Foo::Role' => { -excludes => 'foo' }, 'Bar::Role' => { -excludes => 'foo' }, 'Baz::Role'; - } '... composed our roles correctly'; + }, undef, '... composed our roles correctly' ); } ok(My::Foo::Role->meta->has_method('foo'), "we have a foo method"); @@ -100,11 +99,11 @@ ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not package My::Foo::Role::Other; use Moose::Role; - ::lives_ok { + ::is( ::exception { with 'Foo::Role', 'Bar::Role' => { -excludes => 'foo' }, 'Baz::Role'; - } '... composed our roles correctly'; + }, undef, '... composed our roles correctly' ); } ok(!My::Foo::Role::Other->meta->has_method('foo'), "we dont have a foo method"); diff --git a/t/030_roles/013_method_aliasing_in_composition.t b/t/030_roles/013_method_aliasing_in_composition.t index cbe8bf1..c6146a7 100644 --- a/t/030_roles/013_method_aliasing_in_composition.t +++ b/t/030_roles/013_method_aliasing_in_composition.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -20,16 +20,16 @@ use Test::Exception; package My::Class; use Moose; - ::lives_ok { + ::is( ::exception { with 'My::Role' => { -alias => { bar => 'role_bar' } }; - } '... this succeeds'; + }, undef, '... this succeeds' ); package My::Class::Failure; use Moose; - ::throws_ok { + ::like( ::exception { with 'My::Role' => { -alias => { bar => 'role_bar' } }; - } qr/Cannot create a method alias if a local method of the same name exists/, '... this succeeds'; + }, qr/Cannot create a method alias if a local method of the same name exists/, '... this succeeds' ); sub role_bar { 'FAIL' } } @@ -40,18 +40,18 @@ ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz bar ro package My::OtherRole; use Moose::Role; - ::lives_ok { + ::is( ::exception { with 'My::Role' => { -alias => { bar => 'role_bar' } }; - } '... this succeeds'; + }, undef, '... this succeeds' ); sub bar { 'My::OtherRole::bar' } package My::OtherRole::Failure; use Moose::Role; - ::throws_ok { + ::like( ::exception { with 'My::Role' => { -alias => { bar => 'role_bar' } }; - } qr/Cannot create a method alias if a local method of the same name exists/, '... cannot alias to a name that exists'; + }, qr/Cannot create a method alias if a local method of the same name exists/, '... cannot alias to a name that exists' ); sub role_bar { 'FAIL' } } @@ -64,9 +64,9 @@ ok(!My::OtherRole->meta->requires_method('role_bar'), '... and the &role_bar met package My::AliasingRole; use Moose::Role; - ::lives_ok { + ::is( ::exception { with 'My::Role' => { -alias => { bar => 'role_bar' } }; - } '... this succeeds'; + }, undef, '... this succeeds' ); } ok(My::AliasingRole->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar); @@ -91,21 +91,20 @@ ok(!My::AliasingRole->meta->requires_method('bar'), '... and the &bar method is package My::Foo::Class; use Moose; - ::lives_ok { + ::is( ::exception { with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' }, 'Bar::Role' => { -alias => { 'foo' => 'bar_foo' }, -excludes => 'foo' }, 'Baz::Role'; - } '... composed our roles correctly'; + }, undef, '... composed our roles correctly' ); package My::Foo::Class::Broken; use Moose; - ::throws_ok { + ::like( ::exception { with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' }, 'Bar::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' }, 'Baz::Role'; - } qr/Due to a method name conflict in roles 'Bar::Role' and 'Foo::Role', the method 'foo_foo' must be implemented or excluded by 'My::Foo::Class::Broken'/, - '... composed our roles correctly'; + }, qr/Due to a method name conflict in roles 'Bar::Role' and 'Foo::Role', the method 'foo_foo' must be implemented or excluded by 'My::Foo::Class::Broken'/, '... composed our roles correctly' ); } { @@ -121,11 +120,11 @@ ok(!My::AliasingRole->meta->requires_method('bar'), '... and the &bar method is package My::Foo::Role; use Moose::Role; - ::lives_ok { + ::is( ::exception { with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' }, 'Bar::Role' => { -alias => { 'foo' => 'bar_foo' }, -excludes => 'foo' }, 'Baz::Role'; - } '... composed our roles correctly'; + }, undef, '... composed our roles correctly' ); } ok(My::Foo::Role->meta->has_method($_), "we have a $_ method") for qw/foo foo_foo bar_foo/;; @@ -136,11 +135,11 @@ ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not package My::Foo::Role::Other; use Moose::Role; - ::lives_ok { + ::is( ::exception { with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' }, 'Bar::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' }, 'Baz::Role'; - } '... composed our roles correctly'; + }, undef, '... composed our roles correctly' ); } ok(!My::Foo::Role::Other->meta->has_method('foo_foo'), "we dont have a foo_foo method"); @@ -150,9 +149,9 @@ ok(My::Foo::Role::Other->meta->requires_method('foo_foo'), '... and the &foo met package My::Foo::AliasOnly; use Moose; - ::lives_ok { + ::is( ::exception { with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' } }, - } '... composed our roles correctly'; + }, undef, '... composed our roles correctly' ); } ok(My::Foo::AliasOnly->meta->has_method('foo'), 'we have a foo method'); @@ -170,13 +169,12 @@ ok(My::Foo::AliasOnly->meta->has_method('foo_foo'), '.. and the aliased foo_foo package Role::Bar; use Moose::Role; - ::lives_ok { + ::is( ::exception { with 'Role::Foo' => { -alias => { x1 => 'foo_x1' }, -excludes => ['y1'], }; - } - 'Compose Role::Foo into Role::Bar with alias and exclude'; + }, undef, 'Compose Role::Foo into Role::Bar with alias and exclude' ); sub x1 {} sub y1 {} @@ -192,13 +190,12 @@ ok(My::Foo::AliasOnly->meta->has_method('foo_foo'), '.. and the aliased foo_foo package Role::Baz; use Moose::Role; - ::lives_ok { + ::is( ::exception { with 'Role::Foo' => { -alias => { x1 => 'foo_x1' }, -excludes => ['y1'], }; - } - 'Compose Role::Foo into Role::Baz with alias and exclude'; + }, undef, 'Compose Role::Foo into Role::Baz with alias and exclude' ); } { diff --git a/t/030_roles/014_more_alias_and_exclude.t b/t/030_roles/014_more_alias_and_exclude.t index 1bba604..62d3098 100644 --- a/t/030_roles/014_more_alias_and_exclude.t +++ b/t/030_roles/014_more_alias_and_exclude.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -45,12 +45,12 @@ use Test::Exception; package My::Class; use Moose; - ::lives_ok { + ::is( ::exception { with 'Foo' => { -excludes => [qw/bar baz gorch/], -alias => { gorch => 'foo_gorch' } }, 'Bar' => { -excludes => [qw/foo baz gorch/] }, 'Baz' => { -excludes => [qw/foo bar gorch/], -alias => { foo => 'baz_foo', bar => 'baz_bar' } }, 'Gorch' => { -excludes => [qw/foo bar baz/] }; - } '... everything works out all right'; + }, undef, '... everything works out all right' ); } my $c = My::Class->new; diff --git a/t/030_roles/015_runtime_roles_and_attrs.t b/t/030_roles/015_runtime_roles_and_attrs.t index 865e252..8bcc868 100644 --- a/t/030_roles/015_runtime_roles_and_attrs.t +++ b/t/030_roles/015_runtime_roles_and_attrs.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Scalar::Util 'blessed'; @@ -36,9 +36,9 @@ ok(!$obj->can( 'talk' ), "... the role is not composed yet"); ok(!$obj->can( 'fur' ), 'ditto'); ok(!$obj->does('Dog'), '... we do not do any roles yet'); -dies_ok { +isnt( exception { $obj->dog($obj) -} '... and setting the accessor fails (not a Dog yet)'; +}, undef, '... and setting the accessor fails (not a Dog yet)' ); Dog->meta->apply($obj); @@ -48,9 +48,9 @@ ok($obj->can('fur'), "it has fur"); is($obj->talk, 'woof', '... got the right return value for the newly composed method'); -lives_ok { +is( exception { $obj->dog($obj) -} '... and setting the accessor is okay'; +}, undef, '... and setting the accessor is okay' ); is($obj->fur, "dirty", "role attr initialized"); diff --git a/t/030_roles/016_runtime_roles_and_nonmoose.t b/t/030_roles/016_runtime_roles_and_nonmoose.t index ec4e657..2317688 100644 --- a/t/030_roles/016_runtime_roles_and_nonmoose.t +++ b/t/030_roles/016_runtime_roles_and_nonmoose.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Scalar::Util 'blessed'; @@ -39,9 +39,9 @@ isa_ok($foo, 'Foo'); ok(!$bar->can( 'talk' ), "... the role is not composed yet"); -dies_ok { +isnt( exception { $foo->dog($bar) -} '... and setting the accessor fails (not a Dog yet)'; +}, undef, '... and setting the accessor fails (not a Dog yet)' ); Dog->meta->apply($bar); @@ -49,8 +49,8 @@ ok($bar->can('talk'), "... the role is now composed at the object level"); is($bar->talk, 'woof', '... got the right return value for the newly composed method'); -lives_ok { +is( exception { $foo->dog($bar) -} '... and setting the accessor is okay'; +}, undef, '... and setting the accessor is okay' ); done_testing; diff --git a/t/030_roles/017_extending_role_attrs.t b/t/030_roles/017_extending_role_attrs.t index 16bc2e7..d9b223b 100644 --- a/t/030_roles/017_extending_role_attrs.t +++ b/t/030_roles/017_extending_role_attrs.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; =pod @@ -29,9 +29,9 @@ on role attributes works right. with 'Foo::Role'; - ::lives_ok { + ::is( ::exception { has '+bar' => (default => sub { 100 }); - } '... extended the attribute successfully'; + }, undef, '... extended the attribute successfully' ); } my $foo = Foo->new; @@ -54,11 +54,11 @@ is($foo->bar, 100, '... got the extended attribute'); with 'Bar::Role'; - ::lives_ok { + ::is( ::exception { has '+foo' => ( isa => 'Int', ) - } "... narrowed the role's type constraint successfully"; + }, undef, "... narrowed the role's type constraint successfully" ); } my $bar = Bar->new(foo => 42); @@ -67,7 +67,7 @@ is($bar->foo, 42, '... got the extended attribute'); $bar->foo(100); is($bar->foo, 100, "... can change the attribute's value to an Int"); -throws_ok { $bar->foo("baz") } qr/^Attribute \(foo\) does not pass the type constraint because: Validation failed for 'Int' with value baz at /; +like( exception { $bar->foo("baz") }, qr/^Attribute \(foo\) does not pass the type constraint because: Validation failed for 'Int' with value baz at / ); is($bar->foo, 100, "... still has the old Int value"); @@ -85,11 +85,11 @@ is($bar->foo, 100, "... still has the old Int value"); with 'Baz::Role'; - ::lives_ok { + ::is( ::exception { has '+baz' => ( isa => 'Int | ClassName', ) - } "... narrowed the role's type constraint successfully"; + }, undef, "... narrowed the role's type constraint successfully" ); } my $baz = Baz->new(baz => 99); @@ -98,7 +98,7 @@ is($baz->baz, 99, '... got the extended attribute'); $baz->baz('Foo'); is($baz->baz, 'Foo', "... can change the attribute's value to a ClassName"); -throws_ok { $baz->baz("zonk") } qr/^Attribute \(baz\) does not pass the type constraint because: Validation failed for 'ClassName\|Int' with value zonk at /; +like( exception { $baz->baz("zonk") }, qr/^Attribute \(baz\) does not pass the type constraint because: Validation failed for 'ClassName\|Int' with value zonk at / ); is_deeply($baz->baz, 'Foo', "... still has the old ClassName value"); @@ -121,11 +121,11 @@ is_deeply($baz->baz, 'Foo', "... still has the old ClassName value"); => as 'Int' => where { $_ > 0 }; - ::lives_ok { + ::is( ::exception { has '+quux' => ( isa => 'Positive | ArrayRef', ) - } "... narrowed the role's type constraint successfully"; + }, undef, "... narrowed the role's type constraint successfully" ); } my $quux = Quux->new(quux => 99); @@ -136,10 +136,10 @@ is($quux->quux, 100, "... can change the attribute's value to an Int"); $quux->quux(["hi"]); is_deeply($quux->quux, ["hi"], "... can change the attribute's value to an ArrayRef"); -throws_ok { $quux->quux("quux") } qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef\|Positive' with value quux at /; +like( exception { $quux->quux("quux") }, qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef\|Positive' with value quux at / ); is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value"); -throws_ok { $quux->quux({a => 1}) } qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef\|Positive' with value HASH\(\w+\) at /; +like( exception { $quux->quux({a => 1}) }, qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef\|Positive' with value HASH\(\w+\) at / ); is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value"); @@ -159,17 +159,17 @@ is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value"); with 'Err::Role'; - ::lives_ok { + ::is( ::exception { has '+err1' => (isa => 'Defined'); - } "can get less specific in the subclass"; + }, undef, "can get less specific in the subclass" ); - ::lives_ok { + ::is( ::exception { has '+err2' => (isa => 'Bool'); - } "or change the type completely"; + }, undef, "or change the type completely" ); - ::lives_ok { + ::is( ::exception { has '+err3' => (isa => 'Str | ArrayRef'); - } "or add new types to the union"; + }, undef, "or add new types to the union" ); } { @@ -178,10 +178,9 @@ is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value"); with 'Foo::Role'; - ::throws_ok { + ::like( ::exception { has '+bar' => ( is => 'ro' ); - } qr/has '\+attr' is not supported in roles/, - "Test has '+attr' in roles explodes"; + }, qr/has '\+attr' is not supported in roles/, "Test has '+attr' in roles explodes" ); } done_testing; diff --git a/t/030_roles/018_runtime_roles_w_params.t b/t/030_roles/018_runtime_roles_w_params.t index 0ca57ed..8697ef0 100644 --- a/t/030_roles/018_runtime_roles_w_params.t +++ b/t/030_roles/018_runtime_roles_w_params.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -26,9 +26,9 @@ use Test::Exception; is($foo->bar, 'BAR', '... got the expect value'); ok(!$foo->can('baz'), '... no baz method though'); - lives_ok { + is( exception { Bar->meta->apply($foo) - } '... this works'; + }, undef, '... this works' ); is($foo->bar, 'BAR', '... got the expect value'); ok($foo->can('baz'), '... we have baz method now'); @@ -43,9 +43,9 @@ use Test::Exception; is($foo->bar, 'BAR', '... got the expect value'); ok(!$foo->can('baz'), '... no baz method though'); - lives_ok { + is( exception { Bar->meta->apply($foo, (rebless_params => { baz => 'FOO-BAZ' })) - } '... this works'; + }, undef, '... this works' ); is($foo->bar, 'BAR', '... got the expect value'); ok($foo->can('baz'), '... we have baz method now'); @@ -60,9 +60,9 @@ use Test::Exception; is($foo->bar, 'BAR', '... got the expect value'); ok(!$foo->can('baz'), '... no baz method though'); - lives_ok { + is( exception { Bar->meta->apply($foo, (rebless_params => { bar => 'FOO-BAR', baz => 'FOO-BAZ' })) - } '... this works'; + }, undef, '... this works' ); is($foo->bar, 'FOO-BAR', '... got the expect value'); ok($foo->can('baz'), '... we have baz method now'); diff --git a/t/030_roles/020_role_composite.t b/t/030_roles/020_role_composite.t index 1362868..2ce6a4b 100644 --- a/t/030_roles/020_role_composite.t +++ b/t/030_roles/020_role_composite.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Meta::Role::Application::RoleSummation; use Moose::Meta::Role::Composite; @@ -48,9 +48,9 @@ use Moose::Meta::Role::Composite; Role::Baz ); - lives_ok { + is( exception { Moose::Meta::Role::Application::RoleSummation->new->apply($c); - } '... this composed okay'; + }, undef, '... this composed okay' ); ##... now nest 'em { diff --git a/t/030_roles/021_role_composite_exclusion.t b/t/030_roles/021_role_composite_exclusion.t index 322cd0a..8b9ae2e 100644 --- a/t/030_roles/021_role_composite_exclusion.t +++ b/t/030_roles/021_role_composite_exclusion.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Meta::Role::Application::RoleSummation; use Moose::Meta::Role::Composite; @@ -33,7 +33,7 @@ ok(Role::ExcludesFoo->meta->excludes_role('Role::Foo'), '... got the right exclu ok(Role::DoesExcludesFoo->meta->excludes_role('Role::Foo'), '... got the right exclusions'); # test simple exclusion -dies_ok { +isnt( exception { Moose::Meta::Role::Application::RoleSummation->new->apply( Moose::Meta::Role::Composite->new( roles => [ @@ -42,7 +42,7 @@ dies_ok { ] ) ); -} '... this fails as expected'; +}, undef, '... this fails as expected' ); # test no conflicts { @@ -56,9 +56,9 @@ dies_ok { is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name'); - lives_ok { + is( exception { Moose::Meta::Role::Application::RoleSummation->new->apply($c); - } '... this lives as expected'; + }, undef, '... this lives as expected' ); } # test no conflicts w/exclusion @@ -73,16 +73,16 @@ dies_ok { is($c->name, 'Role::Bar|Role::ExcludesFoo', '... got the composite role name'); - lives_ok { + is( exception { Moose::Meta::Role::Application::RoleSummation->new->apply($c); - } '... this lives as expected'; + }, undef, '... this lives as expected' ); is_deeply([$c->get_excluded_roles_list], ['Role::Foo'], '... has excluded roles'); } # test conflict with an "inherited" exclusion -dies_ok { +isnt( exception { Moose::Meta::Role::Application::RoleSummation->new->apply( Moose::Meta::Role::Composite->new( roles => [ @@ -92,10 +92,10 @@ dies_ok { ) ); -} '... this fails as expected'; +}, undef, '... this fails as expected' ); # test conflict with an "inherited" exclusion of an "inherited" role -dies_ok { +isnt( exception { Moose::Meta::Role::Application::RoleSummation->new->apply( Moose::Meta::Role::Composite->new( roles => [ @@ -104,6 +104,6 @@ dies_ok { ] ) ); -} '... this fails as expected'; +}, undef, '... this fails as expected' ); done_testing; diff --git a/t/030_roles/022_role_composition_req_methods.t b/t/030_roles/022_role_composition_req_methods.t index e3f1beb..f431806 100644 --- a/t/030_roles/022_role_composition_req_methods.t +++ b/t/030_roles/022_role_composition_req_methods.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Meta::Role::Application::RoleSummation; use Moose::Meta::Role::Composite; @@ -39,9 +39,9 @@ use Moose::Meta::Role::Composite; is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name'); - lives_ok { + is( exception { Moose::Meta::Role::Application::RoleSummation->new->apply($c); - } '... this succeeds as expected'; + }, undef, '... this succeeds as expected' ); is_deeply( [ sort $c->get_required_method_list ], @@ -62,9 +62,9 @@ use Moose::Meta::Role::Composite; is($c->name, 'Role::Foo|Role::ProvidesFoo', '... got the composite role name'); - lives_ok { + is( exception { Moose::Meta::Role::Application::RoleSummation->new->apply($c); - } '... this succeeds as expected'; + }, undef, '... this succeeds as expected' ); is_deeply( [ sort $c->get_required_method_list ], @@ -86,9 +86,9 @@ use Moose::Meta::Role::Composite; is($c->name, 'Role::Foo|Role::ProvidesFoo|Role::Bar', '... got the composite role name'); - lives_ok { + is( exception { Moose::Meta::Role::Application::RoleSummation->new->apply($c); - } '... this succeeds as expected'; + }, undef, '... this succeeds as expected' ); is_deeply( [ sort $c->get_required_method_list ], @@ -111,9 +111,9 @@ use Moose::Meta::Role::Composite; is($c->name, 'Role::Foo|Role::ProvidesFoo|Role::ProvidesBar|Role::Bar', '... got the composite role name'); - lives_ok { + is( exception { Moose::Meta::Role::Application::RoleSummation->new->apply($c); - } '... this succeeds as expected'; + }, undef, '... this succeeds as expected' ); is_deeply( [ sort $c->get_required_method_list ], diff --git a/t/030_roles/023_role_composition_attributes.t b/t/030_roles/023_role_composition_attributes.t index b8f8af0..33c605f 100644 --- a/t/030_roles/023_role_composition_attributes.t +++ b/t/030_roles/023_role_composition_attributes.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Meta::Role::Application::RoleSummation; use Moose::Meta::Role::Composite; @@ -43,9 +43,9 @@ use Moose::Meta::Role::Composite; is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name'); - lives_ok { + is( exception { Moose::Meta::Role::Application::RoleSummation->new->apply($c); - } '... this succeeds as expected'; + }, undef, '... this succeeds as expected' ); is_deeply( [ sort $c->get_attribute_list ], @@ -55,7 +55,7 @@ use Moose::Meta::Role::Composite; } # test simple conflict -dies_ok { +isnt( exception { Moose::Meta::Role::Application::RoleSummation->new->apply( Moose::Meta::Role::Composite->new( roles => [ @@ -64,10 +64,10 @@ dies_ok { ] ) ); -} '... this fails as expected'; +}, undef, '... this fails as expected' ); # test complex conflict -dies_ok { +isnt( exception { Moose::Meta::Role::Application::RoleSummation->new->apply( Moose::Meta::Role::Composite->new( roles => [ @@ -78,10 +78,10 @@ dies_ok { ] ) ); -} '... this fails as expected'; +}, undef, '... this fails as expected' ); # test simple conflict -dies_ok { +isnt( exception { Moose::Meta::Role::Application::RoleSummation->new->apply( Moose::Meta::Role::Composite->new( roles => [ @@ -90,6 +90,6 @@ dies_ok { ] ) ); -} '... this fails as expected'; +}, undef, '... this fails as expected' ); done_testing; diff --git a/t/030_roles/024_role_composition_methods.t b/t/030_roles/024_role_composition_methods.t index 5183245..0780c6f 100644 --- a/t/030_roles/024_role_composition_methods.t +++ b/t/030_roles/024_role_composition_methods.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Meta::Role::Application::RoleSummation; use Moose::Meta::Role::Composite; @@ -49,9 +49,9 @@ use Moose::Meta::Role::Composite; is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name'); - lives_ok { + is( exception { Moose::Meta::Role::Application::RoleSummation->new->apply($c); - } '... this succeeds as expected'; + }, undef, '... this succeeds as expected' ); is_deeply( [ sort $c->get_method_list ], @@ -72,9 +72,9 @@ use Moose::Meta::Role::Composite; is($c->name, 'Role::Foo|Role::FooConflict', '... got the composite role name'); - lives_ok { + is( exception { Moose::Meta::Role::Application::RoleSummation->new->apply($c); - } '... this succeeds as expected'; + }, undef, '... this succeeds as expected' ); is_deeply( [ sort $c->get_method_list ], @@ -103,9 +103,9 @@ use Moose::Meta::Role::Composite; is($c->name, 'Role::Foo|Role::Bar|Role::FooConflict|Role::BarConflict', '... got the composite role name'); - lives_ok { + is( exception { Moose::Meta::Role::Application::RoleSummation->new->apply($c); - } '... this succeeds as expected'; + }, undef, '... this succeeds as expected' ); is_deeply( [ sort $c->get_method_list ], @@ -132,9 +132,9 @@ use Moose::Meta::Role::Composite; is($c->name, 'Role::Foo|Role::AnotherFooConflict', '... got the composite role name'); - lives_ok { + is( exception { Moose::Meta::Role::Application::RoleSummation->new->apply($c); - } '... this succeeds as expected'; + }, undef, '... this succeeds as expected' ); is_deeply( [ sort $c->get_method_list ], diff --git a/t/030_roles/025_role_composition_override.t b/t/030_roles/025_role_composition_override.t index 4c428f2..602ac00 100644 --- a/t/030_roles/025_role_composition_override.t +++ b/t/030_roles/025_role_composition_override.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Meta::Role::Application::RoleSummation; use Moose::Meta::Role::Composite; @@ -48,9 +48,9 @@ use Moose::Meta::Role::Composite; is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name'); - lives_ok { + is( exception { Moose::Meta::Role::Application::RoleSummation->new->apply($c); - } '... this lives ok'; + }, undef, '... this lives ok' ); is_deeply( [ sort $c->get_method_modifier_list('override') ], @@ -60,7 +60,7 @@ use Moose::Meta::Role::Composite; } # test simple overrides w/ conflicts -dies_ok { +isnt( exception { Moose::Meta::Role::Application::RoleSummation->new->apply( Moose::Meta::Role::Composite->new( roles => [ @@ -69,10 +69,10 @@ dies_ok { ] ) ); -} '... this fails as expected'; +}, undef, '... this fails as expected' ); # test simple overrides w/ conflicts -dies_ok { +isnt( exception { Moose::Meta::Role::Application::RoleSummation->new->apply( Moose::Meta::Role::Composite->new( roles => [ @@ -81,11 +81,11 @@ dies_ok { ] ) ); -} '... this fails as expected'; +}, undef, '... this fails as expected' ); # test simple overrides w/ conflicts -dies_ok { +isnt( exception { Moose::Meta::Role::Application::RoleSummation->new->apply( Moose::Meta::Role::Composite->new( roles => [ @@ -95,11 +95,11 @@ dies_ok { ] ) ); -} '... this fails as expected'; +}, undef, '... this fails as expected' ); # test simple overrides w/ conflicts -dies_ok { +isnt( exception { Moose::Meta::Role::Application::RoleSummation->new->apply( Moose::Meta::Role::Composite->new( roles => [ @@ -109,6 +109,6 @@ dies_ok { ] ) ); -} '... this fails as expected'; +}, undef, '... this fails as expected' ); done_testing; diff --git a/t/030_roles/026_role_composition_method_mods.t b/t/030_roles/026_role_composition_method_mods.t index 5df6523..3d5495c 100644 --- a/t/030_roles/026_role_composition_method_mods.t +++ b/t/030_roles/026_role_composition_method_mods.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Meta::Role::Application::RoleSummation; use Moose::Meta::Role::Composite; @@ -62,9 +62,9 @@ use Moose::Meta::Role::Composite; is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name'); - lives_ok { + is( exception { Moose::Meta::Role::Application::RoleSummation->new->apply($c); - } '... this succeeds as expected'; + }, undef, '... this succeeds as expected' ); is_deeply( [ sort $c->get_method_modifier_list('before') ], diff --git a/t/030_roles/031_roles_applied_in_create.t b/t/030_roles/031_roles_applied_in_create.t index 0d45373..1fc3cf6 100644 --- a/t/030_roles/031_roles_applied_in_create.t +++ b/t/030_roles/031_roles_applied_in_create.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Meta::Class; use Moose::Util; @@ -13,14 +13,13 @@ use lib 't/lib', 'lib'; # Note that this test passed (pre svn #5543) if we inlined the role # definitions in this file, as it was very timing sensitive. -lives_ok { +is( exception { my $builder_meta = Moose::Meta::Class->create( 'YATTA' => ( superclass => 'Moose::Meta::Class', roles => [qw( Role::Interface Role::Child )], ) ); -} -'Create a new class with several roles'; +}, undef, 'Create a new class with several roles' ); done_testing; diff --git a/t/030_roles/043_conflict_many_methods.t b/t/030_roles/043_conflict_many_methods.t index 785d48f..f016fb0 100644 --- a/t/030_roles/043_conflict_many_methods.t +++ b/t/030_roles/043_conflict_many_methods.t @@ -3,7 +3,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { package Bomb; @@ -33,16 +33,16 @@ use Test::Exception; package PracticalJoke; use Moose; - ::throws_ok { + ::like( ::exception { with 'Bomb', 'Spouse'; - } qr/Due to method name conflicts in roles 'Bomb' and 'Spouse', the methods 'explode' and 'fuse' must be implemented or excluded by 'PracticalJoke'/; + }, qr/Due to method name conflicts in roles 'Bomb' and 'Spouse', the methods 'explode' and 'fuse' must be implemented or excluded by 'PracticalJoke'/ ); - ::throws_ok { + ::like( ::exception { with ( 'Bomb', 'Spouse', 'Caninish', 'Treeve', ); - } qr/Due to a method name conflict in roles 'Caninish' and 'Treeve', the method 'bark' must be implemented or excluded by 'PracticalJoke'/; + }, qr/Due to a method name conflict in roles 'Caninish' and 'Treeve', the method 'bark' must be implemented or excluded by 'PracticalJoke'/ ); } done_testing; diff --git a/t/030_roles/045_role_compose_requires.t b/t/030_roles/045_role_compose_requires.t index 75f2e3b..8c1abee 100644 --- a/t/030_roles/045_role_compose_requires.t +++ b/t/030_roles/045_role_compose_requires.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { package My::Role1; @@ -54,93 +54,79 @@ use Test::Exception; # roles they consume. { local $TODO = "role attributes don't satisfy method requirements"; - lives_ok { package My::Test1; use Moose; with 'My::Role2'; } - 'role2(provides attribute) consumes role1'; + is( exception { package My::Test1; use Moose; with 'My::Role2'; }, undef, 'role2(provides attribute) consumes role1' ); } -lives_ok { package My::Test2; use Moose; with 'My::Role3'; } -'role3(provides method) consumes role1'; +is( exception { package My::Test2; use Moose; with 'My::Role3'; }, undef, 'role3(provides method) consumes role1' ); # As I understand the design, Roles composed in the same with() statement # should NOT demonstrate ordering dependency. Alter these tests if that # assumption is false. -Vince Veselosky { local $TODO = "role attributes don't satisfy method requirements"; - lives_ok { package My::Test3; use Moose; with 'My::Role4', 'My::Role1'; } - 'class consumes role4(provides attribute), role1'; + is( exception { package My::Test3; use Moose; with 'My::Role4', 'My::Role1'; }, undef, 'class consumes role4(provides attribute), role1' ); } { local $TODO = "role attributes don't satisfy method requirements"; - lives_ok { package My::Test4; use Moose; with 'My::Role1', 'My::Role4'; } - 'class consumes role1, role4(provides attribute)'; + is( exception { package My::Test4; use Moose; with 'My::Role1', 'My::Role4'; }, undef, 'class consumes role1, role4(provides attribute)' ); } -lives_ok { package My::Test5; use Moose; with 'My::Role5', 'My::Role1'; } -'class consumes role5(provides method), role1'; +is( exception { package My::Test5; use Moose; with 'My::Role5', 'My::Role1'; }, undef, 'class consumes role5(provides method), role1' ); -lives_ok { package My::Test6; use Moose; with 'My::Role1', 'My::Role5'; } -'class consumes role1, role5(provides method)'; +is( exception { package My::Test6; use Moose; with 'My::Role1', 'My::Role5'; }, undef, 'class consumes role1, role5(provides method)' ); # Inherited methods/attributes should satisfy requires(), as long as # extends() comes first in code order. -lives_ok { +is( exception { package My::Test7; use Moose; extends 'My::Base1'; with 'My::Role1'; -} -'class extends base1(provides attribute), consumes role1'; +}, undef, 'class extends base1(provides attribute), consumes role1' ); -lives_ok { +is( exception { package My::Test8; use Moose; extends 'My::Base2'; with 'My::Role1'; -} -'class extends base2(provides method), consumes role1'; +}, undef, 'class extends base2(provides method), consumes role1' ); # Attributes/methods implemented in class should satisfy requires() -lives_ok { +is( exception { package My::Test9; use Moose; has 'test_output', is => 'rw'; with 'My::Role1'; -} -'class provides attribute, consumes role1'; +}, undef, 'class provides attribute, consumes role1' ); -lives_ok { +is( exception { package My::Test10; use Moose; sub test_output { } with 'My::Role1'; -} -'class provides method, consumes role1'; +}, undef, 'class provides method, consumes role1' ); # Roles composed in separate with() statements SHOULD demonstrate ordering # dependency. See comment with tests 3-6 above. -lives_ok { +is( exception { package My::Test11; use Moose; with 'My::Role4'; with 'My::Role1'; -} -'class consumes role4(provides attribute); consumes role1'; +}, undef, 'class consumes role4(provides attribute); consumes role1' ); -dies_ok { package My::Test12; use Moose; with 'My::Role1'; with 'My::Role4'; } -'class consumes role1; consumes role4(provides attribute)'; +isnt( exception { package My::Test12; use Moose; with 'My::Role1'; with 'My::Role4'; }, undef, 'class consumes role1; consumes role4(provides attribute)' ); -lives_ok { +is( exception { package My::Test13; use Moose; with 'My::Role5'; with 'My::Role1'; -} -'class consumes role5(provides method); consumes role1'; +}, undef, 'class consumes role5(provides method); consumes role1' ); -dies_ok { package My::Test14; use Moose; with 'My::Role1'; with 'My::Role5'; } -'class consumes role1; consumes role5(provides method)'; +isnt( exception { package My::Test14; use Moose; with 'My::Role1'; with 'My::Role5'; }, undef, 'class consumes role1; consumes role5(provides method)' ); done_testing; diff --git a/t/030_roles/047_role_attribute_conflict.t b/t/030_roles/047_role_attribute_conflict.t index 46b3296..d4ad4c5 100644 --- a/t/030_roles/047_role_attribute_conflict.t +++ b/t/030_roles/047_role_attribute_conflict.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { package My::Role1; @@ -22,8 +22,7 @@ use Test::Exception; is => 'ro', ); - ::throws_ok { with 'My::Role1' } qr/attribute conflict.+My::Role2.+foo/, - 'attribute conflict when composing one role into another'; + ::like( ::exception { with 'My::Role1' }, qr/attribute conflict.+My::Role2.+foo/, 'attribute conflict when composing one role into another' ); } done_testing; diff --git a/t/030_roles/048_method_modifiers.t b/t/030_roles/048_method_modifiers.t index 4bab997..4b4bca3 100644 --- a/t/030_roles/048_method_modifiers.t +++ b/t/030_roles/048_method_modifiers.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; my $FooRole; { @@ -66,9 +66,9 @@ my $QuuxRole; package Quux::Role; use Moose::Role; { our $TODO; local $TODO = "can't handle regexes yet"; - ::lives_ok { + ::is( ::exception { after qr/foo|bar/ => sub { $QuuxRole++ } - }; + }, undef ); } } diff --git a/t/040_type_constraints/001_util_type_constraints.t b/t/040_type_constraints/001_util_type_constraints.t index c7c611e..2b26d5f 100644 --- a/t/040_type_constraints/001_util_type_constraints.t +++ b/t/040_type_constraints/001_util_type_constraints.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Scalar::Util (); @@ -118,8 +118,7 @@ is($string->validate(5), "This is not a string (5)", '... validated unsuccessfully (got error)'); -lives_ok { Moose::Meta::Attribute->new('bob', isa => 'Spong') } - 'meta-attr construction ok even when type constraint utils loaded first'; +is( exception { Moose::Meta::Attribute->new('bob', isa => 'Spong') }, undef, 'meta-attr construction ok even when type constraint utils loaded first' ); # Test type constraint predicate return values. @@ -130,9 +129,9 @@ foreach my $predicate (qw/equals is_subtype_of is_a_type_of/) { # Test adding things which don't look like types to the registry throws an exception my $r = Moose::Util::TypeConstraints->get_type_constraint_registry; -throws_ok {$r->add_type_constraint()} qr/not a valid type constraint/, '->add_type_constraint(undef) throws'; -throws_ok {$r->add_type_constraint('foo')} qr/not a valid type constraint/, '->add_type_constraint("foo") throws'; -throws_ok {$r->add_type_constraint(bless {}, 'SomeClass')} qr/not a valid type constraint/, '->add_type_constraint(SomeClass->new) throws'; +like( exception {$r->add_type_constraint()}, qr/not a valid type constraint/, '->add_type_constraint(undef) throws' ); +like( exception {$r->add_type_constraint('foo')}, qr/not a valid type constraint/, '->add_type_constraint("foo") throws' ); +like( exception {$r->add_type_constraint(bless {}, 'SomeClass')}, qr/not a valid type constraint/, '->add_type_constraint(SomeClass->new) throws' ); # Test some specific things that in the past did not work, # specifically weird variations on anon subtypes. @@ -186,8 +185,7 @@ throws_ok {$r->add_type_constraint(bless {}, 'SomeClass')} qr/not a valid type c } { - throws_ok { subtype 'Foo' } qr/cannot consist solely of a name/, - 'Cannot call subtype with a single string argument'; + like( exception { subtype 'Foo' }, qr/cannot consist solely of a name/, 'Cannot call subtype with a single string argument' ); } # Back-compat for being called without sugar. Previously, calling with diff --git a/t/040_type_constraints/005_util_type_coercion.t b/t/040_type_constraints/005_util_type_coercion.t index 49f9069..5ee520d 100644 --- a/t/040_type_constraints/005_util_type_coercion.t +++ b/t/040_type_constraints/005_util_type_coercion.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; BEGIN { use_ok('Moose::Util::TypeConstraints'); @@ -40,13 +40,13 @@ ok(!Header({}), '... this did not pass the type test'); my $anon_type = subtype Object => where { $_->isa('HTTPHeader') }; -lives_ok { +is( exception { coerce $anon_type => from ArrayRef => via { HTTPHeader->new(array => $_[0]) } => from HashRef => via { HTTPHeader->new(hash => $_[0]) }; -} 'coercion of anonymous subtype succeeds'; +}, undef, 'coercion of anonymous subtype succeeds' ); foreach my $coercion ( find_type_constraint('Header')->coercion, diff --git a/t/040_type_constraints/007_util_more_type_coercion.t b/t/040_type_constraints/007_util_more_type_coercion.t index c24d6bc..7c5f30a 100644 --- a/t/040_type_constraints/007_util_more_type_coercion.t +++ b/t/040_type_constraints/007_util_more_type_coercion.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -37,9 +37,9 @@ use Test::Exception; # try with arrays - lives_ok { + is( exception { $engine->header([ 1, 2, 3 ]); - } '... type was coerced without incident'; + }, undef, '... type was coerced without incident' ); isa_ok($engine->header, 'HTTPHeader'); is_deeply( @@ -50,9 +50,9 @@ use Test::Exception; # try with hash - lives_ok { + is( exception { $engine->header({ one => 1, two => 2, three => 3 }); - } '... type was coerced without incident'; + }, undef, '... type was coerced without incident' ); isa_ok($engine->header, 'HTTPHeader'); is_deeply( @@ -61,13 +61,13 @@ use Test::Exception; '... got the right hash value of the header'); ok(!defined($engine->header->array), '... no array value set'); - dies_ok { + isnt( exception { $engine->header("Foo"); - } '... dies with the wrong type, even after coercion'; + }, undef, '... dies with the wrong type, even after coercion' ); - lives_ok { + is( exception { $engine->header(HTTPHeader->new); - } '... lives with the right type, even after coercion'; + }, undef, '... lives with the right type, even after coercion' ); } { @@ -106,13 +106,13 @@ use Test::Exception; ok(!defined($engine->header->array), '... no array value set'); } -dies_ok { +isnt( exception { Engine->new(header => 'Foo'); -} '... dies correctly with bad params'; +}, undef, '... dies correctly with bad params' ); -dies_ok { +isnt( exception { Engine->new(header => \(my $var)); -} '... dies correctly with bad params'; +}, undef, '... dies correctly with bad params' ); { my $tc = Moose::Util::TypeConstraints::find_type_constraint('HTTPHeader'); @@ -126,9 +126,7 @@ dies_ok { isa_ok($from_href, 'HTTPHeader', 'assert_coerce from href to HTTPHeader'); is_deeply($from_href->hash, { a => 1 }, '...and has the right guts'); - throws_ok { $tc->assert_coerce('total garbage') } - qr/Validation failed for .HTTPHeader./, - "assert_coerce throws if result is not acceptable"; + like( exception { $tc->assert_coerce('total garbage') }, qr/Validation failed for .HTTPHeader./, "assert_coerce throws if result is not acceptable" ); } done_testing; diff --git a/t/040_type_constraints/009_union_types_and_coercions.t b/t/040_type_constraints/009_union_types_and_coercions.t index e7071f2..1bf35f2 100644 --- a/t/040_type_constraints/009_union_types_and_coercions.t +++ b/t/040_type_constraints/009_union_types_and_coercions.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Test::Requires { 'IO::String' => '0.01', # skip all if not installed @@ -79,9 +79,9 @@ use Test::Requires { is($email->as_string, '... this is my body ...', '... got correct string'); - lives_ok { + is( exception { $email->raw_body('... this is the next body ...'); - } '... this will coerce correctly'; + }, undef, '... this will coerce correctly' ); isa_ok($email->raw_body, 'IO::String'); @@ -100,9 +100,9 @@ use Test::Requires { my $str2 = '... this is the next body (ref) ...'; - lives_ok { + is( exception { $email->raw_body(\$str2); - } '... this will coerce correctly'; + }, undef, '... this will coerce correctly' ); isa_ok($email->raw_body, 'IO::String'); @@ -122,9 +122,9 @@ use Test::Requires { my $io_str2 = IO::String->new('... this is the next body (IO::String) ...'); - lives_ok { + is( exception { $email->raw_body($io_str2); - } '... this will coerce correctly'; + }, undef, '... this will coerce correctly' ); isa_ok($email->raw_body, 'IO::String'); is($email->raw_body, $io_str2, '... and it is the one we expected'); @@ -175,16 +175,13 @@ use Test::Requires { { my $foo; - lives_ok { $foo = Foo->new( carray => 1 ) } - 'Can pass non-ref value for carray'; + is( exception { $foo = Foo->new( carray => 1 ) }, undef, 'Can pass non-ref value for carray' ); is_deeply( $foo->carray, [1], 'carray was coerced to an array ref' ); - throws_ok { Foo->new( carray => {} ) } - qr/\QValidation failed for 'Coerced|Coerced' with value \E(?!undef)/, - 'Cannot pass a hash ref for carray attribute, and hash ref is not coerced to an undef'; + like( exception { Foo->new( carray => {} ) }, qr/\QValidation failed for 'Coerced|Coerced' with value \E(?!undef)/, 'Cannot pass a hash ref for carray attribute, and hash ref is not coerced to an undef' ); } done_testing; diff --git a/t/040_type_constraints/010_misc_type_tests.t b/t/040_type_constraints/010_misc_type_tests.t index 7b86046..4b5e1d3 100644 --- a/t/040_type_constraints/010_misc_type_tests.t +++ b/t/040_type_constraints/010_misc_type_tests.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Scalar::Util qw(refaddr); BEGIN { @@ -13,9 +13,9 @@ BEGIN { # subtype 'aliasing' ... -lives_ok { +is( exception { subtype 'Numb3rs' => as 'Num'; -} '... create bare subtype fine'; +}, undef, '... create bare subtype fine' ); my $numb3rs = find_type_constraint('Numb3rs'); isa_ok($numb3rs, 'Moose::Meta::TypeConstraint'); diff --git a/t/040_type_constraints/015_enum.t b/t/040_type_constraints/015_enum.t index 92c0062..6a55ec1 100644 --- a/t/040_type_constraints/015_enum.t +++ b/t/040_type_constraints/015_enum.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Scalar::Util (); @@ -63,19 +63,15 @@ ok( !$anon_enum->is_subtype_of('ThisTypeDoesNotExist'), 'enum not a subtype of n ok( !$anon_enum->is_a_type_of('ThisTypeDoesNotExist'), 'enum not type of nonexistant type'); # validation -throws_ok { Moose::Meta::TypeConstraint::Enum->new(name => 'ZeroValues', values => []) } - qr/You must have at least two values to enumerate through/; +like( exception { Moose::Meta::TypeConstraint::Enum->new(name => 'ZeroValues', values => []) }, qr/You must have at least two values to enumerate through/ ); -throws_ok { Moose::Meta::TypeConstraint::Enum->new(name => 'OneValue', values => [ 'a' ]) } - qr/You must have at least two values to enumerate through/; +like( exception { Moose::Meta::TypeConstraint::Enum->new(name => 'OneValue', values => [ 'a' ]) }, qr/You must have at least two values to enumerate through/ ); -throws_ok { Moose::Meta::TypeConstraint::Enum->new(name => 'ReferenceInEnum', values => [ 'a', {} ]) } - qr/Enum values must be strings, not 'HASH\(0x\w+\)'/; +like( exception { Moose::Meta::TypeConstraint::Enum->new(name => 'ReferenceInEnum', values => [ 'a', {} ]) }, qr/Enum values must be strings, not 'HASH\(0x\w+\)'/ ); -throws_ok { Moose::Meta::TypeConstraint::Enum->new(name => 'UndefInEnum', values => [ 'a', undef ]) } - qr/Enum values must be strings, not undef/; +like( exception { Moose::Meta::TypeConstraint::Enum->new(name => 'UndefInEnum', values => [ 'a', undef ]) }, qr/Enum values must be strings, not undef/ ); -throws_ok { +like( exception { package Foo; use Moose; use Moose::Util::TypeConstraints; @@ -85,7 +81,7 @@ throws_ok { isa => enum ['a', 'aa', 'aaa'], # should be parenthesized! default => 'aa', ); -} qr/enum called with an array reference and additional arguments\. Did you mean to parenthesize the enum call's parameters\?/; +}, qr/enum called with an array reference and additional arguments\. Did you mean to parenthesize the enum call's parameters\?/ ); done_testing; diff --git a/t/040_type_constraints/016_subtyping_parameterized_types.t b/t/040_type_constraints/016_subtyping_parameterized_types.t index 21269c4..acdbd22 100644 --- a/t/040_type_constraints/016_subtyping_parameterized_types.t +++ b/t/040_type_constraints/016_subtyping_parameterized_types.t @@ -4,15 +4,15 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; BEGIN { use_ok("Moose::Util::TypeConstraints"); } -lives_ok { +is( exception { subtype 'MySpecialHash' => as 'HashRef[Int]'; -} '... created the subtype special okay'; +}, undef, '... created the subtype special okay' ); { my $t = find_type_constraint('MySpecialHash'); @@ -37,14 +37,14 @@ lives_ok { ok( !$t->is_subtype_of("ThisTypeDoesNotExist"), "not a subtype of a non existant type" ); } -lives_ok { +is( exception { subtype 'MySpecialHashExtended' => as 'HashRef[Int]' => where { # all values are less then 10 (scalar grep { $_ < 10 } values %{$_}) ? 1 : undef }; -} '... created the subtype special okay'; +}, undef, '... created the subtype special okay' ); { my $t = find_type_constraint('MySpecialHashExtended'); @@ -63,11 +63,11 @@ lives_ok { ok(!$t->check({ one => "ONE", two => "TWO" }), '... validated it correctly'); } -lives_ok { +is( exception { subtype 'MyNonSpecialHash' => as "HashRef" => where { keys %$_ == 3 }; -}; +}, undef ); { my $t = find_type_constraint('MyNonSpecialHash'); @@ -114,10 +114,10 @@ lives_ok { ok $SubOfMyArrayRef->check([15,20,25]), '[15,20,25] is a bunch of big ints'; ok ! $SubOfMyArrayRef->check([15,5,25]), '[15,5,25] is NOT a bunch of big ints'; - throws_ok { + like( exception { my $SubOfMyArrayRef = subtype 'SubSubOfMyArrayRef', as 'SubOfMyArrayRef[Str]'; - } qr/Str is not a subtype of BiggerInt/, 'Failed to parameterize with a bad type parameter'; + }, qr/Str is not a subtype of BiggerInt/, 'Failed to parameterize with a bad type parameter' ); } { diff --git a/t/040_type_constraints/017_subtyping_union_types.t b/t/040_type_constraints/017_subtyping_union_types.t index b76ae7c..9b3ae24 100644 --- a/t/040_type_constraints/017_subtyping_union_types.t +++ b/t/040_type_constraints/017_subtyping_union_types.t @@ -4,15 +4,15 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; BEGIN { use_ok("Moose::Util::TypeConstraints"); } -lives_ok { +is( exception { subtype 'MyCollections' => as 'ArrayRef | HashRef'; -} '... created the subtype special okay'; +}, undef, '... created the subtype special okay' ); { my $t = find_type_constraint('MyCollections'); @@ -31,7 +31,7 @@ lives_ok { ok(!$t->check(1), '... validated it correctly'); } -lives_ok { +is( exception { subtype 'MyCollectionsExtended' => as 'ArrayRef|HashRef' => where { @@ -43,7 +43,7 @@ lives_ok { } 1; }; -} '... created the subtype special okay'; +}, undef, '... created the subtype special okay' ); { my $t = find_type_constraint('MyCollectionsExtended'); diff --git a/t/040_type_constraints/018_custom_parameterized_types.t b/t/040_type_constraints/018_custom_parameterized_types.t index c4969e5..14ccd18 100644 --- a/t/040_type_constraints/018_custom_parameterized_types.t +++ b/t/040_type_constraints/018_custom_parameterized_types.t @@ -4,31 +4,31 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; BEGIN { use_ok("Moose::Util::TypeConstraints"); use_ok('Moose::Meta::TypeConstraint::Parameterized'); } -lives_ok { +is( exception { subtype 'AlphaKeyHash' => as 'HashRef' => where { # no keys match non-alpha (grep { /[^a-zA-Z]/ } keys %$_) == 0 }; -} '... created the subtype special okay'; +}, undef, '... created the subtype special okay' ); -lives_ok { +is( exception { subtype 'Trihash' => as 'AlphaKeyHash' => where { keys(%$_) == 3 }; -} '... created the subtype special okay'; +}, undef, '... created the subtype special okay' ); -lives_ok { +is( exception { subtype 'Noncon' => as 'Item'; -} '... created the subtype special okay'; +}, undef, '... created the subtype special okay' ); { my $t = find_type_constraint('AlphaKeyHash'); @@ -68,20 +68,20 @@ ok($th->check({ one => 1, two => 0, three => 1 }), '... validated it correctly') ok(!$th->check({ one => 1, two => 2, three => 1 }), '... validated it correctly'); ok(!$th->check({foo1 => 1, bar2 => 0, baz3 => 1}), '... validated it correctly'); -dies_ok { +isnt( exception { Moose::Meta::TypeConstraint::Parameterized->new( name => 'Str[Int]', parent => find_type_constraint('Str'), type_parameter => find_type_constraint('Int'), ); -} 'non-containers cannot be parameterized'; +}, undef, 'non-containers cannot be parameterized' ); -dies_ok { +isnt( exception { Moose::Meta::TypeConstraint::Parameterized->new( name => 'Noncon[Int]', parent => find_type_constraint('Noncon'), type_parameter => find_type_constraint('Int'), ); -} 'non-containers cannot be parameterized'; +}, undef, 'non-containers cannot be parameterized' ); done_testing; diff --git a/t/040_type_constraints/019_coerced_parameterized_types.t b/t/040_type_constraints/019_coerced_parameterized_types.t index 84de514..e4386e6 100644 --- a/t/040_type_constraints/019_coerced_parameterized_types.t +++ b/t/040_type_constraints/019_coerced_parameterized_types.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; BEGIN { use_ok("Moose::Util::TypeConstraints"); @@ -26,11 +26,11 @@ BEGIN { subtype 'MyList' => as 'Object' => where { $_->isa('MyList') }; -lives_ok { +is( exception { coerce 'ArrayRef' => from 'MyList' => via { [ $_->items ] } -} '... created the coercion okay'; +}, undef, '... created the coercion okay' ); my $mylist = Moose::Util::TypeConstraints::find_or_parse_type_constraint('MyList[Int]'); @@ -43,11 +43,11 @@ subtype 'EvenList' => as 'MyList' => where { $_->items % 2 == 0 }; # XXX: get this to work *without* the declaration. I suspect it'll be a new # method in Moose::Meta::TypeCoercion that will look at the parents of the # coerced type as well. but will that be too "action at a distance"-ey? -lives_ok { +is( exception { coerce 'ArrayRef' => from 'EvenList' => via { [ $_->items ] } -} '... created the coercion okay'; +}, undef, '... created the coercion okay' ); my $evenlist = Moose::Util::TypeConstraints::find_or_parse_type_constraint('EvenList[Int]'); diff --git a/t/040_type_constraints/020_class_type_constraint.t b/t/040_type_constraints/020_class_type_constraint.t index f91ddf5..50608c9 100644 --- a/t/040_type_constraints/020_class_type_constraint.t +++ b/t/040_type_constraints/020_class_type_constraint.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; BEGIN { use_ok('Moose::Util::TypeConstraints'); @@ -24,9 +24,8 @@ BEGIN { } -lives_ok { class_type 'Beep' } 'class_type keywork works'; -lives_ok { class_type('Boop', message { "${_} is not a Boop" }) } - 'class_type keywork works with message'; +is( exception { class_type 'Beep' }, undef, 'class_type keywork works' ); +is( exception { class_type('Boop', message { "${_} is not a Boop" }) }, undef, 'class_type keywork works with message' ); my $type = find_type_constraint("Foo"); diff --git a/t/040_type_constraints/021_maybe_type_constraint.t b/t/040_type_constraints/021_maybe_type_constraint.t index bfa8991..7ea9340 100644 --- a/t/040_type_constraints/021_maybe_type_constraint.t +++ b/t/040_type_constraints/021_maybe_type_constraint.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Util::TypeConstraints; @@ -38,41 +38,41 @@ ok(!$type->check([]), '... checked type correctly (fail)'); has 'maybe_bar' => (is => 'rw', isa => maybe_type(class_type('Bar'))); } -lives_ok { +is( exception { Foo->new(arr => [], bar => Bar->new); -} '... Bar->new isa Bar'; +}, undef, '... Bar->new isa Bar' ); -dies_ok { +isnt( exception { Foo->new(arr => [], bar => undef); -} '... undef isnta Bar'; +}, undef, '... undef isnta Bar' ); -lives_ok { +is( exception { Foo->new(arr => [], maybe_bar => Bar->new); -} '... Bar->new isa maybe(Bar)'; +}, undef, '... Bar->new isa maybe(Bar)' ); -lives_ok { +is( exception { Foo->new(arr => [], maybe_bar => undef); -} '... undef isa maybe(Bar)'; +}, undef, '... undef isa maybe(Bar)' ); -dies_ok { +isnt( exception { Foo->new(arr => [], maybe_bar => 1); -} '... 1 isnta maybe(Bar)'; +}, undef, '... 1 isnta maybe(Bar)' ); -lives_ok { +is( exception { Foo->new(arr => []); -} '... it worked!'; +}, undef, '... it worked!' ); -lives_ok { +is( exception { Foo->new(arr => undef); -} '... it worked!'; +}, undef, '... it worked!' ); -dies_ok { +isnt( exception { Foo->new(arr => 100); -} '... failed the type check'; +}, undef, '... failed the type check' ); -dies_ok { +isnt( exception { Foo->new(arr => 'hello world'); -} '... failed the type check'; +}, undef, '... failed the type check' ); { @@ -121,15 +121,11 @@ ok sub {$obj->Maybe_Int(undef); 1}->() ok !$Maybe_Int->check("") => 'failed ("")'; -throws_ok { $obj->Maybe_Int("") } - qr/Attribute \(Maybe_Int\) does not pass the type constraint/ - => 'failed assigned ("")'; +like( exception { $obj->Maybe_Int("") }, qr/Attribute \(Maybe_Int\) does not pass the type constraint/, 'failed assigned ("")' ); ok !$Maybe_Int->check("a") => 'failed ("a")'; -throws_ok { $obj->Maybe_Int("a") } - qr/Attribute \(Maybe_Int\) does not pass the type constraint/ - => 'failed assigned ("a")'; +like( exception { $obj->Maybe_Int("a") }, qr/Attribute \(Maybe_Int\) does not pass the type constraint/, 'failed assigned ("a")' ); done_testing; diff --git a/t/040_type_constraints/022_custom_type_errors.t b/t/040_type_constraints/022_custom_type_errors.t index f570474..5526342 100644 --- a/t/040_type_constraints/022_custom_type_errors.t +++ b/t/040_type_constraints/022_custom_type_errors.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { package Animal; @@ -25,36 +25,23 @@ use Test::Exception; ); } -lives_ok { my $goat = Animal->new( leg_count => 4 ) } -'... no errors thrown, value is good'; -lives_ok { my $spider = Animal->new( leg_count => 8 ) } -'... no errors thrown, value is good'; +is( exception { my $goat = Animal->new( leg_count => 4 ) }, undef, '... no errors thrown, value is good' ); +is( exception { my $spider = Animal->new( leg_count => 8 ) }, undef, '... no errors thrown, value is good' ); -throws_ok { my $fern = Animal->new( leg_count => 0 ) } -qr/This number \(0\) is not less than ten!/, - 'gave custom supertype error message on new'; +like( exception { my $fern = Animal->new( leg_count => 0 ) }, qr/This number \(0\) is not less than ten!/, 'gave custom supertype error message on new' ); -throws_ok { my $centipede = Animal->new( leg_count => 30 ) } -qr/This number \(30\) is not less than ten!/, - 'gave custom subtype error message on new'; +like( exception { my $centipede = Animal->new( leg_count => 30 ) }, qr/This number \(30\) is not less than ten!/, 'gave custom subtype error message on new' ); my $chimera; -lives_ok { $chimera = Animal->new( leg_count => 4 ) } -'... no errors thrown, value is good'; +is( exception { $chimera = Animal->new( leg_count => 4 ) }, undef, '... no errors thrown, value is good' ); -throws_ok { $chimera->leg_count(0) } -qr/This number \(0\) is not less than ten!/, - 'gave custom supertype error message on set to 0'; +like( exception { $chimera->leg_count(0) }, qr/This number \(0\) is not less than ten!/, 'gave custom supertype error message on set to 0' ); -throws_ok { $chimera->leg_count(16) } -qr/This number \(16\) is not less than ten!/, - 'gave custom subtype error message on set to 16'; +like( exception { $chimera->leg_count(16) }, qr/This number \(16\) is not less than ten!/, 'gave custom subtype error message on set to 16' ); my $gimp = eval { Animal->new() }; is( $@, '', '... no errors thrown, value is good' ); -throws_ok { $gimp->leg_count } -qr/This number \(0\) is not less than ten!/, - 'gave custom supertype error message on lazy set to 0'; +like( exception { $gimp->leg_count }, qr/This number \(0\) is not less than ten!/, 'gave custom supertype error message on lazy set to 0' ); done_testing; diff --git a/t/040_type_constraints/023_types_and_undef.t b/t/040_type_constraints/023_types_and_undef.t index 1c2e7ee..549958c 100644 --- a/t/040_type_constraints/023_types_and_undef.t +++ b/t/040_type_constraints/023_types_and_undef.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -70,41 +70,41 @@ ok(String('Foo'), '... "Foo" is a String'); my $foo = Foo->new; -lives_ok { $foo->vUndef(undef) } '... undef is a Foo->Undef'; -dies_ok { $foo->vDefined(undef) } '... undef is NOT a Foo->Defined'; -dies_ok { $foo->vInt(undef) } '... undef is NOT a Foo->Int'; -dies_ok { $foo->vNumber(undef) } '... undef is NOT a Foo->Number'; -dies_ok { $foo->vStr(undef) } '... undef is NOT a Foo->Str'; -dies_ok { $foo->vString(undef) } '... undef is NOT a Foo->String'; - -dies_ok { $foo->vUndef(5) } '... 5 is NOT a Foo->Undef'; -lives_ok { $foo->vDefined(5) } '... 5 is a Foo->Defined'; -lives_ok { $foo->vInt(5) } '... 5 is a Foo->Int'; -lives_ok { $foo->vNumber(5) } '... 5 is a Foo->Number'; -lives_ok { $foo->vStr(5) } '... 5 is a Foo->Str'; -dies_ok { $foo->vString(5) } '... 5 is NOT a Foo->String'; - -dies_ok { $foo->vUndef(0.5) } '... 0.5 is NOT a Foo->Undef'; -lives_ok { $foo->vDefined(0.5) } '... 0.5 is a Foo->Defined'; -dies_ok { $foo->vInt(0.5) } '... 0.5 is NOT a Foo->Int'; -lives_ok { $foo->vNumber(0.5) } '... 0.5 is a Foo->Number'; -lives_ok { $foo->vStr(0.5) } '... 0.5 is a Foo->Str'; -dies_ok { $foo->vString(0.5) } '... 0.5 is NOT a Foo->String'; - -dies_ok { $foo->vUndef('Foo') } '... "Foo" is NOT a Foo->Undef'; -lives_ok { $foo->vDefined('Foo') } '... "Foo" is a Foo->Defined'; -dies_ok { $foo->vInt('Foo') } '... "Foo" is NOT a Foo->Int'; -dies_ok { $foo->vNumber('Foo') } '... "Foo" is NOT a Foo->Number'; -lives_ok { $foo->vStr('Foo') } '... "Foo" is a Foo->Str'; -lives_ok { $foo->vString('Foo') } '... "Foo" is a Foo->String'; +is( exception { $foo->vUndef(undef) }, undef, '... undef is a Foo->Undef' ); +isnt( exception { $foo->vDefined(undef) }, undef, '... undef is NOT a Foo->Defined' ); +isnt( exception { $foo->vInt(undef) }, undef, '... undef is NOT a Foo->Int' ); +isnt( exception { $foo->vNumber(undef) }, undef, '... undef is NOT a Foo->Number' ); +isnt( exception { $foo->vStr(undef) }, undef, '... undef is NOT a Foo->Str' ); +isnt( exception { $foo->vString(undef) }, undef, '... undef is NOT a Foo->String' ); + +isnt( exception { $foo->vUndef(5) }, undef, '... 5 is NOT a Foo->Undef' ); +is( exception { $foo->vDefined(5) }, undef, '... 5 is a Foo->Defined' ); +is( exception { $foo->vInt(5) }, undef, '... 5 is a Foo->Int' ); +is( exception { $foo->vNumber(5) }, undef, '... 5 is a Foo->Number' ); +is( exception { $foo->vStr(5) }, undef, '... 5 is a Foo->Str' ); +isnt( exception { $foo->vString(5) }, undef, '... 5 is NOT a Foo->String' ); + +isnt( exception { $foo->vUndef(0.5) }, undef, '... 0.5 is NOT a Foo->Undef' ); +is( exception { $foo->vDefined(0.5) }, undef, '... 0.5 is a Foo->Defined' ); +isnt( exception { $foo->vInt(0.5) }, undef, '... 0.5 is NOT a Foo->Int' ); +is( exception { $foo->vNumber(0.5) }, undef, '... 0.5 is a Foo->Number' ); +is( exception { $foo->vStr(0.5) }, undef, '... 0.5 is a Foo->Str' ); +isnt( exception { $foo->vString(0.5) }, undef, '... 0.5 is NOT a Foo->String' ); + +isnt( exception { $foo->vUndef('Foo') }, undef, '... "Foo" is NOT a Foo->Undef' ); +is( exception { $foo->vDefined('Foo') }, undef, '... "Foo" is a Foo->Defined' ); +isnt( exception { $foo->vInt('Foo') }, undef, '... "Foo" is NOT a Foo->Int' ); +isnt( exception { $foo->vNumber('Foo') }, undef, '... "Foo" is NOT a Foo->Number' ); +is( exception { $foo->vStr('Foo') }, undef, '... "Foo" is a Foo->Str' ); +is( exception { $foo->vString('Foo') }, undef, '... "Foo" is a Foo->String' ); # the lazy tests -lives_ok { $foo->v_lazy_Undef() } '... undef is a Foo->Undef'; -dies_ok { $foo->v_lazy_Defined() } '... undef is NOT a Foo->Defined'; -dies_ok { $foo->v_lazy_Int() } '... undef is NOT a Foo->Int'; -dies_ok { $foo->v_lazy_Number() } '... undef is NOT a Foo->Number'; -dies_ok { $foo->v_lazy_Str() } '... undef is NOT a Foo->Str'; -dies_ok { $foo->v_lazy_String() } '... undef is NOT a Foo->String'; +is( exception { $foo->v_lazy_Undef() }, undef, '... undef is a Foo->Undef' ); +isnt( exception { $foo->v_lazy_Defined() }, undef, '... undef is NOT a Foo->Defined' ); +isnt( exception { $foo->v_lazy_Int() }, undef, '... undef is NOT a Foo->Int' ); +isnt( exception { $foo->v_lazy_Number() }, undef, '... undef is NOT a Foo->Number' ); +isnt( exception { $foo->v_lazy_Str() }, undef, '... undef is NOT a Foo->Str' ); +isnt( exception { $foo->v_lazy_String() }, undef, '... undef is NOT a Foo->String' ); done_testing; diff --git a/t/040_type_constraints/024_role_type_constraint.t b/t/040_type_constraints/024_role_type_constraint.t index 163bfca..eae75d4 100644 --- a/t/040_type_constraints/024_role_type_constraint.t +++ b/t/040_type_constraints/024_role_type_constraint.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; BEGIN { use_ok('Moose::Util::TypeConstraints'); @@ -32,8 +32,7 @@ BEGIN { } -lives_ok { role_type('Boop', message { "${_} is not a Boop" }) } - 'role_type keywork works with message'; +is( exception { role_type('Boop', message { "${_} is not a Boop" }) }, undef, 'role_type keywork works with message' ); my $type = find_type_constraint("Foo"); diff --git a/t/040_type_constraints/027_parameterize_from.t b/t/040_type_constraints/027_parameterize_from.t index 5be0677..3e97310 100644 --- a/t/040_type_constraints/027_parameterize_from.t +++ b/t/040_type_constraints/027_parameterize_from.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; BEGIN { use_ok('Moose::Util::TypeConstraints'); @@ -43,39 +43,36 @@ isa_ok $params, 'Test::Moose::Meta::TypeConstraint::Parameterizable' => # test parameterizable -lives_ok { +is( exception { $params->parameterizable( { a => 'Hello', b => 'World' } ); -} 'No problem setting parameterizable'; +}, undef, 'No problem setting parameterizable' ); is_deeply $params->parameterizable, { a => 'Hello', b => 'World' } => 'Got expected values'; # test parameterized -lives_ok { +is( exception { $params->parameterized( { a => 1, b => 2 } ); -} 'No problem setting parameterized'; +}, undef, 'No problem setting parameterized' ); is_deeply $params->parameterized, { a => 1, b => 2 } => 'Got expected values'; -throws_ok { +like( exception { $params->parameterized( { a => 'Hello', b => 'World' } ); - } qr/Attribute \(parameterized\) does not pass the type constraint/ => - 'parameterized throws expected error'; + }, qr/Attribute \(parameterized\) does not pass the type constraint/, 'parameterized throws expected error' ); # test from_parameterizable -lives_ok { +is( exception { $params->from_parameterizable( { a => 1, b => 2 } ); -} 'No problem setting from_parameterizable'; +}, undef, 'No problem setting from_parameterizable' ); is_deeply $params->from_parameterizable, { a => 1, b => 2 } => 'Got expected values'; -throws_ok { +like( exception { $params->from_parameterizable( { a => 'Hello', b => 'World' } ); - } - qr/Attribute \(from_parameterizable\) does not pass the type constraint/, - 'from_parameterizable throws expected error'; + }, qr/Attribute \(from_parameterizable\) does not pass the type constraint/, 'from_parameterizable throws expected error' ); done_testing; diff --git a/t/040_type_constraints/029_define_type_twice_throws.t b/t/040_type_constraints/029_define_type_twice_throws.t index cbec2e2..6cc05ed 100644 --- a/t/040_type_constraints/029_define_type_twice_throws.t +++ b/t/040_type_constraints/029_define_type_twice_throws.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; BEGIN { use_ok('Moose::Util::TypeConstraints'); @@ -17,11 +17,11 @@ BEGIN { subtype 'MySubType' => as 'Int' => where { 1 }; } -throws_ok { +like( exception { package Some::Other::Class; use Moose::Util::TypeConstraints; subtype 'MySubType' => as 'Int' => where { 1 }; -} qr/cannot be created again/, 'Trying to create same type twice throws'; +}, qr/cannot be created again/, 'Trying to create same type twice throws' ); done_testing; diff --git a/t/040_type_constraints/030_class_subtypes.t b/t/040_type_constraints/030_class_subtypes.t index ec9a156..c5839c0 100644 --- a/t/040_type_constraints/030_class_subtypes.t +++ b/t/040_type_constraints/030_class_subtypes.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Util::TypeConstraints; use Moose::Meta::TypeConstraint; @@ -98,26 +98,26 @@ like $isa_foo->get_message( Baz->new ), qr/^Validation failed for 'IsaFoo' with ); } -throws_ok { +like( exception { Quux->new(age => 3) -} qr/^Attribute \(age\) does not pass the type constraint because: Validation failed for 'Positive' with value 3 \(not isa Positive\)/; +}, qr/^Attribute \(age\) does not pass the type constraint because: Validation failed for 'Positive' with value 3 \(not isa Positive\)/ ); -lives_ok { +is( exception { Quux->new(age => (bless {}, 'Positive')); -}; +}, undef ); eval " package Positive; use Moose; "; -throws_ok { +like( exception { Quux->new(age => 3) -} qr/^Attribute \(age\) does not pass the type constraint because: Validation failed for 'Positive' with value 3 \(not isa Positive\)/; +}, qr/^Attribute \(age\) does not pass the type constraint because: Validation failed for 'Positive' with value 3 \(not isa Positive\)/ ); -lives_ok { +is( exception { Quux->new(age => Positive->new) -}; +}, undef ); class_type 'Negative' => message { "$_ is not a Negative Nancy" }; @@ -132,12 +132,12 @@ class_type 'Negative' => message { "$_ is not a Negative Nancy" }; ); } -throws_ok { +like( exception { Quux::Ier->new(age => 3) -} qr/^Attribute \(age\) does not pass the type constraint because: 3 is not a Negative Nancy /; +}, qr/^Attribute \(age\) does not pass the type constraint because: 3 is not a Negative Nancy / ); -lives_ok { +is( exception { Quux::Ier->new(age => (bless {}, 'Negative')) -}; +}, undef ); done_testing; diff --git a/t/040_type_constraints/033_type_names.t b/t/040_type_constraints/033_type_names.t index d523557..bc4dcaf 100644 --- a/t/040_type_constraints/033_type_names.t +++ b/t/040_type_constraints/033_type_names.t @@ -2,7 +2,6 @@ use strict; use warnings; use Test::More; -use Test::Exception; use Test::Fatal; use Moose::Meta::TypeConstraint; @@ -30,15 +29,11 @@ TODO: } } -lives_ok { Moose::Meta::TypeConstraint->new( name => 'Foo.Bar::Baz' ) } -'Type names can contain periods and colons'; +is( exception { Moose::Meta::TypeConstraint->new( name => 'Foo.Bar::Baz' ) }, undef, 'Type names can contain periods and colons' ); -throws_ok { subtype 'Foo-Baz' => as 'Item' } -qr/contains invalid characters/, - 'Type names cannot contain a dash (via subtype sugar)'; +like( exception { subtype 'Foo-Baz' => as 'Item' }, qr/contains invalid characters/, 'Type names cannot contain a dash (via subtype sugar)' ); -lives_ok { subtype 'Foo.Bar::Baz' => as 'Item' } -'Type names can contain periods and colons (via subtype sugar)'; +is( exception { subtype 'Foo.Bar::Baz' => as 'Item' }, undef, 'Type names can contain periods and colons (via subtype sugar)' ); is( Moose::Util::TypeConstraints::find_or_parse_type_constraint('ArrayRef[In-valid]'), undef, diff --git a/t/040_type_constraints/034_duck_types.t b/t/040_type_constraints/034_duck_types.t index 5682793..cc12852 100644 --- a/t/040_type_constraints/034_duck_types.t +++ b/t/040_type_constraints/034_duck_types.t @@ -3,7 +3,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -62,21 +62,18 @@ use Test::Exception; } # try giving it a duck -lives_ok { DucktypeTest->new( duck => Duck->new ) } 'the Duck lives okay'; +is( exception { DucktypeTest->new( duck => Duck->new ) }, undef, 'the Duck lives okay' ); # try giving it a swan which is like a duck, but not close enough -throws_ok { DucktypeTest->new( duck => Swan->new ) } -qr/Swan is missing methods 'quack'/, - "the Swan doesn't quack"; +like( exception { DucktypeTest->new( duck => Swan->new ) }, qr/Swan is missing methods 'quack'/, "the Swan doesn't quack" ); # try giving it a rubber RubberDuckey -lives_ok { DucktypeTest->new( swan => Swan->new ) } 'but a Swan can honk'; +is( exception { DucktypeTest->new( swan => Swan->new ) }, undef, 'but a Swan can honk' ); # try giving it a rubber RubberDuckey -lives_ok { DucktypeTest->new( duck => RubberDuck->new ) } -'the RubberDuck lives okay'; +is( exception { DucktypeTest->new( duck => RubberDuck->new ) }, undef, 'the RubberDuck lives okay' ); # try with the other constraint form -lives_ok { DucktypeTest->new( other_swan => Swan->new ) } 'but a Swan can honk'; +is( exception { DucktypeTest->new( other_swan => Swan->new ) }, undef, 'but a Swan can honk' ); done_testing; diff --git a/t/040_type_constraints/036_match_type_operator.t b/t/040_type_constraints/036_match_type_operator.t index fd5cc88..4304487 100644 --- a/t/040_type_constraints/036_match_type_operator.t +++ b/t/040_type_constraints/036_match_type_operator.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Util::TypeConstraints; @@ -87,9 +87,9 @@ is( is_acceptable_color( 'magenta' ), 'CMYK', '... got the right value'); is( is_acceptable_color( 'yellow' ), 'CMYK', '... got the right value'); is( is_acceptable_color( 'black' ), 'CMYK', '... got the right value'); -dies_ok { +isnt( exception { is_acceptable_color( 'orange' ) -} '... got the exception'; +}, undef, '... got the exception' ); ## using it in an OO context @@ -222,8 +222,8 @@ sub not_enough_matches { CodeRef => sub { $_->('Hello code ref world') }; } -throws_ok { +like( exception { not_enough_matches( [] ) -} qr/No cases matched for /, '... not enough matches'; +}, qr/No cases matched for /, '... not enough matches' ); done_testing; diff --git a/t/050_metaclasses/002_custom_attr_meta_as_role.t b/t/050_metaclasses/002_custom_attr_meta_as_role.t index 55ee9c6..0b1af53 100644 --- a/t/050_metaclasses/002_custom_attr_meta_as_role.t +++ b/t/050_metaclasses/002_custom_attr_meta_as_role.t @@ -4,19 +4,19 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; -lives_ok { +is( exception { package MooseX::Attribute::Test; use Moose::Role; -} 'creating custom attribute "metarole" is okay'; +}, undef, 'creating custom attribute "metarole" is okay' ); -lives_ok { +is( exception { package Moose::Meta::Attribute::Custom::Test; use Moose; extends 'Moose::Meta::Attribute'; with 'MooseX::Attribute::Test'; -} 'custom attribute metaclass extending role is okay'; +}, undef, 'custom attribute metaclass extending role is okay' ); done_testing; diff --git a/t/050_metaclasses/012_moose_exporter.t b/t/050_metaclasses/012_moose_exporter.t index ac39d23..98bde56 100644 --- a/t/050_metaclasses/012_moose_exporter.t +++ b/t/050_metaclasses/012_moose_exporter.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Test::Requires { 'Test::Output' => '0.01', # skip all if not installed @@ -197,18 +197,13 @@ use Test::Requires { use Moose (); - ::dies_ok - { - Moose::Exporter->setup_import_methods( + ::like( + ::exception{ Moose::Exporter->setup_import_methods( also => [ 'Moose', 'MooseX::CircularAlso' ], ); - } - 'a circular reference in also dies with an error'; - - ::like( - $@, + }, qr/\QCircular reference in 'also' parameter to Moose::Exporter between MooseX::CircularAlso and MooseX::CircularAlso/, - 'got the expected error from circular reference in also' + 'a circular reference in also dies with an error' ); } @@ -217,18 +212,13 @@ use Test::Requires { use Moose (); - ::dies_ok - { - Moose::Exporter->setup_import_methods( - also => [ 'NoSuchThing' ], - ); - } - 'a package which does not use Moose::Exporter in also dies with an error'; - ::like( - $@, + ::exception{ Moose::Exporter->setup_import_methods( + also => ['NoSuchThing'], + ); + }, qr/\QPackage in also (NoSuchThing) does not seem to use Moose::Exporter (is it loaded?) at /, - 'got the expected error from a reference in also to a package which is not loaded' + 'a package which does not use Moose::Exporter in also dies with an error' ); } @@ -237,18 +227,13 @@ use Test::Requires { use Moose (); - ::dies_ok - { - Moose::Exporter->setup_import_methods( - also => [ 'Moose::Meta::Method' ], - ); - } - 'a package which does not use Moose::Exporter in also dies with an error'; - ::like( - $@, + ::exception{ Moose::Exporter->setup_import_methods( + also => ['Moose::Meta::Method'], + ); + }, qr/\QPackage in also (Moose::Meta::Method) does not seem to use Moose::Exporter at /, - 'got the expected error from a reference in also to a package which does not use Moose::Exporter' + 'a package which does not use Moose::Exporter in also dies with an error' ); } diff --git a/t/050_metaclasses/013_metaclass_traits.t b/t/050_metaclasses/013_metaclass_traits.t index dcab7bd..a96d95e 100644 --- a/t/050_metaclasses/013_metaclass_traits.t +++ b/t/050_metaclasses/013_metaclass_traits.t @@ -6,7 +6,7 @@ use warnings; use lib 't/lib', 'lib'; use Test::More; -use Test::Exception; +use Test::Fatal; { package My::SimpleTrait; @@ -167,10 +167,14 @@ is( Role::Foo->meta()->simple(), 5, { require Moose::Util::TypeConstraints; - dies_ok { Moose::Util::TypeConstraints->import( -traits => 'My::SimpleTrait' ) } - 'cannot provide -traits to an exporting module that does not init_meta'; - like( $@, qr/does not have an init_meta/, - '... and error provides a useful explanation' ); + like( + exception { + Moose::Util::TypeConstraints->import( + -traits => 'My::SimpleTrait' ); + }, + qr/does not have an init_meta/, + 'cannot provide -traits to an exporting module that does not init_meta' + ); } { @@ -198,11 +202,10 @@ is( Foo::Subclass->meta()->attr2(), 'something', has an_attr => ( is => 'ro' ); } -lives_ok { +is( exception { my $instance = Class::WithAlreadyPresentTrait->new( an_attr => 'value' ); is( $instance->an_attr, 'value', 'Can get value' ); -} -'Can create instance and access attributes'; +}, undef, 'Can create instance and access attributes' ); { @@ -215,10 +218,9 @@ lives_ok { has an_attr => ( is => 'ro' ); } -lives_ok { +is( exception { my $instance = Class::WhichLoadsATraitFromDisk->new( an_attr => 'value' ); is( $instance->an_attr, 'value', 'Can get value' ); -} -'Can create instance and access attributes'; +}, undef, 'Can create instance and access attributes' ); done_testing; diff --git a/t/050_metaclasses/014_goto_moose_import.t b/t/050_metaclasses/014_goto_moose_import.t index 8b45680..b3389cb 100644 --- a/t/050_metaclasses/014_goto_moose_import.t +++ b/t/050_metaclasses/014_goto_moose_import.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; # Some packages out in the wild cooperate with Moose by using goto # &Moose::import. we want to make sure it still works. @@ -31,8 +31,7 @@ use Test::Exception; MooseAlike1->import(); - ::lives_ok { has( 'size', is => 'bare' ) } - 'has was exported via MooseAlike1'; + ::is( ::exception { has( 'size', is => 'bare' ) }, undef, 'has was exported via MooseAlike1' ); MooseAlike1->unimport(); } @@ -68,8 +67,7 @@ isa_ok( Foo->meta(), 'Moose::Meta::Class' ); MooseAlike2->import(); - ::lives_ok { has( 'size', is => 'bare' ) } - 'has was exported via MooseAlike2'; + ::is( ::exception { has( 'size', is => 'bare' ) }, undef, 'has was exported via MooseAlike2' ); MooseAlike2->unimport(); } diff --git a/t/050_metaclasses/015_metarole.t b/t/050_metaclasses/015_metarole.t index 6d80c50..1bdde3e 100644 --- a/t/050_metaclasses/015_metarole.t +++ b/t/050_metaclasses/015_metarole.t @@ -6,7 +6,7 @@ use warnings; use lib 't/lib', 'lib'; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Util::MetaRole; @@ -580,10 +580,10 @@ use Moose::Util::MetaRole; } } -lives_ok { +is( exception { package UsesExportedMoose; ExportsMoose->import; -} 'import module which loads a role from disk during init_meta'; +}, undef, 'import module which loads a role from disk during init_meta' ); { package Foo::Meta::Role; diff --git a/t/050_metaclasses/018_throw_error.t b/t/050_metaclasses/018_throw_error.t index 5988905..a332c93 100644 --- a/t/050_metaclasses/018_throw_error.t +++ b/t/050_metaclasses/018_throw_error.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -119,7 +119,7 @@ sub create_error { ); use Moose; - ::dies_ok { extends 'Baz::Sub' } 'error_class is included in metaclass compatibility checks'; + ::isnt( ::exception { extends 'Baz::Sub' }, undef, 'error_class is included in metaclass compatibility checks' ); } { @@ -145,7 +145,7 @@ ok( Foo::Sub->meta->error_class->isa('Moose::Error::Croak'), package Foo::Sub::Sub; use Moose; - ::lives_ok { extends 'Foo::Sub' } 'error_class differs by role so incompat is handled'; + ::is( ::exception { extends 'Foo::Sub' }, undef, 'error_class differs by role so incompat is handled' ); Moose::Util::MetaRole::apply_metaroles( for => __PACKAGE__, diff --git a/t/050_metaclasses/019_create_anon_with_required_attr.t b/t/050_metaclasses/019_create_anon_with_required_attr.t index 70bddd6..28e5202 100644 --- a/t/050_metaclasses/019_create_anon_with_required_attr.t +++ b/t/050_metaclasses/019_create_anon_with_required_attr.t @@ -7,7 +7,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { package HasFoo; @@ -30,29 +30,29 @@ use Test::Exception; package main; my $anon; -lives_ok { +is( exception { $anon = My::Metaclass->create_anon_class( foo => 'this' ); -} 'create anon class with required attr'; +}, undef, 'create anon class with required attr' ); isa_ok( $anon, 'My::Metaclass' ); cmp_ok( $anon->foo, 'eq', 'this', 'foo is this' ); -dies_ok { +isnt( exception { $anon = My::Metaclass->create_anon_class(); -} 'failed to create anon class without required attr'; +}, undef, 'failed to create anon class without required attr' ); my $meta; -lives_ok { +is( exception { $meta = My::Metaclass->initialize( 'Class::Name1' => ( foo => 'that' ) ); -} 'initialize a class with required attr'; +}, undef, 'initialize a class with required attr' ); isa_ok( $meta, 'My::Metaclass' ); cmp_ok( $meta->foo, 'eq', 'that', 'foo is that' ); cmp_ok( $meta->name, 'eq', 'Class::Name1', 'for the correct class' ); -dies_ok { +isnt( exception { $meta = My::Metaclass->initialize( 'Class::Name2' ); -} 'failed to initialize a class without required attr'; +}, undef, 'failed to initialize a class without required attr' ); -lives_ok { +is( exception { eval qq{ package Class::Name3; use metaclass 'My::Metaclass' => ( @@ -61,28 +61,28 @@ lives_ok { use Moose; }; die $@ if $@; -} 'use metaclass with required attr'; +}, undef, 'use metaclass with required attr' ); $meta = Class::Name3->meta; isa_ok( $meta, 'My::Metaclass' ); cmp_ok( $meta->foo, 'eq', 'another', 'foo is another' ); cmp_ok( $meta->name, 'eq', 'Class::Name3', 'for the correct class' ); -dies_ok { +isnt( exception { eval qq{ package Class::Name4; use metaclass 'My::Metaclass'; use Moose; }; die $@ if $@; -} 'failed to use metaclass without required attr'; +}, undef, 'failed to use metaclass without required attr' ); # how do we pass a required attribute to -traits? -dies_ok { +isnt( exception { eval qq{ package Class::Name5; use Moose -traits => 'HasFoo'; }; die $@ if $@; -} 'failed to use trait without required attr'; +}, undef, 'failed to use trait without required attr' ); done_testing; diff --git a/t/050_metaclasses/021_export_with_prototype.t b/t/050_metaclasses/021_export_with_prototype.t index 6c8f5e2..97227c6 100644 --- a/t/050_metaclasses/021_export_with_prototype.t +++ b/t/050_metaclasses/021_export_with_prototype.t @@ -3,20 +3,20 @@ package MyExporter::User; use MyExporter; use Test::More; -use Test::Exception; +use Test::Fatal; -lives_and { +is( exception { with_prototype { my $caller = caller(0); is($caller, 'MyExporter', "With_caller prototype code gets called from MyMooseX"); }; -} "check function with prototype"; +}, undef, "check function with prototype" ); -lives_and { +is( exception { as_is_prototype { my $caller = caller(0); is($caller, 'MyExporter', "As-is prototype code gets called from MyMooseX"); }; -} "check function with prototype"; +}, undef, "check function with prototype" ); done_testing; diff --git a/t/050_metaclasses/041_moose_nonmoose_moose_chain_init_meta.t b/t/050_metaclasses/041_moose_nonmoose_moose_chain_init_meta.t index ed12d4c..36fac71 100644 --- a/t/050_metaclasses/041_moose_nonmoose_moose_chain_init_meta.t +++ b/t/050_metaclasses/041_moose_nonmoose_moose_chain_init_meta.t @@ -15,10 +15,10 @@ use warnings; } use Test::More; -use Test::Exception; +use Test::Fatal; -lives_ok { +is( exception { Moose->init_meta(for_class => 'SomeClass'); -} 'Moose class => use base => Moose Class, then Moose->init_meta on middle class ok'; +}, undef, 'Moose class => use base => Moose Class, then Moose->init_meta on middle class ok' ); done_testing; diff --git a/t/050_metaclasses/050_metarole_backcompat.t b/t/050_metaclasses/050_metarole_backcompat.t index 2ded6e4..82462c1 100644 --- a/t/050_metaclasses/050_metarole_backcompat.t +++ b/t/050_metaclasses/050_metarole_backcompat.t @@ -9,7 +9,7 @@ use warnings; use lib 't/lib', 'lib'; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Util::MetaRole; @@ -583,10 +583,10 @@ use Moose::Util::MetaRole; } } -lives_ok { +is( exception { package UsesExportedMoose; ExportsMoose->import; -} 'import module which loads a role from disk during init_meta'; +}, undef, 'import module which loads a role from disk during init_meta' ); { package Foo::Meta::Role; diff --git a/t/050_metaclasses/052_metaclass_compat.t b/t/050_metaclasses/052_metaclass_compat.t index f29db50..f56fc59 100644 --- a/t/050_metaclasses/052_metaclass_compat.t +++ b/t/050_metaclasses/052_metaclass_compat.t @@ -3,7 +3,7 @@ use strict; use warnings; use lib 't/lib'; use Test::More; -use Test::Exception; +use Test::Fatal; our $called = 0; { @@ -74,16 +74,16 @@ ok(Foo::Sub->meta->constructor_class->meta->can('does_role') package Baz2; use Moose; my $meta = __PACKAGE__->meta; - ::lives_ok { $meta->superclasses('Foo2') } "can set superclasses once"; + ::is( ::exception { $meta->superclasses('Foo2') }, undef, "can set superclasses once" ); ::isa_ok($meta, Foo2->meta->meta->name); - ::lives_ok { $meta->superclasses('Bar2') } "can still set superclasses"; + ::is( ::exception { $meta->superclasses('Bar2') }, undef, "can still set superclasses" ); ::isa_ok($meta, Bar2->meta->meta->name); ::is_deeply([sort map { $_->name } $meta->meta->calculate_all_roles_with_inheritance], ['Foo2::Role'], "still have the role attached"); ::ok(!$meta->is_immutable, "immutable superclass doesn't make this class immutable"); - ::lives_ok { $meta->make_immutable } "can still make immutable"; + ::is( ::exception { $meta->make_immutable }, undef, "can still make immutable" ); } { package Foo3::Role; @@ -97,19 +97,19 @@ ok(Foo::Sub->meta->constructor_class->meta->can('does_role') package Baz3; use Moose -traits => ['Foo3::Role']; my $meta = __PACKAGE__->meta; - ::lives_ok { $meta->superclasses('Foo2') } "can set superclasses once"; + ::is( ::exception { $meta->superclasses('Foo2') }, undef, "can set superclasses once" ); ::isa_ok($meta, Foo2->meta->meta->name); ::is_deeply([sort map { $_->name } $meta->meta->calculate_all_roles_with_inheritance], ['Foo2::Role', 'Foo3::Role'], "reconciled roles correctly"); - ::lives_ok { $meta->superclasses('Bar3') } "can still set superclasses"; + ::is( ::exception { $meta->superclasses('Bar3') }, undef, "can still set superclasses" ); ::isa_ok($meta, Bar3->meta->meta->name); ::is_deeply([sort map { $_->name } $meta->meta->calculate_all_roles_with_inheritance], ['Foo2::Role', 'Foo3::Role'], "roles still the same"); ::ok(!$meta->is_immutable, "immutable superclass doesn't make this class immutable"); - ::lives_ok { $meta->make_immutable } "can still make immutable"; + ::is( ::exception { $meta->make_immutable }, undef, "can still make immutable" ); } { package Quux3; @@ -119,19 +119,19 @@ ok(Foo::Sub->meta->constructor_class->meta->can('does_role') package Quuux3; use Moose -traits => ['Foo3::Role']; my $meta = __PACKAGE__->meta; - ::lives_ok { $meta->superclasses('Foo2') } "can set superclasses once"; + ::is( ::exception { $meta->superclasses('Foo2') }, undef, "can set superclasses once" ); ::isa_ok($meta, Foo2->meta->meta->name); ::is_deeply([sort map { $_->name } $meta->meta->calculate_all_roles_with_inheritance], ['Foo2::Role', 'Foo3::Role'], "reconciled roles correctly"); - ::lives_ok { $meta->superclasses('Quux3') } "can still set superclasses"; + ::is( ::exception { $meta->superclasses('Quux3') }, undef, "can still set superclasses" ); ::isa_ok($meta, Quux3->meta->meta->name); ::is_deeply([sort map { $_->name } $meta->meta->calculate_all_roles_with_inheritance], ['Foo2::Role', 'Foo3::Role'], "roles still the same"); ::ok(!$meta->is_immutable, "immutable superclass doesn't make this class immutable"); - ::lives_ok { $meta->make_immutable } "can still make immutable"; + ::is( ::exception { $meta->make_immutable }, undef, "can still make immutable" ); } { @@ -151,16 +151,16 @@ ok(Foo::Sub->meta->constructor_class->meta->can('does_role') package Baz4; use Moose; my $meta = __PACKAGE__->meta; - ::lives_ok { $meta->superclasses('Foo4') } "can set superclasses once"; + ::is( ::exception { $meta->superclasses('Foo4') }, undef, "can set superclasses once" ); ::isa_ok($meta, Foo4->meta->_get_mutable_metaclass_name); - ::lives_ok { $meta->superclasses('Bar4') } "can still set superclasses"; + ::is( ::exception { $meta->superclasses('Bar4') }, undef, "can still set superclasses" ); ::isa_ok($meta, Bar4->meta->meta->name); ::is_deeply([sort map { $_->name } $meta->meta->calculate_all_roles_with_inheritance], ['Foo4::Role'], "still have the role attached"); ::ok(!$meta->is_immutable, "immutable superclass doesn't make this class immutable"); - ::lives_ok { $meta->make_immutable } "can still make immutable"; + ::is( ::exception { $meta->make_immutable }, undef, "can still make immutable" ); } { package Foo5::Role; @@ -174,19 +174,19 @@ ok(Foo::Sub->meta->constructor_class->meta->can('does_role') package Baz5; use Moose -traits => ['Foo5::Role']; my $meta = __PACKAGE__->meta; - ::lives_ok { $meta->superclasses('Foo4') } "can set superclasses once"; + ::is( ::exception { $meta->superclasses('Foo4') }, undef, "can set superclasses once" ); ::isa_ok($meta, Foo4->meta->_get_mutable_metaclass_name); ::is_deeply([sort map { $_->name } $meta->meta->calculate_all_roles_with_inheritance], ['Foo4::Role', 'Foo5::Role'], "reconciled roles correctly"); - ::lives_ok { $meta->superclasses('Bar5') } "can still set superclasses"; + ::is( ::exception { $meta->superclasses('Bar5') }, undef, "can still set superclasses" ); ::isa_ok($meta, Bar5->meta->meta->name); ::is_deeply([sort map { $_->name } $meta->meta->calculate_all_roles_with_inheritance], ['Foo4::Role', 'Foo5::Role'], "roles still the same"); ::ok(!$meta->is_immutable, "immutable superclass doesn't make this class immutable"); - ::lives_ok { $meta->make_immutable } "can still make immutable"; + ::is( ::exception { $meta->make_immutable }, undef, "can still make immutable" ); } { package Quux5; @@ -196,19 +196,19 @@ ok(Foo::Sub->meta->constructor_class->meta->can('does_role') package Quuux5; use Moose -traits => ['Foo5::Role']; my $meta = __PACKAGE__->meta; - ::lives_ok { $meta->superclasses('Foo4') } "can set superclasses once"; + ::is( ::exception { $meta->superclasses('Foo4') }, undef, "can set superclasses once" ); ::isa_ok($meta, Foo4->meta->_get_mutable_metaclass_name); ::is_deeply([sort map { $_->name } $meta->meta->calculate_all_roles_with_inheritance], ['Foo4::Role', 'Foo5::Role'], "reconciled roles correctly"); - ::lives_ok { $meta->superclasses('Quux5') } "can still set superclasses"; + ::is( ::exception { $meta->superclasses('Quux5') }, undef, "can still set superclasses" ); ::isa_ok($meta, Quux5->meta->meta->name); ::is_deeply([sort map { $_->name } $meta->meta->calculate_all_roles_with_inheritance], ['Foo4::Role', 'Foo5::Role'], "roles still the same"); ::ok(!$meta->is_immutable, "immutable superclass doesn't make this class immutable"); - ::lives_ok { $meta->make_immutable } "can still make immutable"; + ::is( ::exception { $meta->make_immutable }, undef, "can still make immutable" ); } { @@ -233,13 +233,12 @@ ok(Foo::Sub->meta->constructor_class->meta->can('does_role') push(@superclasses, 'Foo5::SuperClass::After::Attribute'); - ::lives_ok { + ::is( ::exception { extends @superclasses; - } 'MI extends after_generated_methods with metaclass roles'; - ::lives_ok { + }, undef, 'MI extends after_generated_methods with metaclass roles' ); + ::is( ::exception { extends reverse @superclasses; - } - 'MI extends after_generated_methods with metaclass roles (reverse)'; + }, undef, 'MI extends after_generated_methods with metaclass roles (reverse)' ); } { @@ -268,14 +267,12 @@ ok(Foo::Sub->meta->constructor_class->meta->can('does_role') push(@superclasses, 'Foo6::SuperClass::After::Attribute'); - ::throws_ok { + ::like( ::exception { extends @superclasses; - } qr/compat.*pristine/, - 'unsafe MI extends after_generated_methods with metaclass roles'; - ::throws_ok { + }, qr/compat.*pristine/, 'unsafe MI extends after_generated_methods with metaclass roles' ); + ::like( ::exception { extends reverse @superclasses; - } qr/compat.*pristine/, - 'unsafe MI extends after_generated_methods with metaclass roles (reverse)'; + }, qr/compat.*pristine/, 'unsafe MI extends after_generated_methods with metaclass roles (reverse)' ); } { @@ -292,14 +289,14 @@ ok(Foo::Sub->meta->constructor_class->meta->can('does_role') package Bar7; # in an external file use Moose -traits => ['Bar7::Meta::Trait']; - ::lives_ok { extends 'Foo7' } "role reconciliation works"; + ::is( ::exception { extends 'Foo7' }, undef, "role reconciliation works" ); } { package Bar72; # in an external file use Moose -traits => ['Bar7::Meta::Trait2']; - ::lives_ok { extends 'Foo7' } "role reconciliation works"; + ::is( ::exception { extends 'Foo7' }, undef, "role reconciliation works" ); } done_testing; diff --git a/t/050_metaclasses/054_metaclass_compat_no_fixing_bug.t b/t/050_metaclasses/054_metaclass_compat_no_fixing_bug.t index 6190faa..5fc833d 100644 --- a/t/050_metaclasses/054_metaclass_compat_no_fixing_bug.t +++ b/t/050_metaclasses/054_metaclass_compat_no_fixing_bug.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { package Foo::Meta::Constructor1; @@ -40,7 +40,7 @@ use Test::Exception; for => __PACKAGE__, class_metaroles => { constructor => ['Foo::Meta::Constructor2'] }, ); - ::lives_ok { extends 'Foo::Sub' } "doesn't try to fix if nothing is needed"; + ::is( ::exception { extends 'Foo::Sub' }, undef, "doesn't try to fix if nothing is needed" ); } done_testing; diff --git a/t/050_metaclasses/060_reinitialize.t b/t/050_metaclasses/060_reinitialize.t index bb35eb0..ca34b7d 100644 --- a/t/050_metaclasses/060_reinitialize.t +++ b/t/050_metaclasses/060_reinitialize.t @@ -3,7 +3,7 @@ use strict; use warnings; use Test::More; use Test::Moose; -use Test::Exception; +use Test::Fatal; sub check_meta_sanity { my ($meta, $class) = @_; @@ -126,13 +126,13 @@ does_ok(Bar->meta->get_attribute('bar'), 'Foo::Role::Attribute'); BEGIN { extends 'Moose::Meta::Attribute' }; } -throws_ok { +like( exception { Moose::Meta::Class->reinitialize( 'Bar', method_metaclass => 'Bar::Meta::Method', attribute_metaclass => 'Bar::Meta::Attribute', ); -} qr/compatible/; +}, qr/compatible/ ); { package Baz::Meta::Class; @@ -189,13 +189,13 @@ does_ok(Baz->meta->get_attribute('bar'), 'Foo::Role::Attribute'); extends 'Moose::Meta::Attribute'; } -throws_ok { +like( exception { Moose::Meta::Class->reinitialize( 'Baz', method_metaclass => 'Baz::Meta::Method', attribute_metaclass => 'Baz::Meta::Attribute', ); -} qr/compatible/; +}, qr/compatible/ ); { package Quux; diff --git a/t/060_compat/001_module_refresh_compat.t b/t/060_compat/001_module_refresh_compat.t index 03553f9..2eb8e09 100644 --- a/t/060_compat/001_module_refresh_compat.t +++ b/t/060_compat/001_module_refresh_compat.t @@ -6,7 +6,7 @@ use warnings; use lib 't/lib', 'lib'; use Test::More; -use Test::Exception; +use Test::Fatal; use File::Spec; use File::Temp 'tempdir'; @@ -28,9 +28,9 @@ do { is($_->meta->name, $_, '... initialized the meta correctly'); - lives_ok { + is( exception { Module::Refresh->new->refresh_module($_ . '.pm') - } '... successfully refreshed ' . $_; + }, undef, '... successfully refreshed ' ); } foreach @modules; =pod @@ -79,9 +79,9 @@ ok(!TestBaz->isa('Foo'), '... TestBaz is not a Foo'); close FILE; } -lives_ok { +is( exception { Module::Refresh->new->refresh_module('TestBaz.pm') -} '... successfully refreshed ' . $test_module_file; +}, undef, '... successfully refreshed ' ); is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly'); ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well'); diff --git a/t/060_compat/003_foreign_inheritence.t b/t/060_compat/003_foreign_inheritence.t index 0fdcb9b..1279992 100644 --- a/t/060_compat/003_foreign_inheritence.t +++ b/t/060_compat/003_foreign_inheritence.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -79,14 +79,12 @@ is( $foo_moose->no_moose, 'Elk', is( $foo_moose->moose, 'Foo', '... got the right value from the Foo::Moose method' ); -lives_ok { +is( exception { Old::Bucket::Nose->meta->make_immutable( debug => 0 ); -} -'Immutability on Moose class extending Class::MOP class ok'; +}, undef, 'Immutability on Moose class extending Class::MOP class ok' ); -lives_ok { +is( exception { SubClass2->meta->superclasses('MyBase'); -} -'Can subclass the same non-Moose class twice with different metaclasses'; +}, undef, 'Can subclass the same non-Moose class twice with different metaclasses' ); done_testing; diff --git a/t/060_compat/004_extends_nonmoose_that_isa_moose_with_metarole.t b/t/060_compat/004_extends_nonmoose_that_isa_moose_with_metarole.t index 78fe330..8ec5dcb 100644 --- a/t/060_compat/004_extends_nonmoose_that_isa_moose_with_metarole.t +++ b/t/060_compat/004_extends_nonmoose_that_isa_moose_with_metarole.t @@ -22,11 +22,10 @@ use Class::MOP (); package SubSubClassUseBase; use Moose; use Test::More; - use Test::Exception; - lives_ok { + use Test::Fatal; + is( exception { extends 'SubClassUseBase'; - } - 'Can extend non-Moose class with parent class that is a Moose class with a meta role'; + }, undef, 'Can extend non-Moose class with parent class that is a Moose class with a meta role' ); } { @@ -54,11 +53,10 @@ Class::MOP::remove_metaclass_by_name('SubClassUseBase'); package MultiParent1; use Moose; use Test::More; - use Test::Exception; - lives_ok { + use Test::Fatal; + is( exception { extends qw( SubClassUseBase OtherSubClassUseBase ); - } - 'Can extend two non-Moose classes with parents that are different Moose metaclasses'; + }, undef, 'Can extend two non-Moose classes with parents that are different Moose metaclasses' ); } { @@ -74,11 +72,10 @@ Class::MOP::remove_metaclass_by_name($_) package MultiParent2; use Moose; use Test::More; - use Test::Exception; - lives_ok { + use Test::Fatal; + is( exception { extends qw( OtherSubClassUseBase SubClassUseBase ); - } - 'Can extend two non-Moose classes with parents that are different Moose metaclasses (reverse order)'; + }, undef, 'Can extend two non-Moose classes with parents that are different Moose metaclasses (reverse order)' ); } { @@ -94,11 +91,10 @@ Class::MOP::remove_metaclass_by_name($_) package MultiParent3; use Moose; use Test::More; - use Test::Exception; - lives_ok { + use Test::Fatal; + is( exception { extends qw( OtherClass SubClassUseBase ); - } - 'Can extend one Moose class and one non-Moose class'; + }, undef, 'Can extend one Moose class and one non-Moose class' ); } { @@ -114,11 +110,10 @@ Class::MOP::remove_metaclass_by_name($_) package MultiParent4; use Moose; use Test::More; - use Test::Exception; - lives_ok { + use Test::Fatal; + is( exception { extends qw( SubClassUseBase OtherClass ); - } - 'Can extend one non-Moose class and one Moose class'; + }, undef, 'Can extend one non-Moose class and one Moose class' ); } { @@ -134,11 +129,10 @@ Class::MOP::remove_metaclass_by_name($_) package MultiChild1; use Moose; use Test::More; - use Test::Exception; - lives_ok { + use Test::Fatal; + is( exception { extends 'MultiParent1'; - } - 'Can extend class that itself extends two non-Moose classes with Moose parents'; + }, undef, 'Can extend class that itself extends two non-Moose classes with Moose parents' ); } { @@ -154,11 +148,10 @@ Class::MOP::remove_metaclass_by_name($_) package MultiChild2; use Moose; use Test::More; - use Test::Exception; - lives_ok { + use Test::Fatal; + is( exception { extends 'MultiParent2'; - } - 'Can extend class that itself extends two non-Moose classes with Moose parents (reverse order)'; + }, undef, 'Can extend class that itself extends two non-Moose classes with Moose parents (reverse order)' ); } { @@ -174,11 +167,10 @@ Class::MOP::remove_metaclass_by_name($_) package MultiChild3; use Moose; use Test::More; - use Test::Exception; - lives_ok { + use Test::Fatal; + is( exception { extends 'MultiParent3'; - } - 'Can extend class that itself extends one Moose and one non-Moose parent'; + }, undef, 'Can extend class that itself extends one Moose and one non-Moose parent' ); } { @@ -194,11 +186,10 @@ Class::MOP::remove_metaclass_by_name($_) package MultiChild4; use Moose; use Test::More; - use Test::Exception; - lives_ok { + use Test::Fatal; + is( exception { extends 'MultiParent4'; - } - 'Can extend class that itself extends one non-Moose and one Moose parent'; + }, undef, 'Can extend class that itself extends one non-Moose and one Moose parent' ); } { diff --git a/t/060_compat/005_composite_metaroles.t b/t/060_compat/005_composite_metaroles.t index 570ce30..657362b 100755 --- a/t/060_compat/005_composite_metaroles.t +++ b/t/060_compat/005_composite_metaroles.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Test::Moose; { @@ -31,7 +31,7 @@ use Test::Moose; for => __PACKAGE__, class_metaroles => { class => ['Foo::Role', 'Bar::Role'] }, ); - ::lives_ok { extends 'Parent' }; + ::is( ::exception { extends 'Parent' }, undef ); } with_immutable { diff --git a/t/070_native_traits/010_trait_array.t b/t/070_native_traits/010_trait_array.t index 3f87d46..3785904 100644 --- a/t/070_native_traits/010_trait_array.t +++ b/t/070_native_traits/010_trait_array.t @@ -9,7 +9,7 @@ use Moose (); use Moose::Util::TypeConstraints; use NoInlineAttribute; use Test::More; -use Test::Exception; +use Test::Fatal; use Test::Moose; { @@ -137,28 +137,23 @@ sub run_tests { ok( !$obj->is_empty, 'values is not empty' ); is( $obj->count, 3, 'count returns 3' ); - throws_ok { $obj->count(22) } - qr/Cannot call count with any arguments/, - 'throws an error when passing an argument passed to count'; + like( exception { $obj->count(22) }, qr/Cannot call count with any arguments/, 'throws an error when passing an argument passed to count' ); - lives_ok { $obj->push( 1, 2, 3 ) } - 'pushed three new values and lived'; + is( exception { $obj->push( 1, 2, 3 ) }, undef, 'pushed three new values and lived' ); - lives_ok { $obj->push() } 'call to push without arguments lives'; + is( exception { $obj->push() }, undef, 'call to push without arguments lives' ); - lives_and { + is( exception { is( $obj->unshift( 101, 22 ), 8, 'unshift returns size of the new array' ); - } - 'unshifted two values and lived'; + }, undef, 'unshifted two values and lived' ); is_deeply( $obj->_values, [ 101, 22, 10, 12, 42, 1, 2, 3 ], 'unshift changed the value of the array in the object' ); - lives_ok { $obj->unshift() } - 'call to unshift without arguments lives'; + is( exception { $obj->unshift() }, undef, 'call to unshift without arguments lives' ); is( $obj->pop, 3, 'pop returns the last value in the array' ); @@ -167,15 +162,11 @@ sub run_tests { 'pop changed the value of the array in the object' ); - throws_ok { $obj->pop(42) } - qr/Cannot call pop with any arguments/, - 'call to pop with arguments dies'; + like( exception { $obj->pop(42) }, qr/Cannot call pop with any arguments/, 'call to pop with arguments dies' ); is( $obj->shift, 101, 'shift returns the first value' ); - throws_ok { $obj->shift(42) } - qr/Cannot call shift with any arguments/, - 'call to shift with arguments dies'; + like( exception { $obj->shift(42) }, qr/Cannot call shift with any arguments/, 'call to shift with arguments dies' ); is_deeply( $obj->_values, [ 22, 10, 12, 42, 1, 2 ], @@ -187,9 +178,7 @@ sub run_tests { 'call to elements returns values as a list' ); - throws_ok { $obj->elements(22) } - qr/Cannot call elements with any arguments/, - 'throws an error when passing an argument passed to elements'; + like( exception { $obj->elements(22) }, qr/Cannot call elements with any arguments/, 'throws an error when passing an argument passed to elements' ); $obj->_values( [ 1, 2, 3 ] ); @@ -198,120 +187,90 @@ sub run_tests { is( $obj->get(2), 3, 'get values at index 2' ); is( $obj->get_curried, 2, 'get_curried returns value at index 1' ); - throws_ok { $obj->get() } - qr/Cannot call get without at least 1 argument/, - 'throws an error when get is called without any arguments'; + like( exception { $obj->get() }, qr/Cannot call get without at least 1 argument/, 'throws an error when get is called without any arguments' ); - throws_ok { $obj->get( {} ) } - qr/The index passed to get must be an integer/, - 'throws an error when get is called with an invalid argument'; + like( exception { $obj->get( {} ) }, qr/The index passed to get must be an integer/, 'throws an error when get is called with an invalid argument' ); - throws_ok { $obj->get(2.2) } - qr/The index passed to get must be an integer/, - 'throws an error when get is called with an invalid argument'; + like( exception { $obj->get(2.2) }, qr/The index passed to get must be an integer/, 'throws an error when get is called with an invalid argument' ); - throws_ok { $obj->get('foo') } - qr/The index passed to get must be an integer/, - 'throws an error when get is called with an invalid argument'; + like( exception { $obj->get('foo') }, qr/The index passed to get must be an integer/, 'throws an error when get is called with an invalid argument' ); - throws_ok { $obj->get_curried(2) } - qr/Cannot call get with more than 1 argument/, - 'throws an error when get_curried is called with an argument'; + like( exception { $obj->get_curried(2) }, qr/Cannot call get with more than 1 argument/, 'throws an error when get_curried is called with an argument' ); - lives_and { + is( exception { is( $obj->set( 1, 100 ), 100, 'set returns new value' ); - } - 'set value at index 1 lives'; + }, undef, 'set value at index 1 lives' ); is( $obj->get(1), 100, 'get value at index 1 returns new value' ); - throws_ok { $obj->set( 1, 99, 42 ) } - qr/Cannot call set with more than 2 arguments/, - 'throws an error when set is called with three arguments'; + like( exception { $obj->set( 1, 99, 42 ) }, qr/Cannot call set with more than 2 arguments/, 'throws an error when set is called with three arguments' ); - lives_ok { $obj->set_curried_1(99) } 'set_curried_1 lives'; + is( exception { $obj->set_curried_1(99) }, undef, 'set_curried_1 lives' ); is( $obj->get(1), 99, 'get value at index 1 returns new value' ); - throws_ok { $obj->set_curried_1( 99, 42 ) } - qr/Cannot call set with more than 2 arguments/, - 'throws an error when set_curried_1 is called with two arguments'; + like( exception { $obj->set_curried_1( 99, 42 ) }, qr/Cannot call set with more than 2 arguments/, 'throws an error when set_curried_1 is called with two arguments' ); - lives_ok { $obj->set_curried_2 } 'set_curried_2 lives'; + is( exception { $obj->set_curried_2 }, undef, 'set_curried_2 lives' ); is( $obj->get(1), 98, 'get value at index 1 returns new value' ); - throws_ok { $obj->set_curried_2(42) } - qr/Cannot call set with more than 2 arguments/, - 'throws an error when set_curried_2 is called with one argument'; + like( exception { $obj->set_curried_2(42) }, qr/Cannot call set with more than 2 arguments/, 'throws an error when set_curried_2 is called with one argument' ); is( $obj->accessor(1), 98, 'accessor with one argument returns value at index 1' ); - lives_and { + is( exception { is( $obj->accessor( 1 => 97 ), 97, 'accessor returns new value' ); - } - 'accessor as writer lives'; + }, undef, 'accessor as writer lives' ); is( $obj->get(1), 97, 'accessor set value at index 1' ); - throws_ok { $obj->accessor( 1, 96, 42 ) } - qr/Cannot call accessor with more than 2 arguments/, - 'throws an error when accessor is called with three arguments'; + like( exception { $obj->accessor( 1, 96, 42 ) }, qr/Cannot call accessor with more than 2 arguments/, 'throws an error when accessor is called with three arguments' ); is( $obj->accessor_curried_1, 97, 'accessor_curried_1 returns expected value when called with no arguments' ); - lives_ok { $obj->accessor_curried_1(95) } - 'accessor_curried_1 as writer lives'; + is( exception { $obj->accessor_curried_1(95) }, undef, 'accessor_curried_1 as writer lives' ); is( $obj->get(1), 95, 'accessor_curried_1 set value at index 1' ); - throws_ok { $obj->accessor_curried_1( 96, 42 ) } - qr/Cannot call accessor with more than 2 arguments/, - 'throws an error when accessor_curried_1 is called with two arguments'; + like( exception { $obj->accessor_curried_1( 96, 42 ) }, qr/Cannot call accessor with more than 2 arguments/, 'throws an error when accessor_curried_1 is called with two arguments' ); - lives_ok { $obj->accessor_curried_2 } - 'accessor_curried_2 as writer lives'; + is( exception { $obj->accessor_curried_2 }, undef, 'accessor_curried_2 as writer lives' ); is( $obj->get(1), 90, 'accessor_curried_2 set value at index 1' ); - throws_ok { $obj->accessor_curried_2(42) } - qr/Cannot call accessor with more than 2 arguments/, - 'throws an error when accessor_curried_2 is called with one argument'; + like( exception { $obj->accessor_curried_2(42) }, qr/Cannot call accessor with more than 2 arguments/, 'throws an error when accessor_curried_2 is called with one argument' ); - lives_ok { $obj->clear } 'clear lives'; + is( exception { $obj->clear }, undef, 'clear lives' ); ok( $obj->is_empty, 'values is empty after call to clear' ); $obj->set( 0 => 42 ); - throws_ok { $obj->clear(50) } - qr/Cannot call clear with any arguments/, - 'throws an error when clear is called with an argument'; + like( exception { $obj->clear(50) }, qr/Cannot call clear with any arguments/, 'throws an error when clear is called with an argument' ); ok( !$obj->is_empty, 'values is not empty after failed call to clear' ); - throws_ok { $obj->is_empty(50) } - qr/Cannot call is_empty with any arguments/, - 'throws an error when is_empty is called with an argument'; + like( exception { $obj->is_empty(50) }, qr/Cannot call is_empty with any arguments/, 'throws an error when is_empty is called with an argument' ); $obj->clear; is( @@ -319,94 +278,80 @@ sub run_tests { 'pushed 4 elements, got number of elements in the array back' ); - lives_and { + is( exception { is( $obj->delete(2), 10, 'delete returns deleted value' ); - } - 'delete lives'; + }, undef, 'delete lives' ); is_deeply( $obj->_values, [ 1, 5, 42 ], 'delete removed the specified element' ); - throws_ok { $obj->delete( 2, 3 ) } - qr/Cannot call delete with more than 1 argument/, - 'throws an error when delete is called with two arguments'; + like( exception { $obj->delete( 2, 3 ) }, qr/Cannot call delete with more than 1 argument/, 'throws an error when delete is called with two arguments' ); - lives_ok { $obj->delete_curried } 'delete_curried lives'; + is( exception { $obj->delete_curried }, undef, 'delete_curried lives' ); is_deeply( $obj->_values, [ 1, 42 ], 'delete removed the specified element' ); - throws_ok { $obj->delete_curried(2) } - qr/Cannot call delete with more than 1 argument/, - 'throws an error when delete_curried is called with one argument'; + like( exception { $obj->delete_curried(2) }, qr/Cannot call delete with more than 1 argument/, 'throws an error when delete_curried is called with one argument' ); - lives_ok { $obj->insert( 1, 21 ) } 'insert lives'; + is( exception { $obj->insert( 1, 21 ) }, undef, 'insert lives' ); is_deeply( $obj->_values, [ 1, 21, 42 ], 'insert added the specified element' ); - throws_ok { $obj->insert( 1, 22, 44 ) } - qr/Cannot call insert with more than 2 arguments/, - 'throws an error when insert is called with three arguments'; + like( exception { $obj->insert( 1, 22, 44 ) }, qr/Cannot call insert with more than 2 arguments/, 'throws an error when insert is called with three arguments' ); - lives_and { + is( exception { is_deeply( [ $obj->splice( 1, 0, 2, 3 ) ], [], 'return value of splice is empty list when not removing elements' ); - } - 'splice lives'; + }, undef, 'splice lives' ); is_deeply( $obj->_values, [ 1, 2, 3, 21, 42 ], 'splice added the specified elements' ); - lives_and { + is( exception { is_deeply( [ $obj->splice( 1, 2, 99 ) ], [ 2, 3 ], 'splice returns list of removed values' ); - } - 'splice lives'; + }, undef, 'splice lives' ); is_deeply( $obj->_values, [ 1, 99, 21, 42 ], 'splice added the specified elements' ); - throws_ok { $obj->splice() } - qr/Cannot call splice without at least 1 argument/, - 'throws an error when splice is called with no arguments'; + like( exception { $obj->splice() }, qr/Cannot call splice without at least 1 argument/, 'throws an error when splice is called with no arguments' ); - throws_ok { $obj->splice( 1, 'foo', ) } - qr/The length argument passed to splice must be an integer/, - 'throws an error when splice is called with an invalid length'; + like( exception { $obj->splice( 1, 'foo', ) }, qr/The length argument passed to splice must be an integer/, 'throws an error when splice is called with an invalid length' ); - lives_ok { $obj->splice_curried_1( 2, 101 ) } - 'splice_curried_1 lives'; + is( exception { $obj->splice_curried_1( 2, 101 ) }, undef, 'splice_curried_1 lives' ); is_deeply( $obj->_values, [ 1, 101, 42 ], 'splice added the specified elements' ); - lives_ok { $obj->splice_curried_2(102) } 'splice_curried_2 lives'; + is( exception { $obj->splice_curried_2(102) }, undef, 'splice_curried_2 lives' ); is_deeply( $obj->_values, [ 1, 102 ], 'splice added the specified elements' ); - lives_ok { $obj->splice_curried_all } 'splice_curried_all lives'; + is( exception { $obj->splice_curried_all }, undef, 'splice_curried_all lives' ); is_deeply( $obj->_values, [ 1, 3, 4, 5 ], @@ -437,15 +382,11 @@ sub run_tests { 'sort returns values sorted by provided function' ); - throws_ok { $obj->sort(1) } - qr/The argument passed to sort must be a code reference/, - 'throws an error when passing a non coderef to sort'; + like( exception { $obj->sort(1) }, qr/The argument passed to sort must be a code reference/, 'throws an error when passing a non coderef to sort' ); - throws_ok { + like( exception { $obj->sort( sub { }, 27 ); - } - qr/Cannot call sort with more than 1 argument/, - 'throws an error when passing two arguments to sort'; + }, qr/Cannot call sort with more than 1 argument/, 'throws an error when passing two arguments to sort' ); $obj->_values( [ 3, 9, 5, 22, 11 ] ); @@ -463,17 +404,13 @@ sub run_tests { 'sort_in_place with function sorts values' ); - throws_ok { + like( exception { $obj->sort_in_place( 27 ); - } - qr/The argument passed to sort_in_place must be a code reference/, - 'throws an error when passing a non coderef to sort_in_place'; + }, qr/The argument passed to sort_in_place must be a code reference/, 'throws an error when passing a non coderef to sort_in_place' ); - throws_ok { + like( exception { $obj->sort_in_place( sub { }, 27 ); - } - qr/Cannot call sort_in_place with more than 1 argument/, - 'throws an error when passing two arguments to sort_in_place'; + }, qr/Cannot call sort_in_place with more than 1 argument/, 'throws an error when passing two arguments to sort_in_place' ); $obj->_values( [ 3, 9, 5, 22, 11 ] ); @@ -484,9 +421,7 @@ sub run_tests { 'sort_in_place_curried sorts values' ); - throws_ok { $obj->sort_in_place_curried(27) } - qr/Cannot call sort_in_place with more than 1 argument/, - 'throws an error when passing one argument passed to sort_in_place_curried'; + like( exception { $obj->sort_in_place_curried(27) }, qr/Cannot call sort_in_place with more than 1 argument/, 'throws an error when passing one argument passed to sort_in_place_curried' ); $obj->_values( [ 1 .. 5 ] ); @@ -496,19 +431,13 @@ sub run_tests { 'map returns the expected values' ); - throws_ok { $obj->map } - qr/Cannot call map without at least 1 argument/, - 'throws an error when passing no arguments to map'; + like( exception { $obj->map }, qr/Cannot call map without at least 1 argument/, 'throws an error when passing no arguments to map' ); - throws_ok { + like( exception { $obj->map( sub { }, 2 ); - } - qr/Cannot call map with more than 1 argument/, - 'throws an error when passing two arguments to map'; + }, qr/Cannot call map with more than 1 argument/, 'throws an error when passing two arguments to map' ); - throws_ok { $obj->map( {} ) } - qr/The argument passed to map must be a code reference/, - 'throws an error when passing a non coderef to map'; + like( exception { $obj->map( {} ) }, qr/The argument passed to map must be a code reference/, 'throws an error when passing a non coderef to map' ); $obj->_values( [ 1 .. 5 ] ); @@ -518,11 +447,9 @@ sub run_tests { 'map_curried returns the expected values' ); - throws_ok { + like( exception { $obj->map_curried( sub { } ); - } - qr/Cannot call map with more than 1 argument/, - 'throws an error when passing one argument passed to map_curried'; + }, qr/Cannot call map with more than 1 argument/, 'throws an error when passing one argument passed to map_curried' ); $obj->_values( [ 2 .. 9 ] ); @@ -532,19 +459,13 @@ sub run_tests { 'grep returns the expected values' ); - throws_ok { $obj->grep } - qr/Cannot call grep without at least 1 argument/, - 'throws an error when passing no arguments to grep'; + like( exception { $obj->grep }, qr/Cannot call grep without at least 1 argument/, 'throws an error when passing no arguments to grep' ); - throws_ok { + like( exception { $obj->grep( sub { }, 2 ); - } - qr/Cannot call grep with more than 1 argument/, - 'throws an error when passing two arguments to grep'; + }, qr/Cannot call grep with more than 1 argument/, 'throws an error when passing two arguments to grep' ); - throws_ok { $obj->grep( {} ) } - qr/The argument passed to grep must be a code reference/, - 'throws an error when passing a non coderef to grep'; + like( exception { $obj->grep( {} ) }, qr/The argument passed to grep must be a code reference/, 'throws an error when passing a non coderef to grep' ); my $overloader = Overloader->new( sub { $_ < 5 } ); is_deeply( @@ -559,11 +480,9 @@ sub run_tests { 'grep_curried returns the expected values' ); - throws_ok { + like( exception { $obj->grep_curried( sub { } ); - } - qr/Cannot call grep with more than 1 argument/, - 'throws an error when passing one argument passed to grep_curried'; + }, qr/Cannot call grep with more than 1 argument/, 'throws an error when passing one argument passed to grep_curried' ); $obj->_values( [ 2, 4, 22, 99, 101, 6 ] ); @@ -573,19 +492,13 @@ sub run_tests { 'first returns expected value' ); - throws_ok { $obj->first } - qr/Cannot call first without at least 1 argument/, - 'throws an error when passing no arguments to first'; + like( exception { $obj->first }, qr/Cannot call first without at least 1 argument/, 'throws an error when passing no arguments to first' ); - throws_ok { + like( exception { $obj->first( sub { }, 2 ); - } - qr/Cannot call first with more than 1 argument/, - 'throws an error when passing two arguments to first'; + }, qr/Cannot call first with more than 1 argument/, 'throws an error when passing two arguments to first' ); - throws_ok { $obj->first( {} ) } - qr/The argument passed to first must be a code reference/, - 'throws an error when passing a non coderef to first'; + like( exception { $obj->first( {} ) }, qr/The argument passed to first must be a code reference/, 'throws an error when passing a non coderef to first' ); is( $obj->first_curried, @@ -593,11 +506,9 @@ sub run_tests { 'first_curried returns expected value' ); - throws_ok { + like( exception { $obj->first_curried( sub { } ); - } - qr/Cannot call first with more than 1 argument/, - 'throws an error when passing one argument passed to first_curried'; + }, qr/Cannot call first with more than 1 argument/, 'throws an error when passing one argument passed to first_curried' ); $obj->_values( [ 1 .. 4 ] ); @@ -611,17 +522,11 @@ sub run_tests { 'join returns expected result when joining with empty string' ); - throws_ok { $obj->join } - qr/Cannot call join without at least 1 argument/, - 'throws an error when passing no arguments to join'; + like( exception { $obj->join }, qr/Cannot call join without at least 1 argument/, 'throws an error when passing no arguments to join' ); - throws_ok { $obj->join( '-', 2 ) } - qr/Cannot call join with more than 1 argument/, - 'throws an error when passing two arguments to join'; + like( exception { $obj->join( '-', 2 ) }, qr/Cannot call join with more than 1 argument/, 'throws an error when passing two arguments to join' ); - throws_ok { $obj->join( {} ) } - qr/The argument passed to join must be a string/, - 'throws an error when passing a non string to join'; + like( exception { $obj->join( {} ) }, qr/The argument passed to join must be a string/, 'throws an error when passing a non string to join' ); is_deeply( [ sort $obj->shuffle ], @@ -629,9 +534,7 @@ sub run_tests { 'shuffle returns all values (cannot check for a random order)' ); - throws_ok { $obj->shuffle(2) } - qr/Cannot call shuffle with any arguments/, - 'throws an error when passing an argument passed to shuffle'; + like( exception { $obj->shuffle(2) }, qr/Cannot call shuffle with any arguments/, 'throws an error when passing an argument passed to shuffle' ); $obj->_values( [ 1 .. 4, 2, 5, 3, 7, 3, 3, 1 ] ); @@ -641,9 +544,7 @@ sub run_tests { 'uniq returns expected values (in original order)' ); - throws_ok { $obj->uniq(2) } - qr/Cannot call uniq with any arguments/, - 'throws an error when passing an argument passed to uniq'; + like( exception { $obj->uniq(2) }, qr/Cannot call uniq with any arguments/, 'throws an error when passing an argument passed to uniq' ); $obj->_values( [ 1 .. 5 ] ); @@ -653,19 +554,13 @@ sub run_tests { 'reduce returns expected value' ); - throws_ok { $obj->reduce } - qr/Cannot call reduce without at least 1 argument/, - 'throws an error when passing no arguments to reduce'; + like( exception { $obj->reduce }, qr/Cannot call reduce without at least 1 argument/, 'throws an error when passing no arguments to reduce' ); - throws_ok { + like( exception { $obj->reduce( sub { }, 2 ); - } - qr/Cannot call reduce with more than 1 argument/, - 'throws an error when passing two arguments to reduce'; + }, qr/Cannot call reduce with more than 1 argument/, 'throws an error when passing two arguments to reduce' ); - throws_ok { $obj->reduce( {} ) } - qr/The argument passed to reduce must be a code reference/, - 'throws an error when passing a non coderef to reduce'; + like( exception { $obj->reduce( {} ) }, qr/The argument passed to reduce must be a code reference/, 'throws an error when passing a non coderef to reduce' ); is( $obj->reduce_curried, @@ -673,11 +568,9 @@ sub run_tests { 'reduce_curried returns expected value' ); - throws_ok { + like( exception { $obj->reduce_curried( sub { } ); - } - qr/Cannot call reduce with more than 1 argument/, - 'throws an error when passing one argument passed to reduce_curried'; + }, qr/Cannot call reduce with more than 1 argument/, 'throws an error when passing one argument passed to reduce_curried' ); $obj->_values( [ 1 .. 6 ] ); @@ -702,13 +595,9 @@ sub run_tests { 'natatime with function returns expected value' ); - throws_ok { $obj->natatime( {} ) } - qr/The n value passed to natatime must be an integer/, - 'throws an error when passing a non integer to natatime'; + like( exception { $obj->natatime( {} ) }, qr/The n value passed to natatime must be an integer/, 'throws an error when passing a non integer to natatime' ); - throws_ok { $obj->natatime( 2, {} ) } - qr/The second argument passed to natatime must be a code reference/, - 'throws an error when passing a non code ref to natatime'; + like( exception { $obj->natatime( 2, {} ) }, qr/The second argument passed to natatime must be a code reference/, 'throws an error when passing a non code ref to natatime' ); $it = $obj->natatime_curried(); @nat = (); @@ -731,9 +620,7 @@ sub run_tests { 'natatime_curried with function returns expected value' ); - throws_ok { $obj->natatime_curried( {} ) } - qr/The second argument passed to natatime must be a code reference/, - 'throws an error when passing a non code ref to natatime_curried'; + like( exception { $obj->natatime_curried( {} ) }, qr/The second argument passed to natatime must be a code reference/, 'throws an error when passing a non code ref to natatime_curried' ); if ( $class->meta->get_attribute('_values')->is_lazy ) { my $obj = $class->new; diff --git a/t/070_native_traits/011_array_subtypes.t b/t/070_native_traits/011_array_subtypes.t index 5daa36a..d78ac87 100644 --- a/t/070_native_traits/011_array_subtypes.t +++ b/t/070_native_traits/011_array_subtypes.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { use Moose::Util::TypeConstraints; @@ -75,8 +75,7 @@ my $foo = Foo->new; $foo->array_int( [] ); is_deeply( $foo->array_int, [], "array_int - correct contents" ); - dies_ok { $foo->push_array_int('foo') } - "array_int - can't push wrong type"; + isnt( exception { $foo->push_array_int('foo') }, undef, "array_int - can't push wrong type" ); is_deeply( $foo->array_int, [], "array_int - correct contents" ); $foo->push_array_int(1); @@ -84,12 +83,12 @@ my $foo = Foo->new; } { - dies_ok { $foo->push_a1('foo') } "a1 - can't push onto undef"; + isnt( exception { $foo->push_a1('foo') }, undef, "a1 - can't push onto undef" ); $foo->a1( [] ); is_deeply( $foo->a1, [], "a1 - correct contents" ); - dies_ok { $foo->push_a1('foo') } "a1 - can't push wrong type"; + isnt( exception { $foo->push_a1('foo') }, undef, "a1 - can't push wrong type" ); is_deeply( $foo->a1, [], "a1 - correct contents" ); @@ -98,7 +97,7 @@ my $foo = Foo->new; } { - dies_ok { $foo->push_a2('foo') } "a2 - can't push onto undef"; + isnt( exception { $foo->push_a2('foo') }, undef, "a2 - can't push onto undef" ); $foo->a2( [] ); is_deeply( $foo->a2, [], "a2 - correct contents" ); @@ -106,29 +105,27 @@ my $foo = Foo->new; $foo->push_a2('foo'); is_deeply( $foo->a2, ['foo'], "a2 - correct contents" ); - dies_ok { $foo->push_a2('bar') } "a2 - can't push more than one element"; + isnt( exception { $foo->push_a2('bar') }, undef, "a2 - can't push more than one element" ); is_deeply( $foo->a2, ['foo'], "a2 - correct contents" ); } { - dies_ok { $foo->push_a3(1) } "a3 - can't push onto undef"; + isnt( exception { $foo->push_a3(1) }, undef, "a3 - can't push onto undef" ); $foo->a3( [] ); is_deeply( $foo->a3, [], "a3 - correct contents" ); - dies_ok { $foo->push_a3('foo') } "a3 - can't push non-int"; + isnt( exception { $foo->push_a3('foo') }, undef, "a3 - can't push non-int" ); - dies_ok { $foo->push_a3(100) } - "a3 - can't violate overall type constraint"; + isnt( exception { $foo->push_a3(100) }, undef, "a3 - can't violate overall type constraint" ); is_deeply( $foo->a3, [], "a3 - correct contents" ); $foo->push_a3(1); is_deeply( $foo->a3, [1], "a3 - correct contents" ); - dies_ok { $foo->push_a3(100) } - "a3 - can't violate overall type constraint"; + isnt( exception { $foo->push_a3(100) }, undef, "a3 - can't violate overall type constraint" ); is_deeply( $foo->a3, [1], "a3 - correct contents" ); diff --git a/t/070_native_traits/013_array_coerce.t b/t/070_native_traits/013_array_coerce.t index 8145157..ef2f85f 100644 --- a/t/070_native_traits/013_array_coerce.t +++ b/t/070_native_traits/013_array_coerce.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { diff --git a/t/070_native_traits/020_trait_bool.t b/t/070_native_traits/020_trait_bool.t index 5443020..2541c68 100644 --- a/t/070_native_traits/020_trait_bool.t +++ b/t/070_native_traits/020_trait_bool.t @@ -9,7 +9,7 @@ use Moose (); use Moose::Util::TypeConstraints; use NoInlineAttribute; use Test::More; -use Test::Exception; +use Test::Fatal; use Test::Moose; { @@ -78,25 +78,19 @@ sub run_tests { ok( $obj->is_lit, 'set is_lit to 1 using ->illuminate' ); ok( !$obj->is_dark, 'check if is_dark does the right thing' ); - throws_ok { $obj->illuminate(1) } - qr/Cannot call set with any arguments/, - 'set throws an error when an argument is passed'; + like( exception { $obj->illuminate(1) }, qr/Cannot call set with any arguments/, 'set throws an error when an argument is passed' ); ok( !$obj->darken, 'unset returns false' ); ok( !$obj->is_lit, 'set is_lit to 0 using ->darken' ); ok( $obj->is_dark, 'check if is_dark does the right thing' ); - throws_ok { $obj->darken(1) } - qr/Cannot call unset with any arguments/, - 'unset throws an error when an argument is passed'; + like( exception { $obj->darken(1) }, qr/Cannot call unset with any arguments/, 'unset throws an error when an argument is passed' ); ok( $obj->flip_switch, 'toggle returns new value' ); ok( $obj->is_lit, 'toggle is_lit back to 1 using ->flip_switch' ); ok( !$obj->is_dark, 'check if is_dark does the right thing' ); - throws_ok { $obj->flip_switch(1) } - qr/Cannot call toggle with any arguments/, - 'toggle throws an error when an argument is passed'; + like( exception { $obj->flip_switch(1) }, qr/Cannot call toggle with any arguments/, 'toggle throws an error when an argument is passed' ); $obj->flip_switch; ok( !$obj->is_lit, diff --git a/t/070_native_traits/040_trait_counter.t b/t/070_native_traits/040_trait_counter.t index ae7e816..ad2e70d 100644 --- a/t/070_native_traits/040_trait_counter.t +++ b/t/070_native_traits/040_trait_counter.t @@ -8,7 +8,7 @@ use lib 't/lib'; use Moose (); use Moose::Util::TypeConstraints; use NoInlineAttribute; -use Test::Exception; +use Test::Fatal; use Test::More; use Test::Moose; @@ -85,30 +85,22 @@ sub run_tests { is( $obj->inc_counter, 2, 'inc returns new value' ); is( $obj->counter, 2, '... got the incremented value (again)' ); - throws_ok { $obj->inc_counter( 1, 2 ) } - qr/Cannot call inc with more than 1 argument/, - 'inc throws an error when two arguments are passed'; + like( exception { $obj->inc_counter( 1, 2 ) }, qr/Cannot call inc with more than 1 argument/, 'inc throws an error when two arguments are passed' ); is( $obj->dec_counter, 1, 'dec returns new value' ); is( $obj->counter, 1, '... got the decremented value' ); - throws_ok { $obj->dec_counter( 1, 2 ) } - qr/Cannot call dec with more than 1 argument/, - 'dec throws an error when two arguments are passed'; + like( exception { $obj->dec_counter( 1, 2 ) }, qr/Cannot call dec with more than 1 argument/, 'dec throws an error when two arguments are passed' ); is( $obj->reset_counter, 0, 'reset returns new value' ); is( $obj->counter, 0, '... got the original value' ); - throws_ok { $obj->reset_counter(2) } - qr/Cannot call reset with any arguments/, - 'reset throws an error when an argument is passed'; + like( exception { $obj->reset_counter(2) }, qr/Cannot call reset with any arguments/, 'reset throws an error when an argument is passed' ); is( $obj->set_counter(5), 5, 'set returns new value' ); is( $obj->counter, 5, '... set the value' ); - throws_ok { $obj->set_counter( 1, 2 ) } - qr/Cannot call set with more than 1 argument/, - 'set throws an error when two arguments are passed'; + like( exception { $obj->set_counter( 1, 2 ) }, qr/Cannot call set with more than 1 argument/, 'set throws an error when two arguments are passed' ); $obj->inc_counter(2); is( $obj->counter, 7, '... increment by arg' ); diff --git a/t/070_native_traits/050_trait_hash.t b/t/070_native_traits/050_trait_hash.t index e9ea77c..f39040b 100644 --- a/t/070_native_traits/050_trait_hash.t +++ b/t/070_native_traits/050_trait_hash.t @@ -8,7 +8,7 @@ use lib 't/lib'; use Moose (); use Moose::Util::TypeConstraints; use NoInlineAttribute; -use Test::Exception; +use Test::Fatal; use Test::More; use Test::Moose; @@ -88,14 +88,13 @@ sub run_tests { is_deeply( $obj->options, {}, '... no options yet' ); ok( !$obj->has_option('foo'), '... we have no foo option' ); - lives_and { + is( exception { is( $obj->set_option( foo => 'bar' ), 'bar', 'set return single new value in scalar context' ); - } - '... set the option okay'; + }, undef, '... set the option okay' ); ok( $obj->is_defined('foo'), '... foo is defined' ); @@ -104,10 +103,9 @@ sub run_tests { ok( $obj->has_option('foo'), '... we have a foo option' ); is_deeply( $obj->options, { foo => 'bar' }, '... got options now' ); - lives_ok { + is( exception { $obj->set_option( bar => 'baz' ); - } - '... set the option okay'; + }, undef, '... set the option okay' ); is( $obj->num_options, 2, '... we have 2 option(s)' ); is_deeply( @@ -127,10 +125,9 @@ sub run_tests { '... got last option in scalar context' ); - lives_ok { + is( exception { $obj->set_option( oink => "blah", xxy => "flop" ); - } - '... set the option okay'; + }, undef, '... set the option okay' ); is( $obj->num_options, 4, "4 options" ); is_deeply( @@ -138,20 +135,18 @@ sub run_tests { [qw(bar baz blah flop)], "get multiple options at once" ); - lives_and { + is( exception { is( scalar $obj->delete_option('bar'), 'baz', 'delete returns deleted value' ); - } - '... deleted the option okay'; + }, undef, '... deleted the option okay' ); - lives_ok { + is( exception { is_deeply( [ $obj->delete_option( 'oink', 'xxy' ) ], [ 'blah', 'flop' ], 'delete returns all deleted values in list context' ); - } - '... deleted multiple option okay'; + }, undef, '... deleted multiple option okay' ); is( $obj->num_options, 1, '... we have 1 option(s)' ); is_deeply( @@ -163,10 +158,9 @@ sub run_tests { is_deeply( $obj->options, {}, "... cleared options" ); - lives_ok { + is( exception { $obj->quantity(4); - } - '... options added okay with defaults'; + }, undef, '... options added okay with defaults' ); is( $obj->quantity, 4, 'reader part of curried accessor works' ); @@ -175,20 +169,17 @@ sub run_tests { '... returns what we expect' ); - lives_ok { + is( exception { $class->new( options => { foo => 'BAR' } ); - } - '... good constructor params'; + }, undef, '... good constructor params' ); - dies_ok { + isnt( exception { $obj->set_option( bar => {} ); - } - '... could not add a hash ref where an string is expected'; + }, undef, '... could not add a hash ref where an string is expected' ); - dies_ok { + isnt( exception { $class->new( options => { foo => [] } ); - } - '... bad constructor params'; + }, undef, '... bad constructor params' ); is_deeply( [ $obj->set_option( oink => "blah", xxy => "flop" ) ], diff --git a/t/070_native_traits/051_hash_subtypes.t b/t/070_native_traits/051_hash_subtypes.t index 8949a92..dfdbb63 100644 --- a/t/070_native_traits/051_hash_subtypes.t +++ b/t/070_native_traits/051_hash_subtypes.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { use Moose::Util::TypeConstraints; @@ -66,8 +66,7 @@ my $foo = Foo->new; $foo->hash_int( {} ); is_deeply( $foo->hash_int, {}, "hash_int - correct contents" ); - dies_ok { $foo->set_hash_int( x => 'foo' ) } - "hash_int - can't set wrong type"; + isnt( exception { $foo->set_hash_int( x => 'foo' ) }, undef, "hash_int - can't set wrong type" ); is_deeply( $foo->hash_int, {}, "hash_int - correct contents" ); $foo->set_hash_int( x => 1 ); @@ -75,12 +74,12 @@ my $foo = Foo->new; } { - dies_ok { $foo->set_h1('foo') } "h1 - can't set onto undef"; + isnt( exception { $foo->set_h1('foo') }, undef, "h1 - can't set onto undef" ); $foo->h1( {} ); is_deeply( $foo->h1, {}, "h1 - correct contents" ); - dies_ok { $foo->set_h1( x => 'foo' ) } "h1 - can't set wrong type"; + isnt( exception { $foo->set_h1( x => 'foo' ) }, undef, "h1 - can't set wrong type" ); is_deeply( $foo->h1, {}, "h1 - correct contents" ); @@ -89,7 +88,7 @@ my $foo = Foo->new; } { - dies_ok { $foo->set_h2('foo') } "h2 - can't set onto undef"; + isnt( exception { $foo->set_h2('foo') }, undef, "h2 - can't set onto undef" ); $foo->h2( {} ); is_deeply( $foo->h2, {}, "h2 - correct contents" ); @@ -97,30 +96,27 @@ my $foo = Foo->new; $foo->set_h2( x => 'foo' ); is_deeply( $foo->h2, { x => 'foo' }, "h2 - correct contents" ); - dies_ok { $foo->set_h2( y => 'bar' ) } - "h2 - can't set more than one element"; + isnt( exception { $foo->set_h2( y => 'bar' ) }, undef, "h2 - can't set more than one element" ); is_deeply( $foo->h2, { x => 'foo' }, "h2 - correct contents" ); } { - dies_ok { $foo->set_h3(1) } "h3 - can't set onto undef"; + isnt( exception { $foo->set_h3(1) }, undef, "h3 - can't set onto undef" ); $foo->h3( {} ); is_deeply( $foo->h3, {}, "h3 - correct contents" ); - dies_ok { $foo->set_h3( x => 'foo' ) } "h3 - can't set non-int"; + isnt( exception { $foo->set_h3( x => 'foo' ) }, undef, "h3 - can't set non-int" ); - dies_ok { $foo->set_h3( x => 100 ) } - "h3 - can't violate overall type constraint"; + isnt( exception { $foo->set_h3( x => 100 ) }, undef, "h3 - can't violate overall type constraint" ); is_deeply( $foo->h3, {}, "h3 - correct contents" ); $foo->set_h3( x => 1 ); is_deeply( $foo->h3, { x => 1 }, "h3 - correct contents" ); - dies_ok { $foo->set_h3( x => 100 ) } - "h3 - can't violate overall type constraint"; + isnt( exception { $foo->set_h3( x => 100 ) }, undef, "h3 - can't violate overall type constraint" ); is_deeply( $foo->h3, { x => 1 }, "h3 - correct contents" ); diff --git a/t/070_native_traits/060_trait_number.t b/t/070_native_traits/060_trait_number.t index 6b24631..acf4551 100644 --- a/t/070_native_traits/060_trait_number.t +++ b/t/070_native_traits/060_trait_number.t @@ -8,7 +8,7 @@ use lib 't/lib'; use Moose (); use Moose::Util::TypeConstraints; use NoInlineAttribute; -use Test::Exception; +use Test::Fatal; use Test::More; use Test::Moose; @@ -87,49 +87,37 @@ sub run_tests { is( $obj->integer, 15, 'Add ten for fithteen' ); - throws_ok { $obj->add( 10, 2 ) } - qr/Cannot call add with more than 1 argument/, - 'add throws an error when 2 arguments are passed'; + like( exception { $obj->add( 10, 2 ) }, qr/Cannot call add with more than 1 argument/, 'add throws an error when 2 arguments are passed' ); is( $obj->sub(3), 12, 'sub returns new value' ); is( $obj->integer, 12, 'Subtract three for 12' ); - throws_ok { $obj->sub( 10, 2 ) } - qr/Cannot call sub with more than 1 argument/, - 'sub throws an error when 2 arguments are passed'; + like( exception { $obj->sub( 10, 2 ) }, qr/Cannot call sub with more than 1 argument/, 'sub throws an error when 2 arguments are passed' ); is( $obj->set(10), 10, 'set returns new value' ); is( $obj->integer, 10, 'Set to ten' ); - throws_ok { $obj->set( 10, 2 ) } - qr/Cannot call set with more than 1 argument/, - 'set throws an error when 2 arguments are passed'; + like( exception { $obj->set( 10, 2 ) }, qr/Cannot call set with more than 1 argument/, 'set throws an error when 2 arguments are passed' ); is( $obj->div(2), 5, 'div returns new value' ); is( $obj->integer, 5, 'divide by 2' ); - throws_ok { $obj->div( 10, 2 ) } - qr/Cannot call div with more than 1 argument/, - 'div throws an error when 2 arguments are passed'; + like( exception { $obj->div( 10, 2 ) }, qr/Cannot call div with more than 1 argument/, 'div throws an error when 2 arguments are passed' ); is( $obj->mul(2), 10, 'mul returns new value' ); is( $obj->integer, 10, 'multiplied by 2' ); - throws_ok { $obj->mul( 10, 2 ) } - qr/Cannot call mul with more than 1 argument/, - 'mul throws an error when 2 arguments are passed'; + like( exception { $obj->mul( 10, 2 ) }, qr/Cannot call mul with more than 1 argument/, 'mul throws an error when 2 arguments are passed' ); is( $obj->mod(2), 0, 'mod returns new value' ); is( $obj->integer, 0, 'Mod by 2' ); - throws_ok { $obj->mod( 10, 2 ) } - qr/Cannot call mod with more than 1 argument/, - 'mod throws an error when 2 arguments are passed'; + like( exception { $obj->mod( 10, 2 ) }, qr/Cannot call mod with more than 1 argument/, 'mod throws an error when 2 arguments are passed' ); $obj->set(7); @@ -141,9 +129,7 @@ sub run_tests { is( $obj->abs, 1, 'abs returns new value' ); - throws_ok { $obj->abs(10) } - qr/Cannot call abs with any arguments/, - 'abs throws an error when an argument is passed'; + like( exception { $obj->abs(10) }, qr/Cannot call abs with any arguments/, 'abs throws an error when an argument is passed' ); is( $obj->integer, 1, 'abs 1' ); diff --git a/t/070_native_traits/070_trait_string.t b/t/070_native_traits/070_trait_string.t index c6b9c63..cef148d 100644 --- a/t/070_native_traits/070_trait_string.t +++ b/t/070_native_traits/070_trait_string.t @@ -9,7 +9,7 @@ use Moose (); use Moose::Util::TypeConstraints; use NoInlineAttribute; use Test::More; -use Test::Exception; +use Test::Fatal; use Test::Moose; { @@ -92,30 +92,22 @@ sub run_tests { $obj->_string('a'); is( $obj->length, 1, 'length returns 1 for new string' ); - throws_ok { $obj->length(42) } - qr/Cannot call length with any arguments/, - 'length throws an error when an argument is passed'; + like( exception { $obj->length(42) }, qr/Cannot call length with any arguments/, 'length throws an error when an argument is passed' ); is( $obj->inc, 'b', 'inc returns new value' ); is( $obj->_string, 'b', 'a becomes b after inc' ); - throws_ok { $obj->inc(42) } - qr/Cannot call inc with any arguments/, - 'inc throws an error when an argument is passed'; + like( exception { $obj->inc(42) }, qr/Cannot call inc with any arguments/, 'inc throws an error when an argument is passed' ); is( $obj->append('foo'), 'bfoo', 'append returns new value' ); is( $obj->_string, 'bfoo', 'appended to the string' ); - throws_ok { $obj->append( 'foo', 2 ) } - qr/Cannot call append with more than 1 argument/, - 'append throws an error when two arguments are passed'; + like( exception { $obj->append( 'foo', 2 ) }, qr/Cannot call append with more than 1 argument/, 'append throws an error when two arguments are passed' ); $obj->append_curried; is( $obj->_string, 'bfoo!', 'append_curried appended to the string' ); - throws_ok { $obj->append_curried('foo') } - qr/Cannot call append with more than 1 argument/, - 'append_curried throws an error when two arguments are passed'; + like( exception { $obj->append_curried('foo') }, qr/Cannot call append with more than 1 argument/, 'append_curried throws an error when two arguments are passed' ); $obj->_string("has nl$/"); is( $obj->chomp, 1, 'chomp returns number of characters removed' ); @@ -127,16 +119,12 @@ sub run_tests { 'chomp is a no-op when string has no line ending' ); - throws_ok { $obj->chomp(42) } - qr/Cannot call chomp with any arguments/, - 'chomp throws an error when an argument is passed'; + like( exception { $obj->chomp(42) }, qr/Cannot call chomp with any arguments/, 'chomp throws an error when an argument is passed' ); is( $obj->chop, 'l', 'chop returns character removed' ); is( $obj->_string, 'has n', 'chopped string' ); - throws_ok { $obj->chop(42) } - qr/Cannot call chop with any arguments/, - 'chop throws an error when an argument is passed'; + like( exception { $obj->chop(42) }, qr/Cannot call chop with any arguments/, 'chop throws an error when an argument is passed' ); $obj->_string('x'); is( $obj->prepend('bar'), 'barx', 'prepend returns new value' ); @@ -173,13 +161,9 @@ sub run_tests { is( $obj->_string, 'af', 'replace accepts an empty string as first argument' ); - throws_ok { $obj->replace( {}, 'x' ) } - qr/The first argument passed to replace must be a string or regexp reference/, - 'replace throws an error when the first argument is not a string or regexp'; + like( exception { $obj->replace( {}, 'x' ) }, qr/The first argument passed to replace must be a string or regexp reference/, 'replace throws an error when the first argument is not a string or regexp' ); - throws_ok { $obj->replace( qr/x/, {} ) } - qr/The second argument passed to replace must be a string or code reference/, - 'replace throws an error when the first argument is not a string or regexp'; + like( exception { $obj->replace( qr/x/, {} ) }, qr/The second argument passed to replace must be a string or code reference/, 'replace throws an error when the first argument is not a string or regexp' ); $obj->_string('Moosex'); $obj->replace_curried; @@ -207,13 +191,9 @@ sub run_tests { 'match with empty string as argument returns true' ); - throws_ok { $obj->match } - qr/Cannot call match without at least 1 argument/, - 'match throws an error when no arguments are passed'; + like( exception { $obj->match }, qr/Cannot call match without at least 1 argument/, 'match throws an error when no arguments are passed' ); - throws_ok { $obj->match( {} ) } - qr/The argument passed to match must be a string or regexp reference/, - 'match throws an error when an invalid argument is passed'; + like( exception { $obj->match( {} ) }, qr/The argument passed to match must be a string or regexp reference/, 'match throws an error when an invalid argument is passed' ); $obj->_string('1234'); ok( !$obj->match_curried, 'match_curried returns false' ); @@ -224,9 +204,7 @@ sub run_tests { $obj->clear; is( $obj->_string, q{}, 'clear' ); - throws_ok { $obj->clear(42) } - qr/Cannot call clear with any arguments/, - 'clear throws an error when an argument is passed'; + like( exception { $obj->clear(42) }, qr/Cannot call clear with any arguments/, 'clear throws an error when an argument is passed' ); $obj->_string('some long string'); is( @@ -258,25 +236,15 @@ sub run_tests { 'substr as setter with three arguments, replacment is empty string' ); - throws_ok { $obj->substr } - qr/Cannot call substr without at least 1 argument/, - 'substr throws an error when no argumemts are passed'; + like( exception { $obj->substr }, qr/Cannot call substr without at least 1 argument/, 'substr throws an error when no argumemts are passed' ); - throws_ok { $obj->substr( 1, 2, 3, 4 ) } - qr/Cannot call substr with more than 3 arguments/, - 'substr throws an error when four argumemts are passed'; + like( exception { $obj->substr( 1, 2, 3, 4 ) }, qr/Cannot call substr with more than 3 arguments/, 'substr throws an error when four argumemts are passed' ); - throws_ok { $obj->substr( {} ) } - qr/The first argument passed to substr must be an integer/, - 'substr throws an error when first argument is not an integer'; + like( exception { $obj->substr( {} ) }, qr/The first argument passed to substr must be an integer/, 'substr throws an error when first argument is not an integer' ); - throws_ok { $obj->substr( 1, {} ) } - qr/The second argument passed to substr must be an integer/, - 'substr throws an error when second argument is not an integer'; + like( exception { $obj->substr( 1, {} ) }, qr/The second argument passed to substr must be an integer/, 'substr throws an error when second argument is not an integer' ); - throws_ok { $obj->substr( 1, 2, {} ) } - qr/The third argument passed to substr must be a string/, - 'substr throws an error when third argument is not a string'; + like( exception { $obj->substr( 1, 2, {} ) }, qr/The third argument passed to substr must be a string/, 'substr throws an error when third argument is not a string' ); $obj->_string('some long string'); diff --git a/t/070_native_traits/100_array_from_role.t b/t/070_native_traits/100_array_from_role.t index 7f76c1a..205b8ef 100644 --- a/t/070_native_traits/100_array_from_role.t +++ b/t/070_native_traits/100_array_from_role.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { package Foo; @@ -36,11 +36,11 @@ use Test::Exception; package Stuff; use Moose; - ::lives_ok{ with 'Stuffed::Role'; - } '... this should work correctly'; + ::is( ::exception { with 'Stuffed::Role'; + }, undef, '... this should work correctly' ); - ::lives_ok{ with 'Bulkie::Role'; - } '... this should work correctly'; + ::is( ::exception { with 'Bulkie::Role'; + }, undef, '... this should work correctly' ); } done_testing; diff --git a/t/070_native_traits/101_remove_attribute.t b/t/070_native_traits/101_remove_attribute.t index 5e9305d..1551193 100644 --- a/t/070_native_traits/101_remove_attribute.t +++ b/t/070_native_traits/101_remove_attribute.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { package MyHomePage; @@ -33,10 +33,9 @@ can_ok( $page, $_ ) for qw[ reset_counter ]; -lives_ok { +is( exception { $page->meta->remove_attribute('counter'); -} -'... removed the counter attribute okay'; +}, undef, '... removed the counter attribute okay' ); ok( !$page->meta->has_attribute('counter'), '... no longer has the attribute' ); diff --git a/t/070_native_traits/103_custom_instance.t b/t/070_native_traits/103_custom_instance.t index 2830d83..62087b9 100644 --- a/t/070_native_traits/103_custom_instance.t +++ b/t/070_native_traits/103_custom_instance.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Test::Moose; { @@ -55,7 +55,7 @@ use Test::Moose; } ); - ::lives_ok { + ::is( ::exception { has array => ( traits => ['Array'], isa => 'ArrayRef', @@ -110,9 +110,9 @@ use Test::Moose; array_natatime_curried => [ natatime => 2 ], }, ); - } "native array trait inlines properly"; + }, undef, "native array trait inlines properly" ); - ::lives_ok { + ::is( ::exception { has bool => ( traits => ['Bool'], isa => 'Bool', @@ -124,9 +124,9 @@ use Test::Moose; bool_is_dark => 'not', }, ); - } "native bool trait inlines properly"; + }, undef, "native bool trait inlines properly" ); - ::lives_ok { + ::is( ::exception { has code => ( traits => ['Code'], isa => 'CodeRef', @@ -136,9 +136,9 @@ use Test::Moose; code_execute_method => 'execute_method', }, ); - } "native code trait inlines properly"; + }, undef, "native code trait inlines properly" ); - ::lives_ok { + ::is( ::exception { has counter => ( traits => ['Counter'], isa => 'Int', @@ -153,9 +153,9 @@ use Test::Moose; set_counter_42 => [ set => 42 ], }, ); - } "native counter trait inlines properly"; + }, undef, "native counter trait inlines properly" ); - ::lives_ok { + ::is( ::exception { has hash => ( traits => ['Hash'], isa => 'HashRef', @@ -175,9 +175,9 @@ use Test::Moose; hash_set_option => 'set', }, ); - } "native hash trait inlines properly"; + }, undef, "native hash trait inlines properly" ); - ::lives_ok { + ::is( ::exception { has number => ( traits => ['Number'], isa => 'Num', @@ -196,9 +196,9 @@ use Test::Moose; num_dec => [ sub => 1 ], }, ); - } "native number trait inlines properly"; + }, undef, "native number trait inlines properly" ); - ::lives_ok { + ::is( ::exception { has string => ( traits => ['String'], is => 'ro', @@ -224,7 +224,7 @@ use Test::Moose; string_substr_curried_3 => [ substr => ( 1, 3, 'ong' ) ], }, ); - } "native string trait inlines properly"; + }, undef, "native string trait inlines properly" ); } with_immutable { diff --git a/t/100_bugs/005_inline_reader_bug.t b/t/100_bugs/005_inline_reader_bug.t index b85925d..7500dcd 100644 --- a/t/100_bugs/005_inline_reader_bug.t +++ b/t/100_bugs/005_inline_reader_bug.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; =pod @@ -18,14 +18,14 @@ test makes sure it does not creep back in. package Foo; use Moose; - ::lives_ok { + ::is( ::exception { has 'bar' => ( is => 'ro', isa => 'Int', lazy => 1, default => 10, ); - } '... this didnt die'; + }, undef, '... this didnt die' ); } done_testing; diff --git a/t/100_bugs/006_handles_foreign_class_bug.t b/t/100_bugs/006_handles_foreign_class_bug.t index 82bad20..0a550fe 100644 --- a/t/100_bugs/006_handles_foreign_class_bug.t +++ b/t/100_bugs/006_handles_foreign_class_bug.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { package Foo; @@ -20,7 +20,7 @@ use Test::Exception; package Bar; use Moose; - ::lives_ok { + ::is( ::exception { has 'baz' => ( is => 'ro', isa => 'Foo', @@ -28,14 +28,14 @@ use Test::Exception; default => sub { Foo->new() }, handles => qr/^a$/, ); - } '... can create the attribute with delegations'; + }, undef, '... can create the attribute with delegations' ); } my $bar; -lives_ok { +is( exception { $bar = Bar->new; -} '... created the object ok'; +}, undef, '... created the object ok' ); isa_ok($bar, 'Bar'); is($bar->a, 'Foo::a', '... got the right delgated value'); @@ -46,7 +46,7 @@ $SIG{__WARN__} = sub { push @w, "@_" }; package Baz; use Moose; - ::lives_ok { + ::is( ::exception { has 'bar' => ( is => 'ro', isa => 'Foo', @@ -54,7 +54,7 @@ $SIG{__WARN__} = sub { push @w, "@_" }; default => sub { Foo->new() }, handles => qr/.*/, ); - } '... can create the attribute with delegations'; + }, undef, '... can create the attribute with delegations' ); } @@ -62,9 +62,9 @@ is(@w, 0, "no warnings"); my $baz; -lives_ok { +is( exception { $baz = Baz->new; -} '... created the object ok'; +}, undef, '... created the object ok' ); isa_ok($baz, 'Baz'); is($baz->a, 'Foo::a', '... got the right delgated value'); @@ -79,7 +79,7 @@ is($baz->a, 'Foo::a', '... got the right delgated value'); package Blart; use Moose; - ::lives_ok { + ::is( ::exception { has 'bar' => ( is => 'ro', isa => 'Foo', @@ -87,7 +87,7 @@ is($baz->a, 'Foo::a', '... got the right delgated value'); default => sub { Foo->new() }, handles => [qw(a new)], ); - } '... can create the attribute with delegations'; + }, undef, '... can create the attribute with delegations' ); } @@ -101,9 +101,9 @@ is($baz->a, 'Foo::a', '... got the right delgated value'); my $blart; -lives_ok { +is( exception { $blart = Blart->new; -} '... created the object ok'; +}, undef, '... created the object ok' ); isa_ok($blart, 'Blart'); is($blart->a, 'Foo::a', '... got the right delgated value'); diff --git a/t/100_bugs/012_DEMOLISH_eats_mini.t b/t/100_bugs/012_DEMOLISH_eats_mini.t index 953e019..3e1caf6 100644 --- a/t/100_bugs/012_DEMOLISH_eats_mini.t +++ b/t/100_bugs/012_DEMOLISH_eats_mini.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { diff --git a/t/100_bugs/016_inheriting_from_roles.t b/t/100_bugs/016_inheriting_from_roles.t index c001dbb..8d84c7c 100644 --- a/t/100_bugs/016_inheriting_from_roles.t +++ b/t/100_bugs/016_inheriting_from_roles.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -15,10 +15,9 @@ use Test::Exception; package My::Class; use Moose; - ::throws_ok { + ::like( ::exception { extends 'My::Role'; - } qr/You cannot inherit from a Moose Role \(My\:\:Role\)/, - '... this croaks correctly'; + }, qr/You cannot inherit from a Moose Role \(My\:\:Role\)/, '... this croaks correctly' ); } done_testing; diff --git a/t/100_bugs/017_type_constraint_messages.t b/t/100_bugs/017_type_constraint_messages.t index 526130d..e6e5a19 100644 --- a/t/100_bugs/017_type_constraint_messages.t +++ b/t/100_bugs/017_type_constraint_messages.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; # RT #37569 @@ -52,22 +52,16 @@ use Test::Exception; my $foo = Foo->new; my $obj = MyObject->new; -throws_ok { +like( exception { $foo->ar( [] ); -} -qr/Attribute \(ar\) does not pass the type constraint because: ref: ARRAY/, - '... got the right error message'; +}, qr/Attribute \(ar\) does not pass the type constraint because: ref: ARRAY/, '... got the right error message' ); -throws_ok { +like( exception { $foo->obj($foo); # Doh! -} -qr/Attribute \(obj\) does not pass the type constraint because: Well it is an object/, - '... got the right error message'; +}, qr/Attribute \(obj\) does not pass the type constraint because: Well it is an object/, '... got the right error message' ); -throws_ok { +like( exception { $foo->nt($foo); # scalar -} -qr/Attribute \(nt\) does not pass the type constraint because: blessed/, - '... got the right error message'; +}, qr/Attribute \(nt\) does not pass the type constraint because: blessed/, '... got the right error message' ); done_testing; diff --git a/t/100_bugs/018_immutable_metaclass_does_role.t b/t/100_bugs/018_immutable_metaclass_does_role.t index 9a99477..15cf8c0 100644 --- a/t/100_bugs/018_immutable_metaclass_does_role.t +++ b/t/100_bugs/018_immutable_metaclass_does_role.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; BEGIN { @@ -41,9 +41,9 @@ is( $a->meta->foo, 'i am foo', '... foo method returns expected value' ); ok( MyClass->meta->meta->does_role('MyRole'), 'metaclass does MyRole' ); is( MyClass->meta->foo, 'i am foo', '... foo method returns expected value' ); -lives_ok { +is( exception { MyClass->meta->make_immutable; -} '... make MyClass immutable okay'; +}, undef, '... make MyClass immutable okay' ); is(MyClass->meta, $mc, '... these metas are still the same thing'); is(MyClass->meta->meta, $mc->meta, '... these meta-metas are the same thing'); @@ -53,9 +53,9 @@ is( $a->meta->foo, 'i am foo', '... foo method returns expected value' ); ok( MyClass->meta->meta->does_role('MyRole'), 'metaclass does MyRole' ); is( MyClass->meta->foo, 'i am foo', '... foo method returns expected value' ); -lives_ok { +is( exception { MyClass->meta->make_mutable; -} '... make MyClass mutable okay'; +}, undef, '... make MyClass mutable okay' ); is(MyClass->meta, $mc, '... these metas are still the same thing'); is(MyClass->meta->meta, $mc->meta, '... these meta-metas are the same thing'); @@ -65,9 +65,9 @@ is( $a->meta->foo, 'i am foo', '... foo method returns expected value' ); ok( MyClass->meta->meta->does_role('MyRole'), 'metaclass does MyRole' ); is( MyClass->meta->foo, 'i am foo', '... foo method returns expected value' ); -lives_ok { +is( exception { MyMetaclass->meta->make_immutable; -} '... make MyMetaclass immutable okay'; +}, undef, '... make MyMetaclass immutable okay' ); is(MyClass->meta, $mc, '... these metas are still the same thing'); is(MyClass->meta->meta, $mc->meta, '... these meta-metas are the same thing'); @@ -77,9 +77,9 @@ is( $a->meta->foo, 'i am foo', '... foo method returns expected value' ); ok( MyClass->meta->meta->does_role('MyRole'), 'metaclass does MyRole' ); is( MyClass->meta->foo, 'i am foo', '... foo method returns expected value' ); -lives_ok { +is( exception { MyClass->meta->make_immutable; -} '... make MyClass immutable (again) okay'; +}, undef, '... make MyClass immutable (again) okay' ); is(MyClass->meta, $mc, '... these metas are still the same thing'); is(MyClass->meta->meta, $mc->meta, '... these meta-metas are the same thing'); diff --git a/t/100_bugs/023_DEMOLISH_fails_without_metaclass.t b/t/100_bugs/023_DEMOLISH_fails_without_metaclass.t index a061244..b0b0cf4 100644 --- a/t/100_bugs/023_DEMOLISH_fails_without_metaclass.t +++ b/t/100_bugs/023_DEMOLISH_fails_without_metaclass.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { package MyClass; @@ -21,8 +21,7 @@ Class::MOP::remove_metaclass_by_name('MyClass'); # The bug happened when DEMOLISHALL called # Class::MOP::class_of($object) and did not get a metaclass object # back. -lives_ok { $object->DESTROY } -'can call DESTROY on an object without a metaclass object in the CMOP cache'; +is( exception { $object->DESTROY }, undef, 'can call DESTROY on an object without a metaclass object in the CMOP cache' ); MyClass->meta->make_immutable; @@ -30,7 +29,6 @@ Class::MOP::remove_metaclass_by_name('MyClass'); # The bug didn't manifest for immutable objects, but this test should # help us prevent it happening in the future. -lives_ok { $object->DESTROY } -'can call DESTROY on an object without a metaclass object in the CMOP cache (immutable version)'; +is( exception { $object->DESTROY }, undef, 'can call DESTROY on an object without a metaclass object in the CMOP cache (immutable version)' ); done_testing; diff --git a/t/100_bugs/025_universal_methods_wrappable.t b/t/100_bugs/025_universal_methods_wrappable.t index 8eea71a..1d4a1cf 100644 --- a/t/100_bugs/025_universal_methods_wrappable.t +++ b/t/100_bugs/025_universal_methods_wrappable.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::Exception; +use Test::Fatal; use Test::More; { @@ -22,7 +22,7 @@ use Test::More; local $TODO = 'UNIVERSAL methods should be wrappable'; - ::lives_ok { with 'FakeBar' } 'applied role'; + ::is( ::exception { with 'FakeBar' }, undef, 'applied role' ); my $foo = Foo->new; ::isa_ok $foo, 'Bar'; diff --git a/t/100_bugs/026_create_anon_recursion.t b/t/100_bugs/026_create_anon_recursion.t index 1756795..1957381 100644 --- a/t/100_bugs/026_create_anon_recursion.t +++ b/t/100_bugs/026_create_anon_recursion.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Meta::Class; @@ -14,12 +14,11 @@ TODO: = 'Loading Moose::Meta::Class without loading Moose.pm causes weird problems'; my $meta; - lives_ok { + is( exception { $meta = Moose::Meta::Class->create_anon_class( superclasses => [ 'Moose::Object', ], ); - } - 'Class is created successfully'; + }, undef, 'Class is created successfully' ); } done_testing; diff --git a/t/100_bugs/028_apply_role_to_one_instance_only.t b/t/100_bugs/028_apply_role_to_one_instance_only.t index be31007..e484ca1 100644 --- a/t/100_bugs/028_apply_role_to_one_instance_only.t +++ b/t/100_bugs/028_apply_role_to_one_instance_only.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { package MyRole1; @@ -37,8 +37,8 @@ ok ((not $instance_with_role2->can('a_role_method')), ok (($instance_with_role1->does('MyRole1')), 'role was applied to the correct instance'); -lives_and { +is( exception { is $instance_with_role1->a_role_method, 'foo' -} 'instance has correct role method'; +}, undef, 'instance has correct role method' ); done_testing; diff --git a/t/100_bugs/030_coerce_without_coercion.t b/t/100_bugs/030_coerce_without_coercion.t index 7880688..8f2b14f 100644 --- a/t/100_bugs/030_coerce_without_coercion.t +++ b/t/100_bugs/030_coerce_without_coercion.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Test::Moose; { @@ -19,19 +19,13 @@ use Test::Moose; } with_immutable { - lives_ok { Foo->new( x => {} ) } - 'Setting coerce => 1 without a coercion on the type does not cause an error in the constructor'; + is( exception { Foo->new( x => {} ) }, undef, 'Setting coerce => 1 without a coercion on the type does not cause an error in the constructor' ); - lives_ok { Foo->new->x( {} ) } - 'Setting coerce => 1 without a coercion on the type does not cause an error when setting the attribut'; + is( exception { Foo->new->x( {} ) }, undef, 'Setting coerce => 1 without a coercion on the type does not cause an error when setting the attribut' ); - throws_ok { Foo->new( x => 42 ) } - qr/\QAttribute (x) does not pass the type constraint because/, - 'Attempting to provide an invalid value to the constructor for this attr still fails'; + like( exception { Foo->new( x => 42 ) }, qr/\QAttribute (x) does not pass the type constraint because/, 'Attempting to provide an invalid value to the constructor for this attr still fails' ); - throws_ok { Foo->new->x(42) } - qr/\QAttribute (x) does not pass the type constraint because/, - 'Attempting to provide an invalid value to the accessor for this attr still fails'; + like( exception { Foo->new->x(42) }, qr/\QAttribute (x) does not pass the type constraint because/, 'Attempting to provide an invalid value to the accessor for this attr still fails' ); } 'Foo'; diff --git a/t/200_examples/002_example_Moose_POOP.t b/t/200_examples/002_example_Moose_POOP.t index b0227bd..8d6e28a 100644 --- a/t/200_examples/002_example_Moose_POOP.t +++ b/t/200_examples/002_example_Moose_POOP.t @@ -10,7 +10,7 @@ use Test::Requires { 'DateTime::Format::MySQL' => '0.01', }; -use Test::Exception; +use Test::Fatal; BEGIN { # in case there are leftovers @@ -237,7 +237,7 @@ my $article_oid; my $article_ref; { my $article; - lives_ok { + is( exception { $article = Newswriter::Article->new( headline => 'Home Office Redecorated', summary => 'The home office was recently redecorated to match the new company colors', @@ -250,14 +250,14 @@ my $article_ref; status => 'pending' ); - } '... created my article successfully'; + }, undef, '... created my article successfully' ); isa_ok($article, 'Newswriter::Article'); isa_ok($article, 'MooseX::POOP::Object'); - lives_ok { + is( exception { $article->start_date(DateTime->new(year => 2006, month => 6, day => 10)); $article->end_date(DateTime->new(year => 2006, month => 6, day => 17)); - } '... add the article date-time stuff'; + }, undef, '... add the article date-time stuff' ); ## check some meta stuff @@ -300,7 +300,7 @@ my $article2_oid; my $article2_ref; { my $article2; - lives_ok { + is( exception { $article2 = Newswriter::Article->new( headline => 'Company wins Lottery', summary => 'An email was received today that informed the company we have won the lottery', @@ -313,7 +313,7 @@ my $article2_ref; status => 'posted' ); - } '... created my article successfully'; + }, undef, '... created my article successfully' ); isa_ok($article2, 'Newswriter::Article'); isa_ok($article2, 'MooseX::POOP::Object'); @@ -340,9 +340,9 @@ my $article2_ref; ## orig-article my $article; - lives_ok { + is( exception { $article = Newswriter::Article->new(oid => $article_oid); - } '... (re)-created my article successfully'; + }, undef, '... (re)-created my article successfully' ); isa_ok($article, 'Newswriter::Article'); isa_ok($article, 'MooseX::POOP::Object'); @@ -364,10 +364,10 @@ my $article2_ref; is($article->author->first_name, 'Truman', '... got the right author first name'); is($article->author->last_name, 'Capote', '... got the right author last name'); - lives_ok { + is( exception { $article->author->first_name('Dan'); $article->author->last_name('Rather'); - } '... changed the value ok'; + }, undef, '... changed the value ok' ); is($article->author->first_name, 'Dan', '... got the changed author first name'); is($article->author->last_name, 'Rather', '... got the changed author last name'); @@ -379,9 +379,9 @@ MooseX::POOP::Meta::Instance->_reload_db(); { my $article; - lives_ok { + is( exception { $article = Newswriter::Article->new(oid => $article_oid); - } '... (re)-created my article successfully'; + }, undef, '... (re)-created my article successfully' ); isa_ok($article, 'Newswriter::Article'); isa_ok($article, 'MooseX::POOP::Object'); @@ -406,9 +406,9 @@ MooseX::POOP::Meta::Instance->_reload_db(); is($article->status, 'pending', '... got the right status'); my $article2; - lives_ok { + is( exception { $article2 = Newswriter::Article->new(oid => $article2_oid); - } '... (re)-created my article successfully'; + }, undef, '... (re)-created my article successfully' ); isa_ok($article2, 'Newswriter::Article'); isa_ok($article2, 'MooseX::POOP::Object'); diff --git a/t/200_examples/003_example.t b/t/200_examples/003_example.t index a61ba35..c3f5a68 100644 --- a/t/200_examples/003_example.t +++ b/t/200_examples/003_example.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; sub U { my $f = shift; @@ -81,16 +81,16 @@ sub Y { package My::List1; use Moose; - ::lives_ok { + ::is( ::exception { with 'List', 'List::Immutable'; - } '... successfully composed roles together'; + }, undef, '... successfully composed roles together' ); package My::List2; use Moose; - ::lives_ok { + ::is( ::exception { with 'List::Immutable', 'List'; - } '... successfully composed roles together'; + }, undef, '... successfully composed roles together' ); } diff --git a/t/200_examples/004_example_w_DCS.t b/t/200_examples/004_example_w_DCS.t index 671781c..1609886 100644 --- a/t/200_examples/004_example_w_DCS.t +++ b/t/200_examples/004_example_w_DCS.t @@ -18,7 +18,7 @@ use Test::Requires { 'Declare::Constraints::Simple' => '0.01', # skip all if not installed }; -use Test::Exception; +use Test::Fatal; { package Foo; @@ -58,35 +58,35 @@ my $hash_of_arrays_of_objs = { my $array_of_ints = [ 1 .. 10 ]; my $foo; -lives_ok { +is( exception { $foo = Foo->new( 'bar' => $hash_of_arrays_of_objs, 'baz' => $array_of_ints, ); -} '... construction succeeded'; +}, undef, '... construction succeeded' ); isa_ok($foo, 'Foo'); is_deeply($foo->bar, $hash_of_arrays_of_objs, '... got our value correctly'); is_deeply($foo->baz, $array_of_ints, '... got our value correctly'); -dies_ok { +isnt( exception { $foo->bar([]); -} '... validation failed correctly'; +}, undef, '... validation failed correctly' ); -dies_ok { +isnt( exception { $foo->bar({ foo => 3 }); -} '... validation failed correctly'; +}, undef, '... validation failed correctly' ); -dies_ok { +isnt( exception { $foo->bar({ foo => [ 1, 2, 3 ] }); -} '... validation failed correctly'; +}, undef, '... validation failed correctly' ); -dies_ok { +isnt( exception { $foo->baz([ "foo" ]); -} '... validation failed correctly'; +}, undef, '... validation failed correctly' ); -dies_ok { +isnt( exception { $foo->baz({}); -} '... validation failed correctly'; +}, undef, '... validation failed correctly' ); done_testing; diff --git a/t/200_examples/005_example_w_TestDeep.t b/t/200_examples/005_example_w_TestDeep.t index 676ae29..bd16205 100644 --- a/t/200_examples/005_example_w_TestDeep.t +++ b/t/200_examples/005_example_w_TestDeep.t @@ -19,7 +19,7 @@ use Test::Requires { 'Test::Deep' => '0.01', # skip all if not installed }; -use Test::Exception; +use Test::Fatal; { package Foo; @@ -58,19 +58,19 @@ my $array_of_hashes = [ ]; my $foo; -lives_ok { +is( exception { $foo = Foo->new('bar' => $array_of_hashes); -} '... construction succeeded'; +}, undef, '... construction succeeded' ); isa_ok($foo, 'Foo'); is_deeply($foo->bar, $array_of_hashes, '... got our value correctly'); -dies_ok { +isnt( exception { $foo->bar({}); -} '... validation failed correctly'; +}, undef, '... validation failed correctly' ); -dies_ok { +isnt( exception { $foo->bar([{ foo => 3 }]); -} '... validation failed correctly'; +}, undef, '... validation failed correctly' ); done_testing; diff --git a/t/300_immutable/001_immutable_moose.t b/t/300_immutable/001_immutable_moose.t index b969268..48c0674 100644 --- a/t/300_immutable/001_immutable_moose.t +++ b/t/300_immutable/001_immutable_moose.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Meta::Role; @@ -33,25 +33,25 @@ use Moose::Meta::Role; my $foo_role = Moose::Meta::Role->initialize('FooRole'); my $meta = Foo->meta; - lives_ok { Foo->new } "lazy_build works"; + is( exception { Foo->new }, undef, "lazy_build works" ); is( Foo->new->foos, 'many foos', "correct value for 'foos' before inlining constructor" ); is( Foo->new->bars, 'many bars', "correct value for 'bars' before inlining constructor" ); is( Foo->new->bazes, 'many bazes', "correct value for 'bazes' before inlining constructor" ); - lives_ok { $meta->make_immutable } "Foo is imutable"; - lives_ok { $meta->identifier } "->identifier on metaclass lives"; - dies_ok { $meta->add_role($foo_role) } "Add Role is locked"; - lives_ok { Foo->new } "Inlined constructor works with lazy_build"; + is( exception { $meta->make_immutable }, undef, "Foo is imutable" ); + is( exception { $meta->identifier }, undef, "->identifier on metaclass lives" ); + isnt( exception { $meta->add_role($foo_role) }, undef, "Add Role is locked" ); + is( exception { Foo->new }, undef, "Inlined constructor works with lazy_build" ); is( Foo->new->foos, 'many foos', "correct value for 'foos' after inlining constructor" ); is( Foo->new->bars, 'many bars', "correct value for 'bars' after inlining constructor" ); is( Foo->new->bazes, 'many bazes', "correct value for 'bazes' after inlining constructor" ); - lives_ok { $meta->make_mutable } "Foo is mutable"; - lives_ok { $meta->add_role($foo_role) } "Add Role is unlocked"; + is( exception { $meta->make_mutable }, undef, "Foo is mutable" ); + is( exception { $meta->add_role($foo_role) }, undef, "Add Role is unlocked" ); } @@ -73,11 +73,9 @@ use Moose::Meta::Role; sub BUILD { 'baz' } } -lives_ok { Bar->meta->make_immutable } - 'Immutable meta with single BUILD'; +is( exception { Bar->meta->make_immutable }, undef, 'Immutable meta with single BUILD' ); -lives_ok { Baz->meta->make_immutable } - 'Immutable meta with multiple BUILDs'; +is( exception { Baz->meta->make_immutable }, undef, 'Immutable meta with multiple BUILDs' ); =pod diff --git a/t/300_immutable/002_apply_roles_to_immutable.t b/t/300_immutable/002_apply_roles_to_immutable.t index 57d0c7f..b153a8f 100644 --- a/t/300_immutable/002_apply_roles_to_immutable.t +++ b/t/300_immutable/002_apply_roles_to_immutable.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -31,9 +31,9 @@ isa_ok($foo, 'Foo'); is($foo->baz, 'Foo::baz', '... got the right value'); -lives_ok { +is( exception { My::Role->meta->apply($foo) -} '... successfully applied the role to immutable instance'; +}, undef, '... successfully applied the role to immutable instance' ); is($foo->baz, 'My::Role::baz(Foo::baz)', '... got the right value'); diff --git a/t/300_immutable/003_immutable_meta_class.t b/t/300_immutable/003_immutable_meta_class.t index 1a1b662..2f540d6 100644 --- a/t/300_immutable/003_immutable_meta_class.t +++ b/t/300_immutable/003_immutable_meta_class.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -20,8 +20,8 @@ use Test::Exception; ); } -lives_ok { +is( exception { My::Meta->meta()->make_immutable(debug => 0) -} '... can make a meta class immutable'; +}, undef, '... can make a meta class immutable' ); done_testing; diff --git a/t/300_immutable/004_inlined_constructors_n_types.t b/t/300_immutable/004_inlined_constructors_n_types.t index 0c47a8c..e685879 100644 --- a/t/300_immutable/004_inlined_constructors_n_types.t +++ b/t/300_immutable/004_inlined_constructors_n_types.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; =pod @@ -42,19 +42,19 @@ as with a Class::MOP::Attribute object. for (1..2) { my $is_immutable = Foo->meta->is_immutable; my $mutable_string = $is_immutable ? 'immutable' : 'mutable'; - lives_ok { + is( exception { my $f = Foo->new(foo => 10, bar => "Hello World", baz => 10, zot => 4); is($f->moo, 69, "Type coercion works as expected on default ($mutable_string)"); is($f->boo, 69, "Type coercion works as expected on builder ($mutable_string)"); - } "... this passes the constuctor correctly ($mutable_string)"; + }, undef, "... this passes the constuctor correctly ($mutable_string)" ); - lives_ok { + is( exception { Foo->new(foo => 10, bar => "Hello World", baz => 10, zot => "not an int"); - } "... the constructor doesn't care about 'zot' ($mutable_string)"; + }, undef, "... the constructor doesn't care about 'zot' ($mutable_string)" ); - dies_ok { + isnt( exception { Foo->new(foo => "Hello World", bar => 100, baz => "Hello World"); - } "... this fails the constuctor correctly ($mutable_string)"; + }, undef, "... this fails the constuctor correctly ($mutable_string)" ); Foo->meta->make_immutable(debug => 0) unless $is_immutable; } diff --git a/t/300_immutable/005_multiple_demolish_inline.t b/t/300_immutable/005_multiple_demolish_inline.t index d30a9c8..a4637ff 100644 --- a/t/300_immutable/005_multiple_demolish_inline.t +++ b/t/300_immutable/005_multiple_demolish_inline.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -26,20 +26,20 @@ use Test::Exception; sub DEMOLISH { } } -lives_ok { +is( exception { Bar->new(); -} 'Bar->new()'; +}, undef, 'Bar->new()' ); -lives_ok { +is( exception { Bar->meta->make_immutable; -} 'Bar->meta->make_immutable'; +}, undef, 'Bar->meta->make_immutable' ); is( Bar->meta->get_method('DESTROY')->package_name, 'Bar', 'Bar has a DESTROY method in the Bar class (not inherited)' ); -lives_ok { +is( exception { Foo->meta->make_immutable; -} 'Foo->meta->make_immutable'; +}, undef, 'Foo->meta->make_immutable' ); is( Foo->meta->get_method('DESTROY')->package_name, 'Foo', 'Foo has a DESTROY method in the Bar class (not inherited)' ); diff --git a/t/300_immutable/007_immutable_trigger_from_constructor.t b/t/300_immutable/007_immutable_trigger_from_constructor.t index bc86c1d..037a1e5 100644 --- a/t/300_immutable/007_immutable_trigger_from_constructor.t +++ b/t/300_immutable/007_immutable_trigger_from_constructor.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -33,6 +33,6 @@ like ($@, qr/^Pulling the Foo trigger/, "trigger from immutable constructor"); eval { AClass->new(baz => 'bar') }; like ($@, qr/^Pulling the Baz trigger/, "trigger from immutable constructor"); -lives_ok { AClass->new(bar => 'bar') } '... no triggers called'; +is( exception { AClass->new(bar => 'bar') }, undef, '... no triggers called' ); done_testing; diff --git a/t/300_immutable/008_immutable_constructor_error.t b/t/300_immutable/008_immutable_constructor_error.t index d5db002..dc8c6cd 100644 --- a/t/300_immutable/008_immutable_constructor_error.t +++ b/t/300_immutable/008_immutable_constructor_error.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; =pod @@ -25,11 +25,8 @@ constructor. } my $scalar = 1; -throws_ok { Foo->new($scalar) } qr/\QSingle parameters to new() must be a HASH ref/, - 'Non-ref provided to immutable constructor gives useful error message'; -throws_ok { Foo->new(\$scalar) } qr/\QSingle parameters to new() must be a HASH ref/, - 'Scalar ref provided to immutable constructor gives useful error message'; -throws_ok { Foo->new(undef) } qr/\QSingle parameters to new() must be a HASH ref/, - 'undef provided to immutable constructor gives useful error message'; +like( exception { Foo->new($scalar) }, qr/\QSingle parameters to new() must be a HASH ref/, 'Non-ref provided to immutable constructor gives useful error message' ); +like( exception { Foo->new(\$scalar) }, qr/\QSingle parameters to new() must be a HASH ref/, 'Scalar ref provided to immutable constructor gives useful error message' ); +like( exception { Foo->new(undef) }, qr/\QSingle parameters to new() must be a HASH ref/, 'undef provided to immutable constructor gives useful error message' ); done_testing; diff --git a/t/300_immutable/012_default_values.t b/t/300_immutable/012_default_values.t index ad4e611..2b9ab02 100644 --- a/t/300_immutable/012_default_values.t +++ b/t/300_immutable/012_default_values.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { @@ -17,8 +17,7 @@ use Test::Exception; has 'buz' => ( is => 'rw', default => q{"'\\} ); has 'faz' => ( is => 'rw', default => qq{\0} ); - ::lives_ok { __PACKAGE__->meta->make_immutable } - 'no errors making a package immutable when it has default values that could break quoting'; + ::is( ::exception { __PACKAGE__->meta->make_immutable }, undef, 'no errors making a package immutable when it has default values that could break quoting' ); } my $foo = Foo->new; @@ -47,8 +46,7 @@ is( $foo->faz, qq{\0}, has 'buz' => ( is => 'rw', default => q{"'\\}, lazy => 1 ); has 'faz' => ( is => 'rw', default => qq{\0}, lazy => 1 ); - ::lives_ok { __PACKAGE__->meta->make_immutable } - 'no errors making a package immutable when it has lazy default values that could break quoting'; + ::is( ::exception { __PACKAGE__->meta->make_immutable }, undef, 'no errors making a package immutable when it has lazy default values that could break quoting' ); } my $bar = Bar->new; diff --git a/t/400_moose_util/008_method_mod_args.t b/t/400_moose_util/008_method_mod_args.t index 5919287..c4536d8 100644 --- a/t/400_moose_util/008_method_mod_args.t +++ b/t/400_moose_util/008_method_mod_args.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Moose::Util qw( add_method_modifier ); my $COUNT = 0; @@ -14,13 +14,13 @@ my $COUNT = 0; sub bar { } } -lives_ok { +is( exception { add_method_modifier('Foo', 'before', [ ['foo', 'bar'], sub { $COUNT++ } ]); -} 'method modifier with an arrayref'; +}, undef, 'method modifier with an arrayref' ); -dies_ok { +isnt( exception { add_method_modifier('Foo', 'before', [ {'foo' => 'bar'}, sub { $COUNT++ } ]); -} 'method modifier with a hashref'; +}, undef, 'method modifier with a hashref' ); my $foo = Foo->new; $foo->foo; diff --git a/t/600_todo_tests/001_exception_reflects_failed_constraint.t b/t/600_todo_tests/001_exception_reflects_failed_constraint.t index c768b90..b178c89 100644 --- a/t/600_todo_tests/001_exception_reflects_failed_constraint.t +++ b/t/600_todo_tests/001_exception_reflects_failed_constraint.t @@ -8,20 +8,20 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; BEGIN { use_ok('Moose::Util::TypeConstraints'); } -lives_ok { +is( exception { subtype 'ParentConstraint' => as 'Str' => where {0}; -} 'specified parent type constraint'; +}, undef, 'specified parent type constraint' ); my $tc; -lives_ok { +is( exception { $tc = subtype 'ChildConstraint' => as 'ParentConstraint' => where {1}; -} 'specified child type constraint'; +}, undef, 'specified child type constraint' ); { my $errmsg = $tc->validate(); diff --git a/t/600_todo_tests/002_various_role_features.t b/t/600_todo_tests/002_various_role_features.t index 8b6bccc..63e769b 100644 --- a/t/600_todo_tests/002_various_role_features.t +++ b/t/600_todo_tests/002_various_role_features.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; sub req_or_has ($$) { my ( $role, $method ) = @_; @@ -73,7 +73,7 @@ sub req_or_has ($$) { # this doesn't fail but it produces a requires in the role # the order doesn't matter has twist => ( is => "rw" ); - ::lives_ok { with qw(Dancer) }; + ::is( ::exception { with qw(Dancer) }, undef ); package Dancer::Something; use Moose; @@ -83,7 +83,7 @@ sub req_or_has ($$) { has twist => ( is => "rw" ); { - ::lives_ok { with qw(Dancer) }; + ::is( ::exception { with qw(Dancer) }, undef ); } package Dancer::80s; @@ -93,7 +93,7 @@ sub req_or_has ($$) { # but due to the deferrence logic that doesn't actually work { local our $TODO = "attribute accessor in role doesn't satisfy role requires"; - ::lives_ok { with qw(Dancer::Robot) }; + ::is( ::exception { with qw(Dancer::Robot) }, undef ); } package Foo; @@ -135,7 +135,7 @@ sub req_or_has ($$) { { local our $TODO = "attrs and methods from a role should clash"; - ::dies_ok { with qw(Tree Dog) } + ::isnt( ::exception { with qw(Tree Dog) }, undef ); } } diff --git a/t/600_todo_tests/006_required_role_accessors.t b/t/600_todo_tests/006_required_role_accessors.t index fed49f8..e76c273 100644 --- a/t/600_todo_tests/006_required_role_accessors.t +++ b/t/600_todo_tests/006_required_role_accessors.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; { package Foo::API; @@ -24,7 +24,7 @@ use Test::Exception; package Foo::Class; use Moose; { our $TODO; local $TODO = "role accessors don't satisfy other role requires"; - ::lives_ok { with 'Foo' } 'requirements are satisfied properly'; + ::is( ::exception { with 'Foo' }, undef, 'requirements are satisfied properly' ); } } @@ -51,7 +51,7 @@ use Test::Exception; use Moose; { our $TODO; local $TODO = "role accessors don't satisfy other role requires"; - ::lives_ok { with qw(Bar Baz) } 'requirements are satisfied properly'; + ::is( ::exception { with qw(Bar Baz) }, undef, 'requirements are satisfied properly' ); } } diff --git a/t/600_todo_tests/007_application_metarole_compat.t b/t/600_todo_tests/007_application_metarole_compat.t index c254f51..b141e83 100644 --- a/t/600_todo_tests/007_application_metarole_compat.t +++ b/t/600_todo_tests/007_application_metarole_compat.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; BEGIN { { @@ -52,7 +52,7 @@ BEGIN { package Child; use Moose -traits => 'Bar'; { our $TODO; local $TODO = "no idea what's going on here"; - ::lives_ok { extends 'Parent' }; + ::is( ::exception { extends 'Parent' }, undef ); } }