my $base = $self->SUPER::process(@_);
- $base =~ s/(\$\| = 1;)/use Test::Fatal;\n$1/;
+ $base =~ s/(\$\| = 1;)/use Test::Exception;\n$1/;
return $base;
}
$point->y(10);
is( $point->y, 10, '... got the right (changed) value for y' );
-ok exception {
+dies_ok {
$point->y('Foo');
-},
+}
'... cannot assign a non-Int to y';
-ok exception {
+dies_ok {
Point->new();
-},
+}
'... must provide required attributes to new';
$point->clear();
# check the type constraints on the constructor
-ok ! exception {
+lives_ok {
Point->new( x => 0, y => 0 );
-},
+}
'... can assign a 0 to x and y';
-ok exception {
+dies_ok {
Point->new( x => 10, y => 'Foo' );
-},
+}
'... cannot assign a non-Int to y';
-ok exception {
+dies_ok {
Point->new( x => 'Foo', y => 10 );
-},
+}
'... cannot assign a non-Int to x';
# Point3D
is( $point3d->y, 0, '... got the right (cleared) value for y' );
is( $point3d->z, 0, '... got the right (cleared) value for z' );
-ok exception {
+dies_ok {
Point3D->new( x => 10, y => 'Foo', z => 3 );
-},
+}
'... cannot assign a non-Int to y';
-ok exception {
+dies_ok {
Point3D->new( x => 'Foo', y => 10, z => 3 );
-},
+}
'... cannot assign a non-Int to x';
-ok exception {
+dies_ok {
Point3D->new( x => 0, y => 10, z => 'Bar' );
-},
+}
'... cannot assign a non-Int to z';
-ok exception {
+dies_ok {
Point3D->new( x => 10, y => 3 );
-},
+}
'... z is a required attribute for Point3D';
# test some class introspection
isa_ok( $savings_account, 'BankAccount' );
is( $savings_account->balance, 250, '... got the right savings balance' );
- ok ! exception {
+ lives_ok {
$savings_account->withdraw(50);
- },
+ }
'... withdrew from savings successfully';
is( $savings_account->balance, 200,
'... got the right savings balance after withdrawl' );
is( $checking_account->balance, 100,
'... got the right checkings balance' );
- ok ! exception {
+ lives_ok {
$checking_account->withdraw(50);
- },
+ }
'... withdrew from checking successfully';
is( $checking_account->balance, 50,
'... got the right checkings balance after withdrawl' );
'... got the right savings balance after checking withdrawl (no overdraft)'
);
- ok ! exception {
+ lives_ok {
$checking_account->withdraw(200);
- },
+ }
'... withdrew from checking successfully';
is( $checking_account->balance, 0,
'... got the right checkings balance after withdrawl' );
is( $checking_account->balance, 100,
'... got the right checkings balance' );
- ok ! exception {
+ lives_ok {
$checking_account->withdraw(50);
- },
+ }
'... withdrew from checking successfully';
is( $checking_account->balance, 50,
'... got the right checkings balance after withdrawl' );
- ok exception {
+ dies_ok {
$checking_account->withdraw(200);
- },
+ }
'... withdrawl failed due to attempted overdraft';
is( $checking_account->balance, 50,
'... got the right checkings balance after withdrawl failure' );
is($left->node, undef, '... left has got no node value');
-ok ! exception {
+lives_ok {
$left->node('left')
-}, '... assign to lefts node';
+} '... assign to lefts node';
is($left->node, 'left', '... left now has a node value');
my $right = $root->right;
isa_ok($right, 'BinaryTree');
-ok ! exception {
+lives_ok {
$right->node('right')
-}, '... assign to rights node';
+} '... assign to rights node';
is($right->node, 'right', '... left now has a node value');
my $left_right = BinaryTree->new;
isa_ok($left_right, 'BinaryTree');
-ok ! exception {
+lives_ok {
$left->right($left_right)
-}, '... assign to rights node';
+} '... assign to rights node';
ok($left_right->has_parent, '... left does have a parent');
# and check the error
-ok exception {
+dies_ok {
$left_right->right($left_left)
-}, '... cant assign a node which already has a parent';
+} '... cant assign a node which already has a parent';
=end testing
use Scalar::Util 'isweak';
my $ii;
-ok ! exception {
+lives_ok {
$ii = Company->new(
{
name => 'Infinity Interactive',
]
}
);
-},
+}
'... created the entire company successfully';
isa_ok( $ii, 'Company' );
## check some error conditions for the subtypes
-ok exception {
+dies_ok {
Address->new( street => {} ),;
-},
+}
'... we die correctly with bad args';
-ok exception {
+dies_ok {
Address->new( city => {} ),;
-},
+}
'... we die correctly with bad args';
-ok exception {
+dies_ok {
Address->new( state => 'British Columbia' ),;
-},
+}
'... we die correctly with bad args';
-ok ! exception {
+lives_ok {
Address->new( state => 'Connecticut' ),;
-},
+}
'... we live correctly with good args';
-ok exception {
+dies_ok {
Address->new( zip_code => 'AF5J6$' ),;
-},
+}
'... we die correctly with bad args';
-ok ! exception {
+lives_ok {
Address->new( zip_code => '06443' ),;
-},
+}
'... we live correctly with good args';
-ok exception {
+dies_ok {
Company->new(),;
-},
+}
'... we die correctly without good args';
-ok ! exception {
+lives_ok {
Company->new( name => 'Foo' ),;
-},
+}
'... we live correctly without good args';
-ok exception {
+dies_ok {
Company->new( name => 'Foo', employees => [ Person->new ] ),;
-},
+}
'... we die correctly with good args';
-ok ! exception {
+lives_ok {
Company->new( name => 'Foo', employees => [] ),;
-},
+}
'... we live correctly with good args';
=end testing
is( $header4->content_type, 'application/pdf',
'... got the right content type in the header' );
- ok exception {
+ dies_ok {
$r->headers('Foo');
- },
+ }
'... dies when it gets bad params';
}
{
is( $r->protocol, undef, '... got nothing by default' );
- ok ! exception {
+ lives_ok {
$r->protocol('HTTP/1.0');
- },
+ }
'... set the protocol correctly';
is( $r->protocol, 'HTTP/1.0', '... got nothing by default' );
- ok exception {
+ dies_ok {
$r->protocol('http/1.0');
- },
+ }
'... the protocol died with bar params correctly';
}
package main;
-use Test::More;
-use Test::Fatal;
+use Test::Exception;
my $user = MyApp::User->new( password => 'foo!' );
-like exception { $user->_reset_password },
+throws_ok { $user->_reset_password }
qr/The MyApp::User::_reset_password method is private/,
'_reset_password method dies if called outside MyApp::User class';
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
ok(Foo->meta->has_method('meta'), '... we got the &meta method');
ok(Foo->isa('Moose::Object'), '... Foo is automagically a Moose::Object');
-ok exception {
+dies_ok {
Foo->meta->has_method()
-}, '... has_method requires an arg';
+} '... has_method requires an arg';
can_ok('Foo', 'does');
use lib 't/lib', 'lib';
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package Bar;
use Moose;
- ::ok ! ::exception { extends 'Foo' }, 'loaded Foo superclass correctly';
+ ::lives_ok { extends 'Foo' } 'loaded Foo superclass correctly';
}
{
package Baz;
use Moose;
- ::ok ! ::exception { extends 'Bar' }, 'loaded (inline) Bar superclass correctly';
+ ::lives_ok { extends 'Bar' } 'loaded (inline) Bar superclass correctly';
}
{
package Foo::Bar;
use Moose;
- ::ok ! ::exception { extends 'Foo', 'Bar' },
+ ::lives_ok { extends 'Foo', 'Bar' }
'loaded Foo and (inline) Bar superclass correctly';
}
package Bling;
use Moose;
- ::like ::exception { extends 'No::Class' },
+ ::throws_ok { extends 'No::Class' }
qr{Can't locate No/Class\.pm in \@INC},
'correct error when superclass could not be found';
}
package Tiger;
use Moose;
- ::ok ! ::exception { extends 'Foo', Affe => { -version => 13 } },
+ ::lives_ok { extends 'Foo', Affe => { -version => 13 } }
'extends with version requirement';
}
package Birne;
use Moose;
- ::like ::exception { extends 'Foo', Affe => { -version => 42 } },
+ ::throws_ok { extends 'Foo', Affe => { -version => 42 } }
qr/Affe version 42 required--this is only version 23/,
'extends with unsatisfied version requirement';
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
sub bling { 'Bling::bling' }
- ::ok ::exception {
+ ::dies_ok {
override 'bling' => sub {};
- }, '... cannot override a method which has a local equivalent';
+ } '... cannot override a method which has a local equivalent';
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
sub bling { 'Bling::bling' }
- ::ok ::exception {
+ ::dies_ok {
augment 'bling' => sub {};
- }, '... cannot augment a method which has a local equivalent';
+ } '... cannot augment a method which has a local equivalent';
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package Dog::Role;
use Moose::Role;
- ::ok ::exception {
+ ::dies_ok {
before qr/bark.*/ => sub {};
- }, '... this is not currently supported';
+ } '... this is not currently supported';
- ::ok ::exception {
+ ::dies_ok {
around qr/bark.*/ => sub {};
- }, '... this is not currently supported';
+ } '... this is not currently supported';
- ::ok ::exception {
+ ::dies_ok {
after qr/bark.*/ => sub {};
- }, '... this is not currently supported';
+ } '... this is not currently supported';
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Util::TypeConstraints;
my $bar = Bar->new;
isa_ok($bar, 'Bar');
-ok ! exception {
+lives_ok {
$bar->foo('Foo');
-}, '... checked the type constraint correctly';
+} '... checked the type constraint correctly';
-ok exception {
+dies_ok {
$bar->foo(Foo->new);
-}, '... checked the type constraint correctly';
+} '... checked the type constraint correctly';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Scalar::Util 'blessed';
use Moose::Util::TypeConstraints;
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");
-ok ! exception { $foo->type_constrained(10.5) }, "Num type constraint for now..";
+lives_ok { $foo->type_constrained(10.5) } "Num type constraint for now..";
# try to rebless, except it will fail due to Child's stricter type constraint
-like exception { Child->meta->rebless_instance($foo) },
+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';
-like exception { Child->meta->rebless_instance($bar) },
+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';
is($foo->lazy_classname, 'Parent', "lazy attribute was already initialized");
is($bar->lazy_classname, 'Child', "lazy attribute just now initialized");
-like exception { $foo->type_constrained(10.5) },
+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';
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package Class;
my $new_class;
-ok ! exception {
+lives_ok {
$new_class = Moose::Meta::Class->create(
'Class::WithFoo',
superclasses => ['Class'],
roles => ['Foo'],
);
-}, 'creating lives';
+} 'creating lives';
ok $new_class;
my $with_foo = Class::WithFoo->new;
ok $with_foo->foo_role_applied;
isa_ok $with_foo, 'Class', '$with_foo';
-like exception {
+throws_ok {
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";
-ok exception {
+dies_ok {
Moose::Meta::Class->create(
'Continuing::To::Fail',
superclasses => ['Class'],
roles => ['Foo', 'Conflicts::With::Foo'],
);
-}, 'conflicting roles == death';
+} 'conflicting roles == death';
# XXX: Continuing::To::Fail gets created anyway
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
-ok ! exception {
+lives_ok {
eval 'use Moose';
-}, "export to main";
+} "export to main";
isa_ok( main->meta, "Moose::Meta::Class" );
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
# This tests the error handling in Moose::Object only
use Moose;
}
-like exception { Foo->new('bad') }, qr/^\QSingle parameters to new() must be a HASH ref/,
+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';
-like exception { Foo->new(undef) }, qr/^\QSingle parameters to new() must be a HASH ref/,
+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->does() }, qr/^\QYou must supply a role name to does()/,
+throws_ok { Foo->does() } qr/^\QYou must supply a role name to does()/,
'Cannot call does() without a role name';
done_testing;
use strict;
use warnings;
-use Test::Fatal;
+use Test::Exception;
use Test::More;
use Test::Moose qw( with_immutable );
}
with_immutable {
- ok ! exception {
+ lives_and {
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()';
use strict;
use warnings;
-use Test::Fatal;
+use Test::Exception;
use Test::More;
use Test::Requires {
'Test::Output' => '0.01',
};
-# All tests are wrapped with exception{} because the stderr output tests will
+# All tests are wrapped with lives_and because the stderr output tests will
# otherwise eat exceptions, and the test just dies silently.
{
use Moose;
- ::ok not ::exception(
+ ::lives_and(
sub {
::stderr_like{ has foo => (
traits => ['String'],
use Moose;
- ::ok not ::exception(
+ ::lives_and(
sub {
::stderr_is{ has foo => (
traits => ['String'],
use Moose;
- ::ok not ::exception(
+ ::lives_and(
sub {
::stderr_is{ has foo => (
traits => ['String'],
use Moose;
- ::ok not ::exception(
+ ::lives_and(
sub {
::stderr_is{ has foo => (
traits => ['String'],
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
can_ok($foo, 'get_foo');
is($foo->get_foo(), undef, '... got an undefined value');
- ok exception {
+ dies_ok {
$foo->get_foo(100);
- }, '... get_foo is a read-only';
+ } '... 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');
- ok exception {
+ dies_ok {
$foo->get_lazy_foo(100);
- }, '... get_lazy_foo is a read-only';
+ } '... get_lazy_foo is a read-only';
}
{
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Scalar::Util 'isweak';
can_ok($foo, 'set_foo');
is($foo->get_foo(), undef, '... got an unset value');
- ok ! exception {
+ lives_ok {
$foo->set_foo(100);
- }, '... set_foo wrote successfully';
+ } '... 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
- ok exception {
+ dies_ok {
Foo->new;
- }, '... cannot create without the required attribute';
+ } '... cannot create without the required attribute';
can_ok($foo, 'set_foo_required');
is($foo->get_foo_required(), 'required', '... got an unset value');
- ok ! exception {
+ lives_ok {
$foo->set_foo_required(100);
- }, '... set_foo_required wrote successfully';
+ } '... set_foo_required wrote successfully';
is($foo->get_foo_required(), 100, '... got the correct set value');
- ok exception {
+ dies_ok {
$foo->set_foo_required();
- }, '... set_foo_required died successfully with no value';
+ } '... set_foo_required died successfully with no value';
- ok ! exception {
+ lives_ok {
$foo->set_foo_required(undef);
- }, '... set_foo_required did accept undef';
+ } '... set_foo_required did accept undef';
ok(!isweak($foo->{foo_required}), '... it is not a weak reference');
can_ok($foo, 'set_foo_int');
is($foo->get_foo_int(), undef, '... got an unset value');
- ok ! exception {
+ lives_ok {
$foo->set_foo_int(100);
- }, '... set_foo_int wrote successfully';
+ } '... set_foo_int wrote successfully';
is($foo->get_foo_int(), 100, '... got the correct set value');
- ok exception {
+ dies_ok {
$foo->set_foo_int("Foo");
- }, '... set_foo_int died successfully';
+ } '... set_foo_int died successfully';
ok(!isweak($foo->{foo_int}), '... it is not a weak reference');
can_ok($foo, 'set_foo_weak');
is($foo->get_foo_weak(), undef, '... got an unset value');
- ok ! exception {
+ lives_ok {
$foo->set_foo_weak($test);
- }, '... set_foo_weak wrote successfully';
+ } '... 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');
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Scalar::Util 'isweak';
can_ok($foo, 'foo');
is($foo->foo(), undef, '... got an unset value');
- ok ! exception {
+ lives_ok {
$foo->foo(100);
- }, '... foo wrote successfully';
+ } '... foo wrote successfully';
is($foo->foo(), 100, '... got the correct set value');
ok(!isweak($foo->{foo}), '... it is not a weak reference');
# required writer
- ok exception {
+ dies_ok {
Foo->new;
- }, '... cannot create without the required attribute';
+ } '... cannot create without the required attribute';
can_ok($foo, 'foo_required');
is($foo->foo_required(), 'required', '... got an unset value');
- ok ! exception {
+ lives_ok {
$foo->foo_required(100);
- }, '... foo_required wrote successfully';
+ } '... foo_required wrote successfully';
is($foo->foo_required(), 100, '... got the correct set value');
- ok ! exception {
+ lives_ok {
$foo->foo_required(undef);
- }, '... foo_required did not die with undef';
+ } '... foo_required did not die with undef';
is($foo->foo_required, undef, "value is undef");
can_ok($foo, 'foo_int');
is($foo->foo_int(), undef, '... got an unset value');
- ok ! exception {
+ lives_ok {
$foo->foo_int(100);
- }, '... foo_int wrote successfully';
+ } '... foo_int wrote successfully';
is($foo->foo_int(), 100, '... got the correct set value');
- ok exception {
+ dies_ok {
$foo->foo_int("Foo");
- }, '... foo_int died successfully';
+ } '... foo_int died successfully';
ok(!isweak($foo->{foo_int}), '... it is not a weak reference');
can_ok($foo, 'foo_weak');
is($foo->foo_weak(), undef, '... got an unset value');
- ok ! exception {
+ lives_ok {
$foo->foo_weak($test);
- }, '... foo_weak wrote successfully';
+ } '... foo_weak wrote successfully';
is($foo->foo_weak(), $test, '... got the correct set value');
ok(isweak($foo->{foo_weak}), '... it is a weak reference');
can_ok( $foo, 'foo_deref');
is_deeply( [$foo->foo_deref()], [], '... default default value');
my @list;
- ok ! exception {
+ lives_ok {
@list = $foo->foo_deref();
- }, "... doesn't deref undef value";
+ } "... doesn't deref undef value";
is_deeply( \@list, [], "returns empty list in list context");
- ok ! exception {
+ lives_ok {
$foo->foo_deref( [ qw/foo bar gorch/ ] );
- }, '... foo_deref wrote successfully';
+ } '... 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" );
can_ok( $foo, 'foo_deref' );
is_deeply( [$foo->foo_deref_ro()], [], "... default default value" );
- ok exception {
+ dies_ok {
$foo->foo_deref_ro( [] );
- }, "... read only";
+ } "... read only";
$foo->{foo_deref_ro} = [qw/la la la/];
is_deeply( { $foo->foo_deref_hash() }, {}, "... default default value" );
my %hash;
- ok ! exception {
+ lives_ok {
%hash = $foo->foo_deref_hash();
- }, "... doesn't deref undef value";
+ } "... doesn't deref undef value";
is_deeply( \%hash, {}, "returns empty list in list context");
- ok ! exception {
+ lives_ok {
$foo->foo_deref_hash( { foo => 1, bar => 2 } );
- }, '... foo_deref_hash wrote successfully';
+ } '... foo_deref_hash wrote successfully';
is_deeply( scalar($foo->foo_deref_hash), { foo => 1, bar => 2 }, "scalar context" );
use Scalar::Util 'isweak';
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
my $baz = Baz->new;
isa_ok($baz, 'Baz');
- ok ! exception {
+ lives_ok {
$foo->bar($bar);
- }, '... did not die setting bar';
+ } '... 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');
- ok ! exception {
+ lives_ok {
$foo->bar(undef);
- }, '... did not die un-setting bar';
+ } '... 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
- ok ! exception {
+ lives_ok {
$foo->set_baz($baz);
- }, '... did not die setting baz';
+ } '... 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');
package Bling;
use Moose;
- ::ok ::exception {
+ ::dies_ok {
has('bling' => (is => 'rw', trigger => 'Fail'));
- }, '... a trigger must be a CODE ref';
+ } '... a trigger must be a CODE ref';
- ::ok ::exception {
+ ::dies_ok {
has('bling' => (is => 'rw', trigger => []));
- }, '... a trigger must be a CODE ref';
+ } '... a trigger must be a CODE ref';
}
# Triggers do not fire on built values
{
my $blarg;
- ok ! exception { $blarg = Blarg->new; }, 'Blarg->new() lives';
+ lives_ok { $blarg = Blarg->new; } '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");
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');
- ok ! exception { $blarg = Blarg->new( map { $_ => "Yet another $_ value" } qw/foo bar baz/ ) }, '->new() with parameters';
+ lives_ok { $blarg => Blarg->new( map { $_ => "Yet another $_ value" } qw/foo bar baz/ ) } '->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');
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
my $bar = Bar::Class->new;
isa_ok($bar, 'Bar::Class');
-ok ! exception {
+lives_ok {
$foo->bar($bar);
-}, '... bar passed the type constraint okay';
+} '... bar passed the type constraint okay';
-ok exception {
+dies_ok {
$foo->bar($foo);
-}, '... foo did not pass the type constraint okay';
+} '... foo did not pass the type constraint okay';
-ok ! exception {
+lives_ok {
$foo->baz($bar);
-}, '... baz passed the type constraint okay';
+} '... baz passed the type constraint okay';
-ok exception {
+dies_ok {
$foo->baz($foo);
-}, '... foo did not pass the type constraint okay';
+} '... foo did not pass the type constraint okay';
-ok ! exception {
+lives_ok {
$bar->foo($foo);
-}, '... foo passed the type constraint okay';
+} '... foo passed the type constraint okay';
# if isa and does appear together, then see if Class->does(Role)
# if it does not,.. we have a conflict... so we die loudly
- ::ok ::exception {
+ ::dies_ok {
has 'foo' => (isa => 'Foo::Class', does => 'Bar::Class');
- }, '... cannot have a does() which is not done by the isa()';
+ } '... cannot have a does() which is not done by the isa()';
}
{
# if isa and does appear together, then see if Class->does(Role)
# if it does not,.. we have a conflict... so we die loudly
- ::ok ::exception {
+ ::dies_ok {
has 'foo' => (isa => 'Bling', does => 'Bar::Class');
- }, '... cannot have a isa() which is cannot does()';
+ } '... cannot have a isa() which is cannot does()';
}
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
}
#Yeah.. this doesn't work like this anymore, see below. (groditi)
-#like exception {
+#throws_ok {
# Foo->new(bar => 10, baz => undef);
-#}, qr/^Attribute \(baz\) is required and cannot be undef/, '... must supply all the required attribute';
+#} qr/^Attribute \(baz\) is required and cannot be undef/, '... must supply all the required attribute';
-#like exception {
+#throws_ok {
# Foo->new(bar => 10, boo => undef);
-#}, qr/^Attribute \(boo\) is required and cannot be undef/, '... must supply all the required attribute';
+#} qr/^Attribute \(boo\) is required and cannot be undef/, '... must supply all the required attribute';
-ok ! exception {
+lives_ok {
Foo->new(bar => 10, baz => undef);
-}, '... undef is a valid attribute value';
+} '... undef is a valid attribute value';
-ok ! exception {
+lives_ok {
Foo->new(bar => 10, boo => undef);
-}, '... undef is a valid attribute value';
+} '... undef is a valid attribute value';
-like exception {
+throws_ok {
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;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package Bar;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
has 'bar' => (metaclass => 'Bar::Meta::Attribute');
- }, '... the attribute metaclass need not be a Moose::Meta::Attribute as long as it behaves';
+ } '... the attribute metaclass need not be a Moose::Meta::Attribute as long as it behaves';
}
{
package Another::Foo;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
has 'foo' => (metaclass => 'Foo');
- }, '... the attribute metaclass alias worked correctly';
+ } '... the attribute metaclass alias worked correctly';
- ::ok ! ::exception {
+ ::lives_ok {
has 'bar' => (metaclass => 'Bar', is => 'bare');
- }, '... the attribute metaclass alias worked correctly';
+ } '... the attribute metaclass alias worked correctly';
}
{
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
my $foo = Foo->new;
isa_ok($foo, 'Foo');
-ok ! exception {
+lives_ok {
$foo->bar([])
-}, '... set bar successfully with an ARRAY ref';
+} '... set bar successfully with an ARRAY ref';
-ok ! exception {
+lives_ok {
$foo->bar({})
-}, '... set bar successfully with a HASH ref';
+} '... set bar successfully with a HASH ref';
-ok exception {
+dies_ok {
$foo->bar(100)
-}, '... couldnt set bar successfully with a number';
+} '... couldnt set bar successfully with a number';
-ok exception {
+dies_ok {
$foo->bar(sub {})
-}, '... couldnt set bar successfully with a CODE ref';
+} '... couldnt set bar successfully with a CODE ref';
# check the constructor
-ok ! exception {
+lives_ok {
Foo->new(bar => [])
-}, '... created new Foo with bar successfully set with an ARRAY ref';
+} '... created new Foo with bar successfully set with an ARRAY ref';
-ok ! exception {
+lives_ok {
Foo->new(bar => {})
-}, '... created new Foo with bar successfully set with a HASH ref';
+} '... created new Foo with bar successfully set with a HASH ref';
-ok exception {
+dies_ok {
Foo->new(bar => 50)
-}, '... didnt create a new Foo with bar as a number';
+} '... didnt create a new Foo with bar as a number';
-ok exception {
+dies_ok {
Foo->new(bar => sub {})
-}, '... didnt create a new Foo with bar as a CODE ref';
+} '... didnt create a new Foo with bar as a CODE ref';
{
package Bar;
my $bar = Bar->new;
isa_ok($bar, 'Bar');
-ok ! exception {
+lives_ok {
$bar->baz('a string')
-}, '... set baz successfully with a string';
+} '... set baz successfully with a string';
-ok ! exception {
+lives_ok {
$bar->baz(sub { 'a sub' })
-}, '... set baz successfully with a CODE ref';
+} '... set baz successfully with a CODE ref';
-ok exception {
+dies_ok {
$bar->baz(\(my $var1))
-}, '... couldnt set baz successfully with a SCALAR ref';
+} '... couldnt set baz successfully with a SCALAR ref';
-ok exception {
+dies_ok {
$bar->baz({})
-}, '... couldnt set bar successfully with a HASH ref';
+} '... couldnt set bar successfully with a HASH ref';
# check the constructor
-ok ! exception {
+lives_ok {
Bar->new(baz => 'a string')
-}, '... created new Bar with baz successfully set with a string';
+} '... created new Bar with baz successfully set with a string';
-ok ! exception {
+lives_ok {
Bar->new(baz => sub { 'a sub' })
-}, '... created new Bar with baz successfully set with a CODE ref';
+} '... created new Bar with baz successfully set with a CODE ref';
-ok exception {
+dies_ok {
Bar->new(baz => \(my $var2))
-}, '... didnt create a new Bar with baz as a number';
+} '... didnt create a new Bar with baz as a number';
-ok exception {
+dies_ok {
Bar->new(baz => {})
-}, '... didnt create a new Bar with baz as a HASH ref';
+} '... didnt create a new Bar with baz as a HASH ref';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
extends 'Foo';
- ::ok ! ::exception {
+ ::lives_ok {
has '+bar' => (default => 'Bar::bar');
- }, '... we can change the default attribute option';
+ } '... we can change the default attribute option';
- ::ok ! ::exception {
+ ::lives_ok {
has '+baz' => (isa => 'ArrayRef');
- }, '... we can add change the isa as long as it is a subtype';
+ } '... we can add change the isa as long as it is a subtype';
- ::ok ! ::exception {
+ ::lives_ok {
has '+foo' => (coerce => 1);
- }, '... we can change/add coerce as an attribute option';
+ } '... we can change/add coerce as an attribute option';
- ::ok ! ::exception {
+ ::lives_ok {
has '+gorch' => (required => 1);
- }, '... we can change/add required as an attribute option';
+ } '... we can change/add required as an attribute option';
- ::ok ! ::exception {
+ ::lives_ok {
has '+gloum' => (lazy => 1);
- }, '... we can change/add lazy as an attribute option';
+ } '... we can change/add lazy as an attribute option';
- ::ok ! ::exception {
+ ::lives_ok {
has '+fleem' => (lazy_build => 1);
- }, '... we can add lazy_build as an attribute option';
+ } '... we can add lazy_build as an attribute option';
- ::ok ! ::exception {
+ ::lives_ok {
has '+bunch_of_stuff' => (isa => 'ArrayRef[Int]');
- }, '... extend an attribute with parameterized type';
+ } '... extend an attribute with parameterized type';
- ::ok ! ::exception {
+ ::lives_ok {
has '+one_last_one' => (isa => subtype('Ref', where { blessed $_ eq 'CODE' }));
- }, '... extend an attribute with anon-subtype';
+ } '... extend an attribute with anon-subtype';
- ::ok ! ::exception {
+ ::lives_ok {
has '+one_last_one' => (isa => 'Value');
- }, '... now can extend an attribute with a non-subtype';
+ } '... now can extend an attribute with a non-subtype';
- ::ok ! ::exception {
+ ::lives_ok {
has '+fleem' => (weak_ref => 1);
- }, '... now allowed to add the weak_ref option via inheritance';
+ } '... now allowed to add the weak_ref option via inheritance';
- ::ok ! ::exception {
+ ::lives_ok {
has '+bling' => (handles => ['hello']);
- }, '... we can add the handles attribute option';
+ } '... we can add the handles attribute option';
# this one will *not* work here ....
- ::ok ::exception {
+ ::dies_ok {
has '+blang' => (handles => ['hello']);
- }, '... we can not alter the handles attribute option';
- ::ok ! ::exception {
+ } '... we can not alter the handles attribute option';
+ ::lives_ok {
has '+fail' => (isa => 'Ref');
- }, '... can now create an attribute with an improper subtype relation';
- ::ok ::exception {
+ } '... can now create an attribute with an improper subtype relation';
+ ::dies_ok {
has '+other_fail' => (trigger => sub {});
- }, '... cannot create an attribute with an illegal option';
- ::like ::exception {
+ } '... cannot create an attribute with an illegal option';
+ ::throws_ok {
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');
-ok ! exception { $foo->foo('FooString') }, '... assigned foo correctly';
+lives_ok { $foo->foo('FooString') } '... assigned foo correctly';
is($foo->foo, 'FooString', '... got the right value for foo');
-ok exception { $foo->foo([]) }, '... foo is not coercing (as expected)';
+dies_ok { $foo->foo([]) } '... foo is not coercing (as expected)';
is($foo->bar, 'Foo::bar', '... got the right default value');
-ok exception { $foo->bar(10) }, '... Foo::bar is a read/only attr';
+dies_ok { $foo->bar(10) } '... Foo::bar is a read/only attr';
is($foo->baz, undef, '... got the right undef default value');
{
my $hash_ref = {};
- ok ! exception { $foo->baz($hash_ref) }, '... Foo::baz accepts hash refs';
+ lives_ok { $foo->baz($hash_ref) } '... Foo::baz accepts hash refs';
is($foo->baz, $hash_ref, '... got the right value assigned to baz');
my $array_ref = [];
- ok ! exception { $foo->baz($array_ref) }, '... Foo::baz accepts an array ref';
+ lives_ok { $foo->baz($array_ref) } '... Foo::baz accepts an array ref';
is($foo->baz, $array_ref, '... got the right value assigned to baz');
my $scalar_ref = \(my $var);
- ok ! exception { $foo->baz($scalar_ref) }, '... Foo::baz accepts scalar ref';
+ lives_ok { $foo->baz($scalar_ref) } '... Foo::baz accepts scalar ref';
is($foo->baz, $scalar_ref, '... got the right value assigned to baz');
- ok ! exception { $foo->bunch_of_stuff([qw[one two three]]) }, '... Foo::bunch_of_stuff accepts an array of strings';
+ lives_ok { $foo->bunch_of_stuff([qw[one two three]]) } '... Foo::bunch_of_stuff accepts an array of strings';
- ok ! exception { $foo->one_last_one(sub { 'Hello World'}) }, '... Foo::one_last_one accepts a code ref';
+ lives_ok { $foo->one_last_one(sub { 'Hello World'}) } '... Foo::one_last_one accepts a code ref';
my $code_ref = sub { 1 };
- ok ! exception { $foo->baz($code_ref) }, '... Foo::baz accepts a code ref';
+ lives_ok { $foo->baz($code_ref) } '... Foo::baz accepts a code ref';
is($foo->baz, $code_ref, '... got the right value assigned to baz');
}
-ok exception {
+dies_ok {
Bar->new;
-}, '... cannot create Bar without required gorch param';
+} '... 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');
-ok ! exception { $bar->foo('FooString') }, '... assigned foo correctly';
+lives_ok { $bar->foo('FooString') } '... assigned foo correctly';
is($bar->foo, 'FooString', '... got the right value for foo');
-ok ! exception { $bar->foo([]) }, '... assigned foo correctly';
+lives_ok { $bar->foo([]) } '... 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');
-ok exception { $bar->bar(10) }, '... Bar::bar is a read/only attr';
+dies_ok { $bar->bar(10) } '... Bar::bar is a read/only attr';
is($bar->baz, undef, '... got the right undef default value');
{
my $hash_ref = {};
- ok exception { $bar->baz($hash_ref) }, '... Bar::baz does not accept hash refs';
+ dies_ok { $bar->baz($hash_ref) } '... Bar::baz does not accept hash refs';
my $array_ref = [];
- ok ! exception { $bar->baz($array_ref) }, '... Bar::baz can accept an array ref';
+ lives_ok { $bar->baz($array_ref) } '... Bar::baz can accept an array ref';
is($bar->baz, $array_ref, '... got the right value assigned to baz');
my $scalar_ref = \(my $var);
- ok exception { $bar->baz($scalar_ref) }, '... Bar::baz does not accept a scalar ref';
+ dies_ok { $bar->baz($scalar_ref) } '... Bar::baz does not accept a scalar ref';
- ok ! exception { $bar->bunch_of_stuff([1, 2, 3]) }, '... Bar::bunch_of_stuff accepts an array of ints';
- ok exception { $bar->bunch_of_stuff([qw[one two three]]) }, '... Bar::bunch_of_stuff does not accept an array of strings';
+ 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';
my $code_ref = sub { 1 };
- ok exception { $bar->baz($code_ref) }, '... Bar::baz does not accept a code ref';
+ dies_ok { $bar->baz($code_ref) } '... Bar::baz does not accept a code ref';
}
# check some meta-stuff
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
# -------------------------------------------------------------------
is($foo->bar, 25, '... got the right foo->bar');
-ok ! exception {
+lives_ok {
$bar->foo($foo);
-}, '... assigned the new Foo to Bar->foo';
+} '... assigned the new Foo to Bar->foo';
is($bar->foo, $foo, '... assigned bar->foo with the new Foo');
package Goorch::Autoloaded;
use Moose;
- ::ok ::exception {
+ ::dies_ok {
has 'foo' => (
is => 'rw',
default => sub { Foo::Autoloaded->new },
handles => qr/bar/
);
- }, '... you cannot delegate to AUTOLOADED class with regexp';
+ } '... you cannot delegate to AUTOLOADED class with regexp';
}
# check HASH based delegation w/ AUTOLOAD
is($foo->bar, 25, '... got the right foo->bar');
- ok ! exception {
+ lives_ok {
$bar->foo($foo);
- }, '... assigned the new Foo to Bar->foo';
+ } '... assigned the new Foo to Bar->foo';
is($bar->foo, $foo, '... assigned bar->foo with the new Foo');
is($foo->bar, 25, '... got the right foo->bar');
- ok ! exception {
+ lives_ok {
$baz->foo($foo);
- }, '... assigned the new Foo to Baz->foo';
+ } '... assigned the new Foo to Baz->foo';
is($baz->foo, $foo, '... assigned baz->foo with the new Foo');
# not an object
{
my $i = Bar->new(foo => undef);
- like exception { $i->foo_bar }, qr/is not defined/,
+ throws_ok { $i->foo_bar } qr/is not defined/,
'useful error from unblessed reference';
my $j = Bar->new(foo => []);
- like exception { $j->foo_bar }, qr/is not an object \(got 'ARRAY/,
+ throws_ok { $j->foo_bar } qr/is not an object \(got 'ARRAY/,
'useful error from unblessed reference';
my $k = Bar->new(foo => "Foo");
- ok ! exception { $k->foo_baz }, "but not for class name";
+ lives_ok { $k->foo_baz } "but not for class name";
}
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
=pod
sub parent_method_1 { "parent_1" }
::can_ok('Parent', 'parent_method_1');
- ::ok ::exception {
+ ::dies_ok {
has child_a => (
is => "ro",
default => sub { ChildA->new },
handles => qr/.*/,
);
- }, "all_methods requires explicit isa";
+ } "all_methods requires explicit isa";
- ::ok ! ::exception {
+ ::lives_ok {
has child_a => (
isa => "ChildA",
is => "ro",
default => sub { ChildA->new },
handles => qr/.*/,
);
- }, "allow all_methods with explicit isa";
+ } "allow all_methods with explicit isa";
- ::ok ! ::exception {
+ ::lives_ok {
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";
+ } "don't need to declare isa if method list is predefined";
- ::ok ! ::exception {
+ ::lives_ok {
has child_c => (
isa => "ChildC",
is => "ro",
default => sub { ChildC->new },
handles => qr/_la$/,
);
- }, "can declare regex collector";
+ } "can declare regex collector";
- ::ok ::exception {
+ ::dies_ok {
has child_d => (
is => "ro",
default => sub { ChildD->new },
my ( $class, $delegate_class ) = @_;
}
);
- }, "can't create attr with generative handles parameter and no isa";
+ } "can't create attr with generative handles parameter and no isa";
- ::ok ! ::exception {
+ ::lives_ok {
has child_d => (
isa => "ChildD",
is => "ro",
return;
}
);
- }, "can't create attr with generative handles parameter and no isa";
+ } "can't create attr with generative handles parameter and no isa";
- ::ok ! ::exception {
+ ::lives_ok {
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";
+ } "can delegate to non moose class using explicit method list";
my $delegate_class;
- ::ok ! ::exception {
+ ::lives_ok {
has child_f => (
isa => "ChildF",
is => "ro",
return;
},
);
- }, "subrefs on non moose class give no meta";
+ } "subrefs on non moose class give no meta";
::is( $delegate_class, "ChildF", "plain classes are handed down to subs" );
- ::ok ! ::exception {
+ ::lives_ok {
has child_g => (
isa => "ChildG",
default => sub { ChildG->new },
handles => ["child_g_method_1"],
);
- }, "can delegate to object even without explicit reader";
+ } "can delegate to object even without explicit reader";
::can_ok('Parent', 'parent_method_1');
- ::ok ::exception {
+ ::dies_ok {
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";
+ } "Can't override exisiting class method in delegate";
::can_ok('Parent', 'parent_method_1');
- ::ok ! ::exception {
+ ::lives_ok {
has child_i => (
isa => "ChildI",
is => "ro",
$_[1]->get_all_method_names;
},
);
- }, "Test handles code ref for skipping predefined methods";
+ } "Test handles code ref for skipping predefined methods";
sub parent_method { "p" }
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
my $test = Test::For::Lazy::TypeConstraint->new;
isa_ok($test, 'Test::For::Lazy::TypeConstraint');
- ok exception {
+ dies_ok {
$test->bad_lazy_attr;
- }, '... this does not work';
+ } '... this does not work';
- ok ! exception {
+ lives_ok {
$test->good_lazy_attr;
- }, '... this does not work';
+ } '... this does not work';
}
{
}
- ok exception {
+ dies_ok {
Test::UndefDefault::Attributes->new;
- }, '... default must return a value which passes the type constraint';
+ } '... default must return a value which passes the type constraint';
}
is($moose_obj->a_str( 'foobar' ), 'foobar', 'setter took string');
ok($moose_obj, 'this is a *not* a string');
- like exception {
+ throws_ok {
$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.+?\)/,
+ } 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';
}
has 'a_num' => ( isa => 'Int' , is => 'rw', default => 7.5 );
}
- like exception {
+ throws_ok {
OverloadBreaker->new;
- }, qr/Attribute \(a_num\) does not pass the type constraint because\: Validation failed for 'Int' with value 7\.5/,
+ } 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 ';
- ok ! exception {
+ lives_ok {
OverloadBreaker->new(a_num => 5);
- }, '... this works fine though';
+ } '... this works fine though';
}
has 'foo' => ( required => 1, builder => 'build_foo', is => 'ro');
}
- ok exception {
+ dies_ok {
Test::Builder::Attribute::Broken->new;
- }, '... no builder, wtf';
+ } '... no builder, wtf';
}
ok(!$instance->_has_foo, "noo _foo value yet");
is($instance->foo, 'works', "foo builder works");
is($instance->_foo, 'works too', "foo builder works too");
- like exception { $instance->fool },
+ 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";
use Moose;
}
-ok ! exception { OutOfClassTest::has('foo', is => 'bare'); }, 'create attr via direct sub call';
-ok ! exception { OutOfClassTest->can('has')->('bar', is => 'bare'); }, 'create attr via can';
+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';
ok(OutOfClassTest->meta->get_attribute('foo'), 'attr created from sub call');
ok(OutOfClassTest->meta->get_attribute('bar'), 'attr created from can');
package Foo;
use Moose;
- ::like ::exception { has 'foo' => ( 'ro', isa => 'Str' ) },
+ ::throws_ok { has 'foo' => ( 'ro', isa => 'Str' ) }
qr/^Usage/, 'has throws error with odd number of attribute options';
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
use Moose;
use Moose::Util::TypeConstraints;
- ::ok ! ::exception {
+ ::lives_ok {
has 'customers' => (
is => 'ro',
isa => subtype('ArrayRef' => where {
(blessed($_) && $_->isa('Customer') || return) for @$_; 1 }),
auto_deref => 1,
);
- }, '... successfully created attr';
+ } '... successfully created attr';
}
{
{
my $autoderef = AutoDeref->new;
- ok exception {
+ dies_ok {
$autoderef->bar(1, 2, 3);
- }, '... its auto-de-ref-ing, not auto-en-ref-ing';
+ } '... its auto-de-ref-ing, not auto-en-ref-ing';
- ok ! exception {
+ lives_ok {
$autoderef->bar([ 1, 2, 3 ])
- }, '... set the results of bar correctly';
+ } '... set the results of bar correctly';
is_deeply [ $autoderef->bar ], [ 1, 2, 3 ], '... auto-dereffed correctly';
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
my $r = Request->new;
isa_ok($r, 'Request');
-ok ! exception {
+lives_ok {
$r->headers;
-}, '... this coerces and passes the type constraint even with lazy';
+} '... this coerces and passes the type constraint even with lazy';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
__PACKAGE__->meta->make_immutable;
}
-ok exception {
+dies_ok {
Fail::Bar->new(foo => 10)
-}, '... this fails, because initializer returns a bad type';
+} '... this fails, because initializer returns a bad type';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
=pod
$obj = $class->new();
can_ok($obj, qw/foo _foo/);
-ok ! exception {$obj->_foo(1)}, "$class->_foo is writer";
+lives_ok {$obj->_foo(1)} "$class->_foo is writer";
is($obj->foo(), 1, "$class->foo is reader");
-ok exception {$obj->foo(2)}, "$class->foo is not writer"; # this should fail
+dies_ok {$obj->foo(2)} "$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');
$obj = $class->new();
can_ok($obj, qw/foo _foo/);
-ok ! exception {$obj->_foo(1)}, "$class->_foo is writer";
+lives_ok {$obj->_foo(1)} "$class->_foo is writer";
is($obj->foo(), 1, "$class->foo is reader");
-ok exception {$obj->foo(1)}, "$class->foo is not writer";
+dies_ok {$obj->foo(1)} "$class->foo is not writer";
isnt($obj->_foo(), 1, "$class->_foo is not reader");
$class = make_class('rw', 'accessor', 'Test::Class::AccessorRW');
$obj = $class->new();
can_ok($obj, qw/_foo/);
-ok ! exception {$obj->_foo(1)}, "$class->_foo is writer";
+lives_ok {$obj->_foo(1)} "$class->_foo is writer";
is($obj->_foo(), 1, "$class->foo is reader");
-ok exception { make_class('ro', 'accessor', "Test::Class::AccessorRO"); }, "Cant define attr with ro + accessor";
+dies_ok { make_class('ro', 'accessor', "Test::Class::AccessorRO"); } "Cant define attr with ro + accessor";
done_testing;
use strict;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package Foo;
extends 'Foo';
- ::ok ! ::exception { has '+foo' => (is => 'rw') }, "can override is";
- ::like ::exception { has '+foo' => (reader => 'bar') }, qr/illegal/, "can't override reader";
- ::ok ! ::exception { has '+foo' => (clearer => 'baz') }, "can override unspecified things";
+ ::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";
- ::like ::exception { has '+bar' => (clearer => 'quux') }, qr/illegal/, "can't override clearer";
- ::ok ! ::exception { has '+bar' => (predicate => 'has_bar') }, "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";
}
{
package Bar;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
has bar => (
traits => ['Bar::Meta::Attribute'],
my_illegal_option => 'FOO',
is => 'bare',
);
- }, "can use illegal options";
+ } "can use illegal options";
has baz => (
traits => ['Bar::Meta::Attribute'],
extends 'Bar';
- ::like ::exception { has '+bar' => (my_illegal_option => 'BAR') },
+ ::throws_ok { has '+bar' => (my_illegal_option => 'BAR') }
qr/illegal/,
"can't override illegal attribute";
- ::ok ! ::exception { has '+baz' => (my_illegal_option => 'BAR') },
+ ::lives_ok { has '+baz' => (my_illegal_option => 'BAR') }
"can add illegal option if superclass doesn't set it";
}
use strict;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
my $exception_regex = qr/You must provide a name for the attribute/;
{
package My::Role;
use Moose::Role;
- ::like ::exception {
+ ::throws_ok {
has;
- }, $exception_regex, 'has; fails';
+ } $exception_regex, 'has; fails';
- ::like ::exception {
+ ::throws_ok {
has undef;
- }, $exception_regex, 'has undef; fails';
+ } $exception_regex, 'has undef; fails';
- ::ok ! ::exception {
+ ::lives_ok {
has "" => (
is => 'bare',
);
- }, 'has ""; works now';
+ } 'has ""; works now';
- ::ok ! ::exception {
+ ::lives_ok {
has 0 => (
is => 'bare',
);
- }, 'has 0; works now';
+ } 'has 0; works now';
}
{
package My::Class;
use Moose;
- ::like ::exception {
+ ::throws_ok {
has;
- }, $exception_regex, 'has; fails';
+ } $exception_regex, 'has; fails';
- ::like ::exception {
+ ::throws_ok {
has undef;
- }, $exception_regex, 'has undef; fails';
+ } $exception_regex, 'has undef; fails';
- ::ok ! ::exception {
+ ::lives_ok {
has "" => (
is => 'bare',
);
- }, 'has ""; works now';
+ } 'has ""; works now';
- ::ok ! ::exception {
+ ::lives_ok {
has 0 => (
is => 'bare',
);
- }, 'has 0; works now';
+ } 'has 0; works now';
}
done_testing;
use Moose::Util::MetaRole;
use Test::More;
- use Test::Fatal;
+ use Test::Exception;
Moose::Util::MetaRole::apply_metaroles(
for => __PACKAGE__,
class_metaroles => { instance => ['MooseX::SomeAwesomeDBFields'] },
);
- ok ! exception {
+ lives_ok {
has lazy_attr => (
is => 'ro',
isa => 'Bool',
lazy => 1,
default => sub {0},
);
- },
+ }
"Adding lazy accessor does not use inline_slot_access";
- ok ! exception {
+ lives_ok {
has rw_attr => (
is => 'rw',
);
- },
+ }
"Adding read-write accessor does not use inline_slot_access";
- ok ! exception { __PACKAGE__->meta->make_immutable; },
+ lives_ok { __PACKAGE__->meta->make_immutable; }
"Inling constructor does not use inline_slot_access";
done_testing;
use strict;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
-ok ! exception {
+lives_ok {
package My::Class;
use Moose;
auto_deref => 1,
);
-}, 'class definition';
+} 'class definition';
-ok ! exception {
+lives_ok {
my $o = My::Class->new();
is_deeply [scalar $o->s_rw], [undef], 'uninitialized scalar attribute/rw in scalar context';
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';
+} 'testing';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Meta::Role;
use Moose::Util::TypeConstraints ();
ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
-ok ! exception {
+lives_ok {
$foo_role->add_attribute('bar' => (is => 'rw', isa => 'Foo'));
-}, '... added the bar attribute okay';
+} '... added the bar attribute okay';
is_deeply(
[ $foo_role->get_attribute_list() ],
'bar has a Foo class type'
);
-ok ! exception {
+lives_ok {
$foo_role->add_attribute('baz' => (is => 'ro'));
-}, '... added the baz attribute okay';
+} '... added the baz attribute okay';
is_deeply(
[ sort $foo_role->get_attribute_list() ],
is_deeply( $baz->original_options, { is => 'ro' },
'original options for baz attribute' );
-ok ! exception {
+lives_ok {
$foo_role->remove_attribute('bar');
-}, '... removed the bar attribute okay';
+} '... removed the bar attribute okay';
is_deeply(
[ $foo_role->get_attribute_list() ],
ok(!$foo_role->has_before_method_modifiers('boo'), '... no boo:before modifier');
my $method = sub { "FooRole::boo:before" };
-ok ! exception {
+lives_ok {
$foo_role->add_before_method_modifier('boo' => $method);
-}, '... added a method modifier okay';
+} '... 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');
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
=pod
override 'bling' => sub { "FooRole::bling:override" };
override 'fling' => sub { "FooRole::fling:override" };
- ::ok ::exception { extends() }, '... extends() is not supported';
- ::ok ::exception { augment() }, '... augment() is not supported';
- ::ok ::exception { inner() }, '... inner() is not supported';
+ ::dies_ok { extends() } '... extends() is not supported';
+ ::dies_ok { augment() } '... augment() is not supported';
+ ::dies_ok { inner() } '... inner() is not supported';
no Moose::Role;
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package FooRole;
extends 'BarClass';
- ::like ::exception { with 'FooRole' => { -version => 42 } },
+ ::throws_ok { with 'FooRole' => { -version => 42 } }
qr/FooRole version 42 required--this is only version 23/,
'applying role with unsatisfied version requirement';
- ::ok ! ::exception { with 'FooRole' => { -version => 13 } },
+ ::lives_ok { with 'FooRole' => { -version => 13 } }
'applying role with satisfied version requirement';
sub blau {'FooClass::blau'} # << the role wraps this ...
my $foobar_class_meta = FooBarClass->meta;
isa_ok( $foobar_class_meta, 'Moose::Meta::Class' );
-ok exception {
+dies_ok {
$foo_class_meta->does_role();
-},
+}
'... does_role requires a role name';
-ok exception {
+dies_ok {
$foo_class_meta->add_role();
-},
+}
'... apply_role requires a role';
-ok exception {
+dies_ok {
$foo_class_meta->add_role( bless( {} => 'Fail' ) );
-},
+}
'... apply_role requires a role';
ok( $foo_class_meta->does_role('FooRole'),
ok( !defined( $foo->baz ), '... $foo->baz is undefined' );
ok( !defined( $foo->bar ), '... $foo->bar is undefined' );
- ok exception {
+ dies_ok {
$foo->baz(1);
- },
+ }
'... baz is a read-only accessor';
- ok exception {
+ dies_ok {
$foo->bar(1);
- },
+ }
'... bar is a read-write accessor with a type constraint';
my $foo2 = FooClass->new();
isa_ok( $foo2, 'FooClass' );
- ok ! exception {
+ lives_ok {
$foo->bar($foo2);
- },
+ }
'... bar is a read-write accessor with a type constraint';
is( $foo->bar, $foo2, '... got the right value for bar now' );
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package Foo::Class;
use Moose;
- ::ok ::exception { with('Foo::Role') },
+ ::dies_ok { with('Foo::Role') }
'... no foo method implemented by Foo::Class';
}
package Bar::Class;
use Moose;
- ::ok ::exception { with('Foo::Class') },
+ ::dies_ok { with('Foo::Class') }
'... cannot consume a class, it must be a role';
- ::ok ! ::exception { with('Foo::Role') },
+ ::lives_ok { with('Foo::Role') }
'... has a foo method implemented by Bar::Class';
sub foo {'Bar::Class::foo'}
package Bar::Role;
use Moose::Role;
- ::ok ! ::exception { with('Foo::Role') },
+ ::lives_ok { with('Foo::Role') }
'... has a foo method implemented by Bar::Role';
sub foo {'Bar::Role::foo'}
package Baz::Role;
use Moose::Role;
- ::ok ! ::exception { with('Foo::Role') },
+ ::lives_ok { with('Foo::Role') }
'... no foo method implemented by Baz::Role';
}
package Baz::Class;
use Moose;
- ::ok ::exception { with('Baz::Role') },
+ ::dies_ok { with('Baz::Role') }
'... no foo method implemented by Baz::Class2';
}
package Baz::Class2;
use Moose;
- ::ok ! ::exception { with('Baz::Role') },
+ ::lives_ok { with('Baz::Role') }
'... has a foo method implemented by Baz::Class2';
sub foo {'Baz::Class2::foo'}
package Quux::Class;
use Moose;
- ::like ::exception { with('Quux::Role') },
+ ::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';
}
sub meth1 { }
- ::like ::exception { with('Quux::Role') },
+ ::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';
}
has 'meth1' => ( is => 'ro' );
has 'meth2' => ( is => 'ro' );
- ::like ::exception { with('Quux::Role') },
+ ::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';
}
sub meth1 { }
has 'meth2' => ( is => 'ro' );
- ::like ::exception { with('Quux::Role') },
+ ::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';
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
=pod
package My::Test1;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Foo', 'Role::Bar';
- }, '... our mutually recursive roles combine okay';
+ } '... our mutually recursive roles combine okay';
package My::Test2;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Bar', 'Role::Foo';
- }, '... our mutually recursive roles combine okay (no matter what order)';
+ } '... our mutually recursive roles combine okay (no matter what order)';
}
my $test1 = My::Test1->new;
package My::Test3;
use Moose;
- ::like ::exception {
+ ::throws_ok {
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;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Bling';
with 'Role::Bling::Bling';
- }, '... role methods didnt conflict when manually combined';
+ } '... role methods didnt conflict when manually combined';
package My::Test5;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Bling::Bling';
with 'Role::Bling';
- }, '... role methods didnt conflict when manually combined (in opposite order)';
+ } '... role methods didnt conflict when manually combined (in opposite order)';
package My::Test6;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Bling::Bling', 'Role::Bling';
- }, '... role methods didnt conflict when manually resolved';
+ } '... role methods didnt conflict when manually resolved';
sub bling { 'My::Test6::bling' }
}
package My::Test7;
use Moose;
- ::like ::exception {
+ ::throws_ok {
with 'Role::Boo', 'Role::Boo::Hoo';
}, qr/We have encountered an attribute conflict.+ghost/,
- '... role attrs conflict and method was required';
package My::Test8;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Boo';
with 'Role::Boo::Hoo';
- }, '... role attrs didnt conflict when manually combined';
+ } '... role attrs didnt conflict when manually combined';
package My::Test9;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Boo::Hoo';
with 'Role::Boo';
- }, '... role attrs didnt conflict when manually combined';
+ } '... role attrs didnt conflict when manually combined';
package My::Test10;
use Moose;
has 'ghost' => (is => 'ro', default => 'My::Test10::ghost');
- ::like ::exception {
+ ::throws_ok {
with 'Role::Boo', 'Role::Boo::Hoo';
- }, qr/We have encountered an attribute conflict/,
+ } qr/We have encountered an attribute conflict/,
'... role attrs conflict and cannot be manually disambiguted';
}
extends 'My::Test::Base';
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Truth';
- }, '... composed the role with override okay';
+ } '... composed the role with override okay';
package My::Test12;
use Moose;
extends 'My::Test::Base';
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Plot';
- }, '... composed the role with override okay';
+ } '... composed the role with override okay';
package My::Test13;
use Moose;
- ::ok ::exception {
+ ::dies_ok {
with 'Role::Plot';
- }, '... cannot compose it because we have no superclass';
+ } '... cannot compose it because we have no superclass';
package My::Test14;
use Moose;
extends 'My::Test::Base';
- ::like ::exception {
+ ::throws_ok {
with 'Role::Plot', 'Role::Truth';
- }, qr/Two \'override\' methods of the same name encountered/,
+ } qr/Two \'override\' methods of the same name encountered/,
'... cannot compose it because we have no superclass';
}
package Role::Reality;
use Moose::Role;
- ::like ::exception {
+ ::throws_ok {
with 'Role::Plot';
- }, qr/A local method of the same name as been found/,
+ } qr/A local method of the same name as been found/,
'... could not compose roles here, it dies';
sub twist {
package Conflicts;
use Moose;
- ::like ::exception {
+ ::throws_ok {
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
package My::Test15;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Method';
- }, '... composed the method role into the method class';
+ } '... composed the method role into the method class';
sub ghost { 'My::Test15::ghost' }
package My::Test16;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Method';
- }, '... composed the method role into the attribute class';
+ } '... composed the method role into the attribute class';
has 'ghost' => (is => 'ro', default => 'My::Test16::ghost');
package My::Test17;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Attribute';
- }, '... composed the attribute role into the method class';
+ } '... composed the attribute role into the method class';
sub ghost { 'My::Test17::ghost' }
package My::Test18;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Attribute';
- }, '... composed the attribute role into the attribute class';
+ } '... composed the attribute role into the attribute class';
has 'ghost' => (is => 'ro', default => 'My::Test18::ghost');
package My::Test19;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Method', 'Role::Method2';
- }, '... composed method roles into class with method tiebreaker';
+ } '... composed method roles into class with method tiebreaker';
sub ghost { 'My::Test19::ghost' }
package My::Test20;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Method', 'Role::Method2';
- }, '... composed method roles into class with attribute tiebreaker';
+ } '... composed method roles into class with attribute tiebreaker';
has 'ghost' => (is => 'ro', default => 'My::Test20::ghost');
package My::Test21;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Attribute', 'Role::Attribute2';
- }, '... composed attribute roles into class with method tiebreaker';
+ } '... composed attribute roles into class with method tiebreaker';
sub ghost { 'My::Test21::ghost' }
package My::Test22;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Attribute', 'Role::Attribute2';
- }, '... composed attribute roles into class with attribute tiebreaker';
+ } '... composed attribute roles into class with attribute tiebreaker';
has 'ghost' => (is => 'ro', default => 'My::Test22::ghost');
package My::Test23;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Method', 'Role::Attribute';
- }, '... composed method and attribute role into class with method tiebreaker';
+ } '... composed method and attribute role into class with method tiebreaker';
sub ghost { 'My::Test23::ghost' }
package My::Test24;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Method', 'Role::Attribute';
- }, '... composed method and attribute role into class with attribute tiebreaker';
+ } '... composed method and attribute role into class with attribute tiebreaker';
has 'ghost' => (is => 'ro', default => 'My::Test24::ghost');
package My::Test25;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Attribute', 'Role::Method';
- }, '... composed attribute and method role into class with method tiebreaker';
+ } '... composed attribute and method role into class with method tiebreaker';
sub ghost { 'My::Test25::ghost' }
package My::Test26;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Attribute', 'Role::Method';
- }, '... composed attribute and method role into class with attribute tiebreaker';
+ } '... composed attribute and method role into class with attribute tiebreaker';
has 'ghost' => (is => 'ro', default => 'My::Test26::ghost');
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
=pod
package My::Test1;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Molecule::Organic';
- }, '... adding the role (w/ excluded roles) okay';
+ } '... adding the role (w/ excluded roles) okay';
package My::Test2;
use Moose;
- ::like ::exception {
+ ::throws_ok {
with 'Molecule::Organic', 'Molecule::Inorganic';
- }, qr/Conflict detected: Role Molecule::Organic excludes role 'Molecule::Inorganic'/,
+ } qr/Conflict detected: Role Molecule::Organic excludes role 'Molecule::Inorganic'/,
'... adding the role w/ excluded role conflict dies okay';
package My::Test3;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Molecule::Organic';
- }, '... adding the role (w/ excluded roles) okay';
+ } '... adding the role (w/ excluded roles) okay';
- ::like ::exception {
+ ::throws_ok {
with 'Molecule::Inorganic';
- }, qr/Conflict detected: My::Test3 excludes role 'Molecule::Inorganic'/,
+ } qr/Conflict detected: My::Test3 excludes role 'Molecule::Inorganic'/,
'... adding the role w/ excluded role conflict dies okay';
}
extends 'Methane';
- ::like ::exception {
+ ::throws_ok {
with 'Molecule::Inorganic';
- }, qr/Conflict detected: My::Test4 excludes role \'Molecule::Inorganic\'/,
+ } qr/Conflict detected: My::Test4 excludes role \'Molecule::Inorganic\'/,
'... cannot add exculded role into class which extends Methane';
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
=pod
use warnings;
use Moose::Role;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::RequireFoo';
- }, '... the required "foo" method will not exist yet (but we will live)';
+ } '... the required "foo" method will not exist yet (but we will live)';
override 'foo' => sub { 'Role::ProvideFoo::foo' };
}
extends 'Class::ProvideFoo::Base';
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::RequireFoo';
- }, '... the required "foo" method will be found in the superclass';
+ } '... the required "foo" method will be found in the superclass';
override 'foo' => sub { 'Class::ProvideFoo::foo' };
override 'foo' => sub { 'Class::ProvideFoo::foo' };
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::RequireFoo';
- }, '... the required "foo" method exists, although it is overriden locally';
+ } '... the required "foo" method exists, although it is overriden locally';
}
extends 'Class::ProvideFoo::Base';
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::RequireFoo';
- }, '... the required "foo" method will be found in the superclass';
+ } '... the required "foo" method will be found in the superclass';
before 'foo' => sub { 'Class::ProvideFoo::foo:before' };
before 'foo' => sub { 'Class::ProvideFoo::foo:before' };
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::RequireFoo';
- }, '... the required "foo" method exists, although it is a before modifier locally';
+ } '... the required "foo" method exists, although it is a before modifier locally';
package Class::ProvideFoo::Before3;
use Moose;
sub foo { 'Class::ProvideFoo::foo' }
before 'foo' => sub { 'Class::ProvideFoo::foo:before' };
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::RequireFoo';
- }, '... the required "foo" method exists locally, and it is modified locally';
+ } '... the required "foo" method exists locally, and it is modified locally';
package Class::ProvideFoo::Before4;
use Moose;
::is(__PACKAGE__->meta->get_method('foo')->get_original_method->package_name, __PACKAGE__,
'... but the original method is from our package');
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::RequireFoo';
- }, '... the required "foo" method exists in the symbol table (and we will live)';
+ } '... the required "foo" method exists in the symbol table (and we will live)';
}
extends 'Class::ProvideFoo::Base';
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::RequireFoo';
- }, '... the required "foo" method will be found in the superclass (but then overriden)';
+ } '... the required "foo" method will be found in the superclass (but then overriden)';
has 'foo' => (is => 'ro');
has 'foo' => (is => 'ro');
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::RequireFoo';
- }, '... the required "foo" method exists, and is an accessor';
+ } '... the required "foo" method exists, and is an accessor';
}
# ...
use Moose;
extends 'Foo::Class::Base';
- ::ok ! ::exception {
+ ::lives_ok {
with 'Foo::Role';
- }, '... our role combined successfully';
+ } '... our role combined successfully';
}
# a method required in a role and implemented in a superclass, with a method
use Moose;
extends 'Bar::Class::Base';
after bar => sub { "o noes" };
- # technically we could run ok exception {} here, too, but putting it into a
+ # technically we could run lives_ok here, too, but putting it into a
# grandchild class makes it more obvious why this matters.
}
{
package Bar::Class::Grandchild;
use Moose;
extends 'Bar::Class::Child';
- ::ok ! ::exception {
+ ::lives_ok {
with 'Bar::Role';
- }, 'required method exists in superclass as non-modifier, so we live';
+ } 'required method exists in superclass as non-modifier, so we live';
}
{
use Moose;
extends 'Bar2::Class::Base';
override bar => sub { "o noes" };
- # technically we could run ok exception {} here, too, but putting it into a
+ # technically we could run lives_ok here, too, but putting it into a
# grandchild class makes it more obvious why this matters.
}
{
package Bar2::Class::Grandchild;
use Moose;
extends 'Bar2::Class::Child';
- ::ok ! ::exception {
+ ::lives_ok {
with 'Bar2::Role';
- }, 'required method exists in superclass as non-modifier, so we live';
+ } 'required method exists in superclass as non-modifier, so we live';
}
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
=pod
package My::Test::Class1;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Derived1', 'Role::Derived2';
- }, '... roles composed okay (no conflicts)';
+ } '... roles composed okay (no conflicts)';
}
ok(Role::Base->meta->has_method('foo'), '... have the method foo as expected');
extends 'My::Test::Class2::Base';
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Derived3', 'Role::Derived4';
- }, '... roles composed okay (no conflicts)';
+ } '... roles composed okay (no conflicts)';
}
ok(Role::Base2->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
extends 'My::Test::Class3::Base';
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Derived5', 'Role::Derived6';
- }, '... roles composed okay (no conflicts)';
+ } '... roles composed okay (no conflicts)';
}
ok(Role::Base3->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
package My::Test::Class4;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::Derived7', 'Role::Derived8';
- }, '... roles composed okay (no conflicts)';
+ } '... roles composed okay (no conflicts)';
}
ok(Role::Base4->meta->has_attribute('foo'), '... have the attribute foo as expected');
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package SubAB;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with "SubAA", "RootA";
- }, '... role was composed as expected';
+ } '... role was composed as expected';
}
ok( SubAB->does("SubAA"), "does SubAA");
can_ok( $i, "foo" );
my $foo_rv;
- ok ! exception {
+ lives_ok {
$foo_rv = $i->foo;
- }, '... called foo successfully';
+ } '... called foo successfully';
is($foo_rv, "RootA::foo", "... got the right foo rv");
}
package SubBB;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with "SubBA";
- }, '... composed the role successfully';
+ } '... composed the role successfully';
}
ok( SubBB->does("SubBA"), "BB does SubBA" );
can_ok( $i, "foo" );
my $foo_rv;
- ok ! exception {
+ lives_ok {
$foo_rv = $i->foo
- }, '... called foo successfully';
+ } '... called foo successfully';
is( $foo_rv, "RootB::foo", "foo rv" );
is( $i->counter, 1, "after hook called" );
- ok ! exception { $i->foo }, '... called foo successfully (again)';
+ lives_ok { $i->foo } '... called foo successfully (again)';
is( $i->counter, 2, "after hook called (again)" );
ok(SubBA->meta->has_method('foo'), '... this has the foo method');
#my $subba_foo_rv;
- #ok ! exception {
+ #lives_ok {
# $subba_foo_rv = SubBA::foo();
- #}, '... called the sub as a function correctly';
+ #} '... called the sub as a function correctly';
#is($subba_foo_rv, 'RootB::foo', '... the SubBA->foo is still the RootB version');
}
with "RootC";
- ::ok ::exception {
+ ::dies_ok {
override foo => sub { "overridden" };
- }, '... cannot compose an override over a local method';
+ } '... cannot compose an override over a local method';
}
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package Role::C;
use Moose::Role;
- ::ok ! ::exception {
+ ::lives_ok {
with qw(Role::A Role::B); # no conflict here
- }, "define role C";
+ } "define role C";
sub foo { 'Role::C::foo' }
sub zot { 'Role::C::zot' }
package Class::A;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with qw(Role::C);
- }, "define class A";
+ } "define class A";
sub zot { 'Class::A::zot' }
}
package Class::A::Conflict;
use Moose;
- ::like ::exception {
+ ::throws_ok {
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;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Role::A::Conflict';
- }, '... did fufill the requirement of &bar method';
+ } '... did fufill the requirement of &bar method';
sub bar { 'Class::A::Resolved::bar' }
}
package Role::F;
use Moose::Role;
- ::ok ! ::exception {
+ ::lives_ok {
with qw(Role::D Role::E); # conflict between 'foo's here
- }, "define role Role::F";
+ } "define role Role::F";
sub foo { 'Role::F::foo' }
sub zot { 'Role::F::zot' }
package Class::B;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with qw(Role::F);
- }, "define class Class::B";
+ } "define class Class::B";
sub zot { 'Class::B::zot' }
}
package Role::D::And::E::Conflict;
use Moose::Role;
- ::ok ! ::exception {
+ ::lives_ok {
with qw(Role::D Role::E); # conflict between 'foo's here
- }, "... define role Role::D::And::E::Conflict";
+ } "... define role Role::D::And::E::Conflict";
sub foo { 'Role::D::And::E::Conflict::foo' } # this overrides ...
package Role::I;
use Moose::Role;
- ::ok ! ::exception {
+ ::lives_ok {
with qw(Role::J Role::H); # conflict between 'foo's here
- }, "define role Role::I";
+ } "define role Role::I";
sub zot { 'Role::I::zot' }
sub zzy { 'Role::I::zzy' }
package Class::C;
use Moose;
- ::like ::exception {
+ ::throws_ok {
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;
- ::ok ! ::exception {
+ ::lives_ok {
with qw(Role::I);
- }, "resolved with method";
+ } "resolved with method";
sub foo { 'Class::E::foo' }
sub zot { 'Class::E::zot' }
ok(Role::I->meta->requires_method('foo'), '... Role::I still have the &foo requirement');
{
- ok ! exception {
+ lives_ok {
package Class::D;
use Moose;
with qw(Role::I);
- }, "resolved with attr";
+ } "resolved with attr";
can_ok( Class::D->new, qw(foo bar xxy zot) );
is( eval { Class::D->new->bar }, "Role::H::bar", "bar" );
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package My::Foo::Class;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Foo::Role' => { -excludes => 'foo' },
'Bar::Role' => { -excludes => 'foo' },
'Baz::Role';
- }, '... composed our roles correctly';
+ } '... composed our roles correctly';
package My::Foo::Class::Broken;
use Moose;
- ::like ::exception {
+ ::throws_ok {
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'/,
+ } 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';
}
package My::Foo::Role;
use Moose::Role;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Foo::Role' => { -excludes => 'foo' },
'Bar::Role' => { -excludes => 'foo' },
'Baz::Role';
- }, '... composed our roles correctly';
+ } '... composed our roles correctly';
}
ok(My::Foo::Role->meta->has_method('foo'), "we have a foo method");
package My::Foo::Role::Other;
use Moose::Role;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Foo::Role',
'Bar::Role' => { -excludes => 'foo' },
'Baz::Role';
- }, '... composed our roles correctly';
+ } '... composed our roles correctly';
}
ok(!My::Foo::Role::Other->meta->has_method('foo'), "we dont have a foo method");
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package My::Class;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'My::Role' => { -alias => { bar => 'role_bar' } };
- }, '... this succeeds';
+ } '... this succeeds';
package My::Class::Failure;
use Moose;
- ::like ::exception {
+ ::throws_ok {
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' }
}
package My::OtherRole;
use Moose::Role;
- ::ok ! ::exception {
+ ::lives_ok {
with 'My::Role' => { -alias => { bar => 'role_bar' } };
- }, '... this succeeds';
+ } '... this succeeds';
sub bar { 'My::OtherRole::bar' }
package My::OtherRole::Failure;
use Moose::Role;
- ::like ::exception {
+ ::throws_ok {
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' }
}
package My::AliasingRole;
use Moose::Role;
- ::ok ! ::exception {
+ ::lives_ok {
with 'My::Role' => { -alias => { bar => 'role_bar' } };
- }, '... this succeeds';
+ } '... this succeeds';
}
ok(My::AliasingRole->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar);
package My::Foo::Class;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' },
'Bar::Role' => { -alias => { 'foo' => 'bar_foo' }, -excludes => 'foo' },
'Baz::Role';
- }, '... composed our roles correctly';
+ } '... composed our roles correctly';
package My::Foo::Class::Broken;
use Moose;
- ::like ::exception {
+ ::throws_ok {
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'/,
+ } 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';
}
package My::Foo::Role;
use Moose::Role;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' },
'Bar::Role' => { -alias => { 'foo' => 'bar_foo' }, -excludes => 'foo' },
'Baz::Role';
- }, '... composed our roles correctly';
+ } '... composed our roles correctly';
}
ok(My::Foo::Role->meta->has_method($_), "we have a $_ method") for qw/foo foo_foo bar_foo/;;
package My::Foo::Role::Other;
use Moose::Role;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' },
'Bar::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' },
'Baz::Role';
- }, '... composed our roles correctly';
+ } '... composed our roles correctly';
}
ok(!My::Foo::Role::Other->meta->has_method('foo_foo'), "we dont have a foo_foo method");
package My::Foo::AliasOnly;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' } },
- }, '... composed our roles correctly';
+ } '... composed our roles correctly';
}
ok(My::Foo::AliasOnly->meta->has_method('foo'), 'we have a foo method');
package Role::Bar;
use Moose::Role;
- ::ok ! ::exception {
+ use Test::Exception;
+
+ lives_ok {
with 'Role::Foo' => {
-alias => { x1 => 'foo_x1' },
-excludes => ['y1'],
};
- },
+ }
'Compose Role::Foo into Role::Bar with alias and exclude';
sub x1 {}
package Role::Baz;
use Moose::Role;
- ::ok ! ::exception {
+ use Test::Exception;
+
+ lives_ok {
with 'Role::Foo' => {
-alias => { x1 => 'foo_x1' },
-excludes => ['y1'],
};
- },
+ }
'Compose Role::Foo into Role::Baz with alias and exclude';
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package My::Class;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
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';
+ } '... everything works out all right';
}
my $c = My::Class->new;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Scalar::Util 'blessed';
ok(!$obj->can( 'fur' ), 'ditto');
ok(!$obj->does('Dog'), '... we do not do any roles yet');
-ok exception {
+dies_ok {
$obj->dog($obj)
-}, '... and setting the accessor fails (not a Dog yet)';
+} '... and setting the accessor fails (not a Dog yet)';
Dog->meta->apply($obj);
is($obj->talk, 'woof', '... got the right return value for the newly composed method');
-ok ! exception {
+lives_ok {
$obj->dog($obj)
-}, '... and setting the accessor is okay';
+} '... and setting the accessor is okay';
is($obj->fur, "dirty", "role attr initialized");
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Scalar::Util 'blessed';
ok(!$bar->can( 'talk' ), "... the role is not composed yet");
-ok exception {
+dies_ok {
$foo->dog($bar)
-}, '... and setting the accessor fails (not a Dog yet)';
+} '... and setting the accessor fails (not a Dog yet)';
Dog->meta->apply($bar);
is($bar->talk, 'woof', '... got the right return value for the newly composed method');
-ok ! exception {
+lives_ok {
$foo->dog($bar)
-}, '... and setting the accessor is okay';
+} '... and setting the accessor is okay';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
=pod
with 'Foo::Role';
- ::ok ! ::exception {
+ ::lives_ok {
has '+bar' => (default => sub { 100 });
- }, '... extended the attribute successfully';
+ } '... extended the attribute successfully';
}
my $foo = Foo->new;
with 'Bar::Role';
- ::ok ! ::exception {
+ ::lives_ok {
has '+foo' => (
isa => 'Int',
)
- }, "... narrowed the role's type constraint successfully";
+ } "... narrowed the role's type constraint successfully";
}
my $bar = Bar->new(foo => 42);
$bar->foo(100);
is($bar->foo, 100, "... can change the attribute's value to an Int");
-like exception { $bar->foo("baz") }, qr/^Attribute \(foo\) does not pass the type constraint because: Validation failed for 'Int' with value baz at /;
+throws_ok { $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");
with 'Baz::Role';
- ::ok ! ::exception {
+ ::lives_ok {
has '+baz' => (
isa => 'Int | ClassName',
)
- }, "... narrowed the role's type constraint successfully";
+ } "... narrowed the role's type constraint successfully";
}
my $baz = Baz->new(baz => 99);
$baz->baz('Foo');
is($baz->baz, 'Foo', "... can change the attribute's value to a ClassName");
-like exception { $baz->baz("zonk") }, qr/^Attribute \(baz\) does not pass the type constraint because: Validation failed for 'ClassName\|Int' with value zonk at /;
+throws_ok { $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");
=> as 'Int'
=> where { $_ > 0 };
- ::ok ! ::exception {
+ ::lives_ok {
has '+quux' => (
isa => 'Positive | ArrayRef',
)
- }, "... narrowed the role's type constraint successfully";
+ } "... narrowed the role's type constraint successfully";
}
my $quux = Quux->new(quux => 99);
$quux->quux(["hi"]);
is_deeply($quux->quux, ["hi"], "... can change the attribute's value to an ArrayRef");
-like exception { $quux->quux("quux") }, qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef\|Positive' with value quux at /;
+throws_ok { $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");
-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 /;
+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 /;
is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value");
with 'Err::Role';
- ::ok ! ::exception {
+ ::lives_ok {
has '+err1' => (isa => 'Defined');
- }, "can get less specific in the subclass";
+ } "can get less specific in the subclass";
- ::ok ! ::exception {
+ ::lives_ok {
has '+err2' => (isa => 'Bool');
- }, "or change the type completely";
+ } "or change the type completely";
- ::ok ! ::exception {
+ ::lives_ok {
has '+err3' => (isa => 'Str | ArrayRef');
- }, "or add new types to the union";
+ } "or add new types to the union";
}
{
with 'Foo::Role';
- ::like ::exception {
+ ::throws_ok {
has '+bar' => ( is => 'ro' );
- }, qr/has '\+attr' is not supported in roles/,
+ } qr/has '\+attr' is not supported in roles/,
"Test has '+attr' in roles explodes";
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
is($foo->bar, 'BAR', '... got the expect value');
ok(!$foo->can('baz'), '... no baz method though');
- ok ! exception {
+ lives_ok {
Bar->meta->apply($foo)
- }, '... this works';
+ } '... this works';
is($foo->bar, 'BAR', '... got the expect value');
ok($foo->can('baz'), '... we have baz method now');
is($foo->bar, 'BAR', '... got the expect value');
ok(!$foo->can('baz'), '... no baz method though');
- ok ! exception {
+ lives_ok {
Bar->meta->apply($foo, (rebless_params => { baz => 'FOO-BAZ' }))
- }, '... this works';
+ } '... this works';
is($foo->bar, 'BAR', '... got the expect value');
ok($foo->can('baz'), '... we have baz method now');
is($foo->bar, 'BAR', '... got the expect value');
ok(!$foo->can('baz'), '... no baz method though');
- ok ! exception {
+ lives_ok {
Bar->meta->apply($foo, (rebless_params => { bar => 'FOO-BAR', baz => 'FOO-BAZ' }))
- }, '... this works';
+ } '... this works';
is($foo->bar, 'FOO-BAR', '... got the expect value');
ok($foo->can('baz'), '... we have baz method now');
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Meta::Role::Application::RoleSummation;
use Moose::Meta::Role::Composite;
Role::Baz
);
- ok ! exception {
+ lives_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply($c);
- }, '... this composed okay';
+ } '... this composed okay';
##... now nest 'em
{
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Meta::Role::Application::RoleSummation;
use Moose::Meta::Role::Composite;
ok(Role::DoesExcludesFoo->meta->excludes_role('Role::Foo'), '... got the right exclusions');
# test simple exclusion
-ok exception {
+dies_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply(
Moose::Meta::Role::Composite->new(
roles => [
]
)
);
-}, '... this fails as expected';
+} '... this fails as expected';
# test no conflicts
{
is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name');
- ok ! exception {
+ lives_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply($c);
- }, '... this lives as expected';
+ } '... this lives as expected';
}
# test no conflicts w/exclusion
is($c->name, 'Role::Bar|Role::ExcludesFoo', '... got the composite role name');
- ok ! exception {
+ lives_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply($c);
- }, '... this lives as expected';
+ } '... this lives as expected';
is_deeply([$c->get_excluded_roles_list], ['Role::Foo'], '... has excluded roles');
}
# test conflict with an "inherited" exclusion
-ok exception {
+dies_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply(
Moose::Meta::Role::Composite->new(
roles => [
)
);
-}, '... this fails as expected';
+} '... this fails as expected';
# test conflict with an "inherited" exclusion of an "inherited" role
-ok exception {
+dies_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply(
Moose::Meta::Role::Composite->new(
roles => [
]
)
);
-}, '... this fails as expected';
+} '... this fails as expected';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Meta::Role::Application::RoleSummation;
use Moose::Meta::Role::Composite;
is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name');
- ok ! exception {
+ lives_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply($c);
- }, '... this succeeds as expected';
+ } '... this succeeds as expected';
is_deeply(
[ sort $c->get_required_method_list ],
is($c->name, 'Role::Foo|Role::ProvidesFoo', '... got the composite role name');
- ok ! exception {
+ lives_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply($c);
- }, '... this succeeds as expected';
+ } '... this succeeds as expected';
is_deeply(
[ sort $c->get_required_method_list ],
is($c->name, 'Role::Foo|Role::ProvidesFoo|Role::Bar', '... got the composite role name');
- ok ! exception {
+ lives_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply($c);
- }, '... this succeeds as expected';
+ } '... this succeeds as expected';
is_deeply(
[ sort $c->get_required_method_list ],
is($c->name, 'Role::Foo|Role::ProvidesFoo|Role::ProvidesBar|Role::Bar', '... got the composite role name');
- ok ! exception {
+ lives_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply($c);
- }, '... this succeeds as expected';
+ } '... this succeeds as expected';
is_deeply(
[ sort $c->get_required_method_list ],
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Meta::Role::Application::RoleSummation;
use Moose::Meta::Role::Composite;
is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name');
- ok ! exception {
+ lives_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply($c);
- }, '... this succeeds as expected';
+ } '... this succeeds as expected';
is_deeply(
[ sort $c->get_attribute_list ],
}
# test simple conflict
-ok exception {
+dies_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply(
Moose::Meta::Role::Composite->new(
roles => [
]
)
);
-}, '... this fails as expected';
+} '... this fails as expected';
# test complex conflict
-ok exception {
+dies_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply(
Moose::Meta::Role::Composite->new(
roles => [
]
)
);
-}, '... this fails as expected';
+} '... this fails as expected';
# test simple conflict
-ok exception {
+dies_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply(
Moose::Meta::Role::Composite->new(
roles => [
]
)
);
-}, '... this fails as expected';
+} '... this fails as expected';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Meta::Role::Application::RoleSummation;
use Moose::Meta::Role::Composite;
is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name');
- ok ! exception {
+ lives_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply($c);
- }, '... this succeeds as expected';
+ } '... this succeeds as expected';
is_deeply(
[ sort $c->get_method_list ],
is($c->name, 'Role::Foo|Role::FooConflict', '... got the composite role name');
- ok ! exception {
+ lives_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply($c);
- }, '... this succeeds as expected';
+ } '... this succeeds as expected';
is_deeply(
[ sort $c->get_method_list ],
is($c->name, 'Role::Foo|Role::Bar|Role::FooConflict|Role::BarConflict', '... got the composite role name');
- ok ! exception {
+ lives_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply($c);
- }, '... this succeeds as expected';
+ } '... this succeeds as expected';
is_deeply(
[ sort $c->get_method_list ],
is($c->name, 'Role::Foo|Role::AnotherFooConflict', '... got the composite role name');
- ok ! exception {
+ lives_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply($c);
- }, '... this succeeds as expected';
+ } '... this succeeds as expected';
is_deeply(
[ sort $c->get_method_list ],
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Meta::Role::Application::RoleSummation;
use Moose::Meta::Role::Composite;
is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name');
- ok ! exception {
+ lives_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply($c);
- }, '... this lives ok';
+ } '... this lives ok';
is_deeply(
[ sort $c->get_method_modifier_list('override') ],
}
# test simple overrides w/ conflicts
-ok exception {
+dies_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply(
Moose::Meta::Role::Composite->new(
roles => [
]
)
);
-}, '... this fails as expected';
+} '... this fails as expected';
# test simple overrides w/ conflicts
-ok exception {
+dies_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply(
Moose::Meta::Role::Composite->new(
roles => [
]
)
);
-}, '... this fails as expected';
+} '... this fails as expected';
# test simple overrides w/ conflicts
-ok exception {
+dies_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply(
Moose::Meta::Role::Composite->new(
roles => [
]
)
);
-}, '... this fails as expected';
+} '... this fails as expected';
# test simple overrides w/ conflicts
-ok exception {
+dies_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply(
Moose::Meta::Role::Composite->new(
roles => [
]
)
);
-}, '... this fails as expected';
+} '... this fails as expected';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Meta::Role::Application::RoleSummation;
use Moose::Meta::Role::Composite;
is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name');
- ok ! exception {
+ lives_ok {
Moose::Meta::Role::Application::RoleSummation->new->apply($c);
- }, '... this succeeds as expected';
+ } '... this succeeds as expected';
is_deeply(
[ sort $c->get_method_modifier_list('before') ],
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Meta::Class;
use Moose::Util;
# Note that this test passed (pre svn #5543) if we inlined the role
# definitions in this file, as it was very timing sensitive.
-ok (! exception (
+lives_ok(
sub {
my $builder_meta = Moose::Meta::Class->create(
'YATTA' => (
roles => [qw( Role::Interface Role::Child )],
)
);
- }),
+ },
'Create a new class with several roles'
);
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package Bomb;
package PracticalJoke;
use Moose;
- ::like ::exception {
+ ::throws_ok {
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'/;
- ::like ::exception {
+ ::throws_ok {
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;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package My::Role1;
# roles they consume.
{
local $TODO = "role attributes don't satisfy method requirements";
- ok ! exception { package My::Test1; use Moose; with 'My::Role2'; },
+ lives_ok { package My::Test1; use Moose; with 'My::Role2'; }
'role2(provides attribute) consumes role1';
}
-ok ! exception { package My::Test2; use Moose; with 'My::Role3'; },
+lives_ok { package My::Test2; use Moose; with 'My::Role3'; }
'role3(provides method) consumes role1';
# As I understand the design, Roles composed in the same with() statement
# assumption is false. -Vince Veselosky
{
local $TODO = "role attributes don't satisfy method requirements";
- ok ! exception { package My::Test3; use Moose; with 'My::Role4', 'My::Role1'; },
+ lives_ok { package My::Test3; use Moose; with 'My::Role4', 'My::Role1'; }
'class consumes role4(provides attribute), role1';
}
{
local $TODO = "role attributes don't satisfy method requirements";
- ok ! exception { package My::Test4; use Moose; with 'My::Role1', 'My::Role4'; },
+ lives_ok { package My::Test4; use Moose; with 'My::Role1', 'My::Role4'; }
'class consumes role1, role4(provides attribute)';
}
-ok ! exception { package My::Test5; use Moose; with 'My::Role5', 'My::Role1'; },
+lives_ok { package My::Test5; use Moose; with 'My::Role5', 'My::Role1'; }
'class consumes role5(provides method), role1';
-ok ! exception { package My::Test6; use Moose; with 'My::Role1', 'My::Role5'; },
+lives_ok { package My::Test6; use Moose; with 'My::Role1', 'My::Role5'; }
'class consumes role1, role5(provides method)';
# Inherited methods/attributes should satisfy requires(), as long as
# extends() comes first in code order.
-ok ! exception {
+lives_ok {
package My::Test7;
use Moose;
extends 'My::Base1';
with 'My::Role1';
-},
+}
'class extends base1(provides attribute), consumes role1';
-ok ! exception {
+lives_ok {
package My::Test8;
use Moose;
extends 'My::Base2';
with 'My::Role1';
-},
+}
'class extends base2(provides method), consumes role1';
# Attributes/methods implemented in class should satisfy requires()
-ok ! exception {
+lives_ok {
package My::Test9;
use Moose;
has 'test_output', is => 'rw';
with 'My::Role1';
-},
+}
'class provides attribute, consumes role1';
-ok ! exception {
+lives_ok {
package My::Test10;
use Moose;
sub test_output { }
with 'My::Role1';
-},
+}
'class provides method, consumes role1';
# Roles composed in separate with() statements SHOULD demonstrate ordering
# dependency. See comment with tests 3-6 above.
-ok ! exception {
+lives_ok {
package My::Test11;
use Moose;
with 'My::Role4';
with 'My::Role1';
-},
+}
'class consumes role4(provides attribute); consumes role1';
-ok exception { package My::Test12; use Moose; with 'My::Role1'; with 'My::Role4'; },
+dies_ok { package My::Test12; use Moose; with 'My::Role1'; with 'My::Role4'; }
'class consumes role1; consumes role4(provides attribute)';
-ok ! exception {
+lives_ok {
package My::Test13;
use Moose;
with 'My::Role5';
with 'My::Role1';
-},
+}
'class consumes role5(provides method); consumes role1';
-ok exception { package My::Test14; use Moose; with 'My::Role1'; with 'My::Role5'; },
+dies_ok { package My::Test14; use Moose; with 'My::Role1'; with 'My::Role5'; }
'class consumes role1; consumes role5(provides method)';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package My::Role1;
is => 'ro',
);
- ::like ::exception { with 'My::Role1' }, qr/attribute conflict.+My::Role2.+foo/,
+ ::throws_ok { with 'My::Role1' } qr/attribute conflict.+My::Role2.+foo/,
'attribute conflict when composing one role into another';
}
use strict;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
my $FooRole;
{
package Quux::Role;
use Moose::Role;
{ our $TODO; local $TODO = "can't handle regexes yet";
- ::ok ! ::exception {
+ ::lives_ok {
after qr/foo|bar/ => sub { $QuuxRole++ }
};
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Scalar::Util ();
"This is not a string (5)",
'... validated unsuccessfully (got error)');
-ok ! exception { Moose::Meta::Attribute->new('bob', isa => 'Spong') },
+lives_ok { Moose::Meta::Attribute->new('bob', isa => 'Spong') }
'meta-attr construction ok even when type constraint utils loaded first';
# Test type constraint predicate return values.
# Test adding things which don't look like types to the registry throws an exception
my $r = Moose::Util::TypeConstraints->get_type_constraint_registry;
-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';
+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';
# Test some specific things that in the past did not work,
# specifically weird variations on anon subtypes.
}
{
- like exception { subtype 'Foo' }, qr/cannot consist solely of a name/,
+ throws_ok { subtype 'Foo' } qr/cannot consist solely of a name/,
'Cannot call subtype with a single string argument';
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
BEGIN {
use_ok('Moose::Util::TypeConstraints');
my $anon_type = subtype Object => where { $_->isa('HTTPHeader') };
-ok ! exception {
+lives_ok {
coerce $anon_type
=> from ArrayRef
=> via { HTTPHeader->new(array => $_[0]) }
=> from HashRef
=> via { HTTPHeader->new(hash => $_[0]) };
-}, 'coercion of anonymous subtype succeeds';
+} 'coercion of anonymous subtype succeeds';
foreach my $coercion (
find_type_constraint('Header')->coercion,
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
# try with arrays
- ok ! exception {
+ lives_ok {
$engine->header([ 1, 2, 3 ]);
- }, '... type was coerced without incident';
+ } '... type was coerced without incident';
isa_ok($engine->header, 'HTTPHeader');
is_deeply(
# try with hash
- ok ! exception {
+ lives_ok {
$engine->header({ one => 1, two => 2, three => 3 });
- }, '... type was coerced without incident';
+ } '... type was coerced without incident';
isa_ok($engine->header, 'HTTPHeader');
is_deeply(
'... got the right hash value of the header');
ok(!defined($engine->header->array), '... no array value set');
- ok exception {
+ dies_ok {
$engine->header("Foo");
- }, '... dies with the wrong type, even after coercion';
+ } '... dies with the wrong type, even after coercion';
- ok ! exception {
+ lives_ok {
$engine->header(HTTPHeader->new);
- }, '... lives with the right type, even after coercion';
+ } '... lives with the right type, even after coercion';
}
{
ok(!defined($engine->header->array), '... no array value set');
}
-ok exception {
+dies_ok {
Engine->new(header => 'Foo');
-}, '... dies correctly with bad params';
+} '... dies correctly with bad params';
-ok exception {
+dies_ok {
Engine->new(header => \(my $var));
-}, '... dies correctly with bad params';
+} '... dies correctly with bad params';
{
my $tc = Moose::Util::TypeConstraints::find_type_constraint('HTTPHeader');
isa_ok($from_href, 'HTTPHeader', 'assert_coerce from href to HTTPHeader');
is_deeply($from_href->hash, { a => 1 }, '...and has the right guts');
- like exception { $tc->assert_coerce('total garbage') },
+ throws_ok { $tc->assert_coerce('total garbage') }
qr/Validation failed for .HTTPHeader./,
"assert_coerce throws if result is not acceptable";
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Test::Requires {
'IO::String' => '0.01', # skip all if not installed
is($email->as_string, '... this is my body ...', '... got correct string');
- ok ! exception {
+ lives_ok {
$email->raw_body('... this is the next body ...');
- }, '... this will coerce correctly';
+ } '... this will coerce correctly';
isa_ok($email->raw_body, 'IO::String');
my $str2 = '... this is the next body (ref) ...';
- ok ! exception {
+ lives_ok {
$email->raw_body(\$str2);
- }, '... this will coerce correctly';
+ } '... this will coerce correctly';
isa_ok($email->raw_body, 'IO::String');
my $io_str2 = IO::String->new('... this is the next body (IO::String) ...');
- ok ! exception {
+ lives_ok {
$email->raw_body($io_str2);
- }, '... this will coerce correctly';
+ } '... this will coerce correctly';
isa_ok($email->raw_body, 'IO::String');
is($email->raw_body, $io_str2, '... and it is the one we expected');
{
my $foo;
- ok ! exception { $foo = Foo->new( carray => 1 ) },
+ lives_ok { $foo = Foo->new( carray => 1 ) }
'Can pass non-ref value for carray';
is_deeply(
$foo->carray, [1],
'carray was coerced to an array ref'
);
- like exception { Foo->new( carray => {} ) },
+ 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';
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Scalar::Util qw(refaddr);
BEGIN {
# subtype 'aliasing' ...
-ok ! exception {
+lives_ok {
subtype 'Numb3rs' => as 'Num';
-}, '... create bare subtype fine';
+} '... create bare subtype fine';
my $numb3rs = find_type_constraint('Numb3rs');
isa_ok($numb3rs, 'Moose::Meta::TypeConstraint');
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Scalar::Util ();
ok( !$anon_enum->is_a_type_of('ThisTypeDoesNotExist'), 'enum not type of nonexistant type');
# validation
-like exception { Moose::Meta::TypeConstraint::Enum->new(name => 'ZeroValues', values => []) },
+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 => 'OneValue', values => [ 'a' ]) },
+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 => 'ReferenceInEnum', values => [ 'a', {} ]) },
+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 => 'UndefInEnum', values => [ 'a', undef ]) },
+throws_ok { Moose::Meta::TypeConstraint::Enum->new(name => 'UndefInEnum', values => [ 'a', undef ]) }
qr/Enum values must be strings, not undef/;
-like exception {
+throws_ok {
package Foo;
use Moose;
use Moose::Util::TypeConstraints;
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;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
BEGIN {
use_ok("Moose::Util::TypeConstraints");
}
-ok ! exception {
+lives_ok {
subtype 'MySpecialHash' => as 'HashRef[Int]';
-}, '... created the subtype special okay';
+} '... created the subtype special okay';
{
my $t = find_type_constraint('MySpecialHash');
ok( !$t->is_subtype_of("ThisTypeDoesNotExist"), "not a subtype of a non existant type" );
}
-ok ! exception {
+lives_ok {
subtype 'MySpecialHashExtended'
=> as 'HashRef[Int]'
=> where {
# all values are less then 10
(scalar grep { $_ < 10 } values %{$_}) ? 1 : undef
};
-}, '... created the subtype special okay';
+} '... created the subtype special okay';
{
my $t = find_type_constraint('MySpecialHashExtended');
ok(!$t->check({ one => "ONE", two => "TWO" }), '... validated it correctly');
}
-ok ! exception {
+lives_ok {
subtype 'MyNonSpecialHash'
=> as "HashRef"
=> where { keys %$_ == 3 };
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';
- like exception {
+ throws_ok sub {
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';
}
{
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
BEGIN {
use_ok("Moose::Util::TypeConstraints");
}
-ok ! exception {
+lives_ok {
subtype 'MyCollections' => as 'ArrayRef | HashRef';
-}, '... created the subtype special okay';
+} '... created the subtype special okay';
{
my $t = find_type_constraint('MyCollections');
ok(!$t->check(1), '... validated it correctly');
}
-ok ! exception {
+lives_ok {
subtype 'MyCollectionsExtended'
=> as 'ArrayRef|HashRef'
=> where {
}
1;
};
-}, '... created the subtype special okay';
+} '... created the subtype special okay';
{
my $t = find_type_constraint('MyCollectionsExtended');
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
BEGIN {
use_ok("Moose::Util::TypeConstraints");
use_ok('Moose::Meta::TypeConstraint::Parameterized');
}
-ok ! exception {
+lives_ok {
subtype 'AlphaKeyHash' => as 'HashRef'
=> where {
# no keys match non-alpha
(grep { /[^a-zA-Z]/ } keys %$_) == 0
};
-}, '... created the subtype special okay';
+} '... created the subtype special okay';
-ok ! exception {
+lives_ok {
subtype 'Trihash' => as 'AlphaKeyHash'
=> where {
keys(%$_) == 3
};
-}, '... created the subtype special okay';
+} '... created the subtype special okay';
-ok ! exception {
+lives_ok {
subtype 'Noncon' => as 'Item';
-}, '... created the subtype special okay';
+} '... created the subtype special okay';
{
my $t = find_type_constraint('AlphaKeyHash');
ok(!$th->check({ one => 1, two => 2, three => 1 }), '... validated it correctly');
ok(!$th->check({foo1 => 1, bar2 => 0, baz3 => 1}), '... validated it correctly');
-ok exception {
+dies_ok {
Moose::Meta::TypeConstraint::Parameterized->new(
name => 'Str[Int]',
parent => find_type_constraint('Str'),
type_parameter => find_type_constraint('Int'),
);
-}, 'non-containers cannot be parameterized';
+} 'non-containers cannot be parameterized';
-ok exception {
+dies_ok {
Moose::Meta::TypeConstraint::Parameterized->new(
name => 'Noncon[Int]',
parent => find_type_constraint('Noncon'),
type_parameter => find_type_constraint('Int'),
);
-}, 'non-containers cannot be parameterized';
+} 'non-containers cannot be parameterized';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
BEGIN {
use_ok("Moose::Util::TypeConstraints");
subtype 'MyList' => as 'Object' => where { $_->isa('MyList') };
-ok ! exception {
+lives_ok {
coerce 'ArrayRef'
=> from 'MyList'
=> via { [ $_->items ] }
-}, '... created the coercion okay';
+} '... created the coercion okay';
my $mylist = Moose::Util::TypeConstraints::find_or_parse_type_constraint('MyList[Int]');
# 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?
-ok ! exception {
+lives_ok {
coerce 'ArrayRef'
=> from 'EvenList'
=> via { [ $_->items ] }
-}, '... created the coercion okay';
+} '... created the coercion okay';
my $evenlist = Moose::Util::TypeConstraints::find_or_parse_type_constraint('EvenList[Int]');
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
BEGIN {
use_ok('Moose::Util::TypeConstraints');
}
-ok ! exception { class_type 'Beep' }, 'class_type keywork works';
-ok ! exception { class_type('Boop', message { "${_} is not a Boop" }) },
+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';
my $type = find_type_constraint("Foo");
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Util::TypeConstraints;
has 'maybe_bar' => (is => 'rw', isa => maybe_type(class_type('Bar')));
}
-ok ! exception {
+lives_ok {
Foo->new(arr => [], bar => Bar->new);
-}, '... Bar->new isa Bar';
+} '... Bar->new isa Bar';
-ok exception {
+dies_ok {
Foo->new(arr => [], bar => undef);
-}, '... undef isnta Bar';
+} '... undef isnta Bar';
-ok ! exception {
+lives_ok {
Foo->new(arr => [], maybe_bar => Bar->new);
-}, '... Bar->new isa maybe(Bar)';
+} '... Bar->new isa maybe(Bar)';
-ok ! exception {
+lives_ok {
Foo->new(arr => [], maybe_bar => undef);
-}, '... undef isa maybe(Bar)';
+} '... undef isa maybe(Bar)';
-ok exception {
+dies_ok {
Foo->new(arr => [], maybe_bar => 1);
-}, '... 1 isnta maybe(Bar)';
+} '... 1 isnta maybe(Bar)';
-ok ! exception {
+lives_ok {
Foo->new(arr => []);
-}, '... it worked!';
+} '... it worked!';
-ok ! exception {
+lives_ok {
Foo->new(arr => undef);
-}, '... it worked!';
+} '... it worked!';
-ok exception {
+dies_ok {
Foo->new(arr => 100);
-}, '... failed the type check';
+} '... failed the type check';
-ok exception {
+dies_ok {
Foo->new(arr => 'hello world');
-}, '... failed the type check';
+} '... failed the type check';
{
ok !$Maybe_Int->check("")
=> 'failed ("")';
-like exception { $obj->Maybe_Int("") },,
+throws_ok sub { $obj->Maybe_Int("") },
qr/Attribute \(Maybe_Int\) does not pass the type constraint/
=> 'failed assigned ("")';
ok !$Maybe_Int->check("a")
=> 'failed ("a")';
-like exception { $obj->Maybe_Int("a") },,
+throws_ok sub { $obj->Maybe_Int("a") },
qr/Attribute \(Maybe_Int\) does not pass the type constraint/
=> 'failed assigned ("a")';
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package Animal;
);
}
-ok ! exception { my $goat = Animal->new( leg_count => 4 ) },
+lives_ok { my $goat = Animal->new( leg_count => 4 ) }
'... no errors thrown, value is good';
-ok ! exception { my $spider = Animal->new( leg_count => 8 ) },
+lives_ok { my $spider = Animal->new( leg_count => 8 ) }
'... no errors thrown, value is good';
-like exception { my $fern = Animal->new( leg_count => 0 ) },
+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 $centipede = Animal->new( leg_count => 30 ) },
+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';
my $chimera;
-ok ! exception { $chimera = Animal->new( leg_count => 4 ) },
+lives_ok { $chimera = Animal->new( leg_count => 4 ) }
'... no errors thrown, value is good';
-like exception { $chimera->leg_count(0) },
+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(16) },
+throws_ok { $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' );
-like exception { $gimp->leg_count },
+throws_ok { $gimp->leg_count }
qr/This number \(0\) is not less than ten!/,
'gave custom supertype error message on lazy set to 0';
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
my $foo = Foo->new;
-ok ! exception { $foo->vUndef(undef) }, '... undef is a Foo->Undef';
-ok exception { $foo->vDefined(undef) }, '... undef is NOT a Foo->Defined';
-ok exception { $foo->vInt(undef) }, '... undef is NOT a Foo->Int';
-ok exception { $foo->vNumber(undef) }, '... undef is NOT a Foo->Number';
-ok exception { $foo->vStr(undef) }, '... undef is NOT a Foo->Str';
-ok exception { $foo->vString(undef) }, '... undef is NOT a Foo->String';
-
-ok exception { $foo->vUndef(5) }, '... 5 is NOT a Foo->Undef';
-ok ! exception { $foo->vDefined(5) }, '... 5 is a Foo->Defined';
-ok ! exception { $foo->vInt(5) }, '... 5 is a Foo->Int';
-ok ! exception { $foo->vNumber(5) }, '... 5 is a Foo->Number';
-ok ! exception { $foo->vStr(5) }, '... 5 is a Foo->Str';
-ok exception { $foo->vString(5) }, '... 5 is NOT a Foo->String';
-
-ok exception { $foo->vUndef(0.5) }, '... 0.5 is NOT a Foo->Undef';
-ok ! exception { $foo->vDefined(0.5) }, '... 0.5 is a Foo->Defined';
-ok exception { $foo->vInt(0.5) }, '... 0.5 is NOT a Foo->Int';
-ok ! exception { $foo->vNumber(0.5) }, '... 0.5 is a Foo->Number';
-ok ! exception { $foo->vStr(0.5) }, '... 0.5 is a Foo->Str';
-ok exception { $foo->vString(0.5) }, '... 0.5 is NOT a Foo->String';
-
-ok exception { $foo->vUndef('Foo') }, '... "Foo" is NOT a Foo->Undef';
-ok ! exception { $foo->vDefined('Foo') }, '... "Foo" is a Foo->Defined';
-ok exception { $foo->vInt('Foo') }, '... "Foo" is NOT a Foo->Int';
-ok exception { $foo->vNumber('Foo') }, '... "Foo" is NOT a Foo->Number';
-ok ! exception { $foo->vStr('Foo') }, '... "Foo" is a Foo->Str';
-ok ! exception { $foo->vString('Foo') }, '... "Foo" is a Foo->String';
+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';
# the lazy tests
-ok ! exception { $foo->v_lazy_Undef() }, '... undef is a Foo->Undef';
-ok exception { $foo->v_lazy_Defined() }, '... undef is NOT a Foo->Defined';
-ok exception { $foo->v_lazy_Int() }, '... undef is NOT a Foo->Int';
-ok exception { $foo->v_lazy_Number() }, '... undef is NOT a Foo->Number';
-ok exception { $foo->v_lazy_Str() }, '... undef is NOT a Foo->Str';
-ok exception { $foo->v_lazy_String() }, '... undef is NOT a Foo->String';
+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';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
BEGIN {
use_ok('Moose::Util::TypeConstraints');
}
-ok ! exception { role_type('Boop', message { "${_} is not a Boop" }) },
+lives_ok { role_type('Boop', message { "${_} is not a Boop" }) }
'role_type keywork works with message';
my $type = find_type_constraint("Foo");
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
BEGIN {
use_ok('Moose::Util::TypeConstraints');
# test parameterizable
-ok ! exception {
+lives_ok sub {
$params->parameterizable( { a => 'Hello', b => 'World' } );
-}, => 'No problem setting parameterizable';
+} => 'No problem setting parameterizable';
is_deeply $params->parameterizable,
{ a => 'Hello', b => 'World' } => 'Got expected values';
# test parameterized
-ok ! exception {
+lives_ok sub {
$params->parameterized( { a => 1, b => 2 } );
-}, => 'No problem setting parameterized';
+} => 'No problem setting parameterized';
is_deeply $params->parameterized, { a => 1, b => 2 } => 'Got expected values';
-like exception {
+throws_ok sub {
$params->parameterized( { a => 'Hello', b => 'World' } );
- },, qr/Attribute \(parameterized\) does not pass the type constraint/ =>
+ }, qr/Attribute \(parameterized\) does not pass the type constraint/ =>
'parameterized throws expected error';
# test from_parameterizable
-ok ! exception {
+lives_ok sub {
$params->from_parameterizable( { a => 1, b => 2 } );
-}, => 'No problem setting from_parameterizable';
+} => 'No problem setting from_parameterizable';
is_deeply $params->from_parameterizable,
{ a => 1, b => 2 } => 'Got expected values';
-like exception {
+throws_ok sub {
$params->from_parameterizable( { a => 'Hello', b => 'World' } );
- },,
+ },
qr/Attribute \(from_parameterizable\) does not pass the type constraint/
=> 'from_parameterizable throws expected error';
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
BEGIN {
use_ok('Moose::Util::TypeConstraints');
subtype 'MySubType' => as 'Int' => where { 1 };
}
-like exception {
+throws_ok {
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;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Util::TypeConstraints;
use Moose::Meta::TypeConstraint;
);
}
-like exception {
+throws_ok {
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\)/;
-ok ! exception {
+lives_ok {
Quux->new(age => (bless {}, 'Positive'));
};
use Moose;
";
-like exception {
+throws_ok {
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\)/;
-ok ! exception {
+lives_ok {
Quux->new(age => Positive->new)
};
);
}
-like exception {
+throws_ok {
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 /;
-ok ! exception {
+lives_ok {
Quux::Ier->new(age => (bless {}, 'Negative'))
};
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Meta::TypeConstraint;
use Moose::Util::TypeConstraints;
}
}
-ok ! exception { Moose::Meta::TypeConstraint->new( name => 'Foo.Bar::Baz' ) },
+lives_ok { Moose::Meta::TypeConstraint->new( name => 'Foo.Bar::Baz' ) }
'Type names can contain periods and colons';
-like exception { subtype 'Foo-Baz' => as 'Item' },
+throws_ok { subtype 'Foo-Baz' => as 'Item' }
qr/contains invalid characters/,
'Type names cannot contain a dash (via subtype sugar)';
-ok ! exception { subtype 'Foo.Bar::Baz' => as 'Item' },
+lives_ok { subtype 'Foo.Bar::Baz' => as 'Item' }
'Type names can contain periods and colons (via subtype sugar)';
is( Moose::Util::TypeConstraints::find_or_parse_type_constraint('ArrayRef[In-valid]'),
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
}
# try giving it a duck
-ok ! exception { DucktypeTest->new( duck => Duck->new ) }, 'the Duck lives okay';
+lives_ok { DucktypeTest->new( duck => Duck->new ) } 'the Duck lives okay';
# try giving it a swan which is like a duck, but not close enough
-like exception { DucktypeTest->new( duck => Swan->new ) },
+throws_ok { DucktypeTest->new( duck => Swan->new ) }
qr/Swan is missing methods 'quack'/,
"the Swan doesn't quack";
# try giving it a rubber RubberDuckey
-ok ! exception { DucktypeTest->new( swan => Swan->new ) }, 'but a Swan can honk';
+lives_ok { DucktypeTest->new( swan => Swan->new ) } 'but a Swan can honk';
# try giving it a rubber RubberDuckey
-ok ! exception { DucktypeTest->new( duck => RubberDuck->new ) },
+lives_ok { DucktypeTest->new( duck => RubberDuck->new ) }
'the RubberDuck lives okay';
# try with the other constraint form
-ok ! exception { DucktypeTest->new( other_swan => Swan->new ) }, 'but a Swan can honk';
+lives_ok { DucktypeTest->new( other_swan => Swan->new ) } 'but a Swan can honk';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Util::TypeConstraints;
is( is_acceptable_color( 'yellow' ), 'CMYK', '... got the right value');
is( is_acceptable_color( 'black' ), 'CMYK', '... got the right value');
-ok exception {
+dies_ok {
is_acceptable_color( 'orange' )
-}, '... got the exception';
+} '... got the exception';
## using it in an OO context
CodeRef => sub { $_->('Hello code ref world') };
}
-like exception {
+throws_ok {
not_enough_matches( [] )
-}, qr/No cases matched for /, '... not enough matches';
+} qr/No cases matched for /, '... not enough matches';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
-ok ! exception {
+lives_ok {
package MooseX::Attribute::Test;
use Moose::Role;
-}, 'creating custom attribute "metarole" is okay';
+} 'creating custom attribute "metarole" is okay';
-ok ! exception {
+lives_ok {
package Moose::Meta::Attribute::Custom::Test;
use Moose;
extends 'Moose::Meta::Attribute';
with 'MooseX::Attribute::Test';
-}, 'custom attribute metaclass extending role is okay';
+} 'custom attribute metaclass extending role is okay';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Test::Requires {
'Test::Output' => '0.01', # skip all if not installed
use Moose ();
- my $error;
- ::ok($error = ::exception
- {
+ ::dies_ok(
+ sub {
Moose::Exporter->setup_import_methods(
also => [ 'Moose', 'MooseX::CircularAlso' ],
);
);
::like(
- $error,
+ $@,
qr/\QCircular reference in 'also' parameter to Moose::Exporter between MooseX::CircularAlso and MooseX::CircularAlso/,
'got the expected error from circular reference in also'
);
use Moose ();
- my $error;
- ::ok($error = ::exception
- {
+ ::dies_ok(
+ sub {
Moose::Exporter->setup_import_methods(
also => [ 'NoSuchThing' ],
);
);
::like(
- $error,
+ $@,
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'
);
use Moose ();
- my $error;
- ::ok($error = ::exception
- {
+ ::dies_ok(
+ sub {
Moose::Exporter->setup_import_methods(
also => [ 'Moose::Meta::Method' ],
);
);
::like(
- $error,
+ $@,
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'
);
use lib 't/lib', 'lib';
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package My::SimpleTrait;
{
require Moose::Util::TypeConstraints;
- my $error;
- ok($error = exception { Moose::Util::TypeConstraints->import( -traits => 'My::SimpleTrait' ) },
- 'cannot provide -traits to an exporting module that does not init_meta');
- like( $error, qr/does not have an init_meta/,
+ dies_ok( sub { 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' );
}
has an_attr => ( is => 'ro' );
}
-ok ! exception {
+lives_ok {
my $instance = Class::WithAlreadyPresentTrait->new( an_attr => 'value' );
is( $instance->an_attr, 'value', 'Can get value' );
-},
+}
'Can create instance and access attributes';
{
has an_attr => ( is => 'ro' );
}
-ok ! exception {
+lives_ok {
my $instance = Class::WhichLoadsATraitFromDisk->new( an_attr => 'value' );
is( $instance->an_attr, 'value', 'Can get value' );
-},
+}
'Can create instance and access attributes';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
# Some packages out in the wild cooperate with Moose by using goto
# &Moose::import. we want to make sure it still works.
MooseAlike1->import();
- ::ok ! ::exception { has( 'size', is => 'bare' ) },
- 'has was exported via MooseAlike1';
+ ::lives_ok( sub { has( 'size', is => 'bare' ) },
+ 'has was exported via MooseAlike1' );
MooseAlike1->unimport();
}
MooseAlike2->import();
- ::ok ! ::exception { has( 'size', is => 'bare' ) },
- 'has was exported via MooseAlike2';
+ ::lives_ok( sub { has( 'size', is => 'bare' ) },
+ 'has was exported via MooseAlike2' );
MooseAlike2->unimport();
}
use lib 't/lib', 'lib';
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Util::MetaRole;
}
}
-ok ! exception {
+lives_ok {
package UsesExportedMoose;
ExportsMoose->import;
-}, 'import module which loads a role from disk during init_meta';
+} 'import module which loads a role from disk during init_meta';
{
package Foo::Meta::Role;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
);
use Moose;
- ::ok ::exception { extends 'Baz::Sub' }, 'error_class is included in metaclass compatibility checks';
+ ::dies_ok { extends 'Baz::Sub' } 'error_class is included in metaclass compatibility checks';
}
{
package Foo::Sub::Sub;
use Moose;
- ::ok ! ::exception { extends 'Foo::Sub' }, 'error_class differs by role so incompat is handled';
+ ::lives_ok { extends 'Foo::Sub' } 'error_class differs by role so incompat is handled';
Moose::Util::MetaRole::apply_metaroles(
for => __PACKAGE__,
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package HasFoo;
package main;
my $anon;
-ok ! exception {
+lives_ok {
$anon = My::Metaclass->create_anon_class( foo => 'this' );
-}, 'create anon class with required attr';
+} 'create anon class with required attr';
isa_ok( $anon, 'My::Metaclass' );
cmp_ok( $anon->foo, 'eq', 'this', 'foo is this' );
-ok exception {
+dies_ok {
$anon = My::Metaclass->create_anon_class();
-}, 'failed to create anon class without required attr';
+} 'failed to create anon class without required attr';
my $meta;
-ok ! exception {
+lives_ok {
$meta
= My::Metaclass->initialize( 'Class::Name1' => ( foo => 'that' ) );
-}, 'initialize a class with required attr';
+} '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' );
-ok exception {
+dies_ok {
$meta
= My::Metaclass->initialize( 'Class::Name2' );
-}, 'failed to initialize a class without required attr';
+} 'failed to initialize a class without required attr';
-ok ! exception {
+lives_ok {
eval qq{
package Class::Name3;
use metaclass 'My::Metaclass' => (
use Moose;
};
die $@ if $@;
-}, 'use metaclass with required attr';
+} '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' );
-ok exception {
+dies_ok {
eval qq{
package Class::Name4;
use metaclass 'My::Metaclass';
use Moose;
};
die $@ if $@;
-}, 'failed to use metaclass without required attr';
+} 'failed to use metaclass without required attr';
# how do we pass a required attribute to -traits?
-ok exception {
+dies_ok {
eval qq{
package Class::Name5;
use Moose -traits => 'HasFoo';
};
die $@ if $@;
-}, 'failed to use trait without required attr';
+} 'failed to use trait without required attr';
done_testing;
use MyExporter;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
-ok ! exception {
+lives_and {
with_prototype {
my $caller = caller(0);
is($caller, 'MyExporter', "With_caller prototype code gets called from MyMooseX");
};
-}, "check function with prototype";
+} "check function with prototype";
-ok ! exception {
+lives_and {
as_is_prototype {
my $caller = caller(0);
is($caller, 'MyExporter', "As-is prototype code gets called from MyMooseX");
};
-}, "check function with prototype";
+} "check function with prototype";
done_testing;
}
use Test::More;
-use Test::Fatal;
+use Test::Exception;
-ok ! exception {
+lives_ok {
Moose->init_meta(for_class => 'SomeClass');
-}, 'Moose class => use base => Moose Class, then Moose->init_meta on middle class ok';
+} 'Moose class => use base => Moose Class, then Moose->init_meta on middle class ok';
done_testing;
use lib 't/lib', 'lib';
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Util::MetaRole;
}
}
-ok ! exception {
+lives_ok {
package UsesExportedMoose;
ExportsMoose->import;
-}, 'import module which loads a role from disk during init_meta';
+} 'import module which loads a role from disk during init_meta';
{
package Foo::Meta::Role;
use warnings;
use lib 't/lib';
use Test::More;
-use Test::Fatal;
+use Test::Exception;
our $called = 0;
{
package Baz2;
use Moose;
my $meta = __PACKAGE__->meta;
- ::ok ! ::exception { $meta->superclasses('Foo2') }, "can set superclasses once";
+ ::lives_ok { $meta->superclasses('Foo2') } "can set superclasses once";
::isa_ok($meta, Foo2->meta->meta->name);
- ::ok ! ::exception { $meta->superclasses('Bar2') }, "can still set superclasses";
+ ::lives_ok { $meta->superclasses('Bar2') } "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");
- ::ok ! ::exception { $meta->make_immutable }, "can still make immutable";
+ ::lives_ok { $meta->make_immutable } "can still make immutable";
}
{
package Foo3::Role;
package Baz3;
use Moose -traits => ['Foo3::Role'];
my $meta = __PACKAGE__->meta;
- ::ok ! ::exception { $meta->superclasses('Foo2') }, "can set superclasses once";
+ ::lives_ok { $meta->superclasses('Foo2') } "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");
- ::ok ! ::exception { $meta->superclasses('Bar3') }, "can still set superclasses";
+ ::lives_ok { $meta->superclasses('Bar3') } "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");
- ::ok ! ::exception { $meta->make_immutable }, "can still make immutable";
+ ::lives_ok { $meta->make_immutable } "can still make immutable";
}
{
package Quux3;
package Quuux3;
use Moose -traits => ['Foo3::Role'];
my $meta = __PACKAGE__->meta;
- ::ok ! ::exception { $meta->superclasses('Foo2') }, "can set superclasses once";
+ ::lives_ok { $meta->superclasses('Foo2') } "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");
- ::ok ! ::exception { $meta->superclasses('Quux3') }, "can still set superclasses";
+ ::lives_ok { $meta->superclasses('Quux3') } "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");
- ::ok ! ::exception { $meta->make_immutable }, "can still make immutable";
+ ::lives_ok { $meta->make_immutable } "can still make immutable";
}
{
package Baz4;
use Moose;
my $meta = __PACKAGE__->meta;
- ::ok ! ::exception { $meta->superclasses('Foo4') }, "can set superclasses once";
+ ::lives_ok { $meta->superclasses('Foo4') } "can set superclasses once";
::isa_ok($meta, Foo4->meta->_get_mutable_metaclass_name);
- ::ok ! ::exception { $meta->superclasses('Bar4') }, "can still set superclasses";
+ ::lives_ok { $meta->superclasses('Bar4') } "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");
- ::ok ! ::exception { $meta->make_immutable }, "can still make immutable";
+ ::lives_ok { $meta->make_immutable } "can still make immutable";
}
{
package Foo5::Role;
package Baz5;
use Moose -traits => ['Foo5::Role'];
my $meta = __PACKAGE__->meta;
- ::ok ! ::exception { $meta->superclasses('Foo4') }, "can set superclasses once";
+ ::lives_ok { $meta->superclasses('Foo4') } "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");
- ::ok ! ::exception { $meta->superclasses('Bar5') }, "can still set superclasses";
+ ::lives_ok { $meta->superclasses('Bar5') } "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");
- ::ok ! ::exception { $meta->make_immutable }, "can still make immutable";
+ ::lives_ok { $meta->make_immutable } "can still make immutable";
}
{
package Quux5;
package Quuux5;
use Moose -traits => ['Foo5::Role'];
my $meta = __PACKAGE__->meta;
- ::ok ! ::exception { $meta->superclasses('Foo4') }, "can set superclasses once";
+ ::lives_ok { $meta->superclasses('Foo4') } "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");
- ::ok ! ::exception { $meta->superclasses('Quux5') }, "can still set superclasses";
+ ::lives_ok { $meta->superclasses('Quux5') } "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");
- ::ok ! ::exception { $meta->make_immutable }, "can still make immutable";
+ ::lives_ok { $meta->make_immutable } "can still make immutable";
}
{
push(@superclasses, 'Foo5::SuperClass::After::Attribute');
- ::ok ! ::exception {
+ ::lives_ok {
extends @superclasses;
- }, 'MI extends after_generated_methods with metaclass roles';
- ::ok ! ::exception {
+ } 'MI extends after_generated_methods with metaclass roles';
+ ::lives_ok {
extends reverse @superclasses;
- },
+ }
'MI extends after_generated_methods with metaclass roles (reverse)';
}
push(@superclasses, 'Foo6::SuperClass::After::Attribute');
- ::like ::exception {
+ ::throws_ok {
extends @superclasses;
- }, qr/compat.*pristine/,
+ } qr/compat.*pristine/,
'unsafe MI extends after_generated_methods with metaclass roles';
- ::like ::exception {
+ ::throws_ok {
extends reverse @superclasses;
- }, qr/compat.*pristine/,
+ } qr/compat.*pristine/,
'unsafe MI extends after_generated_methods with metaclass roles (reverse)';
}
package Bar7;
# in an external file
use Moose -traits => ['Bar7::Meta::Trait'];
- ::ok ! ::exception { extends 'Foo7' }, "role reconciliation works";
+ ::lives_ok { extends 'Foo7' } "role reconciliation works";
}
{
package Bar72;
# in an external file
use Moose -traits => ['Bar7::Meta::Trait2'];
- ::ok ! ::exception { extends 'Foo7' }, "role reconciliation works";
+ ::lives_ok { extends 'Foo7' } "role reconciliation works";
}
done_testing;
use strict;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package Foo::Meta::Constructor1;
for => __PACKAGE__,
class_metaroles => { constructor => ['Foo::Meta::Constructor2'] },
);
- ::ok ! ::exception { extends 'Foo::Sub' }, "doesn't try to fix if nothing is needed";
+ ::lives_ok { extends 'Foo::Sub' } "doesn't try to fix if nothing is needed";
}
done_testing;
use warnings;
use Test::More;
use Test::Moose;
-use Test::Fatal;
+use Test::Exception;
sub check_meta_sanity {
my ($meta, $class) = @_;
BEGIN { extends 'Moose::Meta::Attribute' };
}
-like exception {
+throws_ok {
Moose::Meta::Class->reinitialize(
'Bar',
method_metaclass => 'Bar::Meta::Method',
attribute_metaclass => 'Bar::Meta::Attribute',
);
-}, qr/compatible/;
+} qr/compatible/;
{
package Baz::Meta::Class;
extends 'Moose::Meta::Attribute';
}
-like exception {
+throws_ok {
Moose::Meta::Class->reinitialize(
'Baz',
method_metaclass => 'Baz::Meta::Method',
attribute_metaclass => 'Baz::Meta::Attribute',
);
-}, qr/compatible/;
+} qr/compatible/;
{
package Quux;
use lib 't/lib', 'lib';
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use File::Spec;
use File::Temp 'tempdir';
is($_->meta->name, $_, '... initialized the meta correctly');
- ok ! exception {
+ lives_ok {
Module::Refresh->new->refresh_module($_ . '.pm')
- }, '... successfully refreshed ' . $_;
+ } '... successfully refreshed ' . $_;
} foreach @modules;
=pod
close FILE;
}
-ok ! exception {
+lives_ok {
Module::Refresh->new->refresh_module('TestBaz.pm')
-}, '... successfully refreshed ' . $test_module_file;
+} '... successfully refreshed ' . $test_module_file;
is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
is( $foo_moose->moose, 'Foo',
'... got the right value from the Foo::Moose method' );
-ok ! exception {
+lives_ok {
Old::Bucket::Nose->meta->make_immutable( debug => 0 );
-},
+}
'Immutability on Moose class extending Class::MOP class ok';
-ok ! exception {
+lives_ok {
SubClass2->meta->superclasses('MyBase');
-},
+}
'Can subclass the same non-Moose class twice with different metaclasses';
done_testing;
package SubSubClassUseBase;
use Moose;
use Test::More;
- use Test::Fatal;
- ok ! exception {
+ use Test::Exception;
+ lives_ok {
extends 'SubClassUseBase';
- },
+ }
'Can extend non-Moose class with parent class that is a Moose class with a meta role';
}
package MultiParent1;
use Moose;
use Test::More;
- use Test::Fatal;
- ok ! exception {
+ use Test::Exception;
+ lives_ok {
extends qw( SubClassUseBase OtherSubClassUseBase );
- },
+ }
'Can extend two non-Moose classes with parents that are different Moose metaclasses';
}
package MultiParent2;
use Moose;
use Test::More;
- use Test::Fatal;
- ok ! exception {
+ use Test::Exception;
+ lives_ok {
extends qw( OtherSubClassUseBase SubClassUseBase );
- },
+ }
'Can extend two non-Moose classes with parents that are different Moose metaclasses (reverse order)';
}
package MultiParent3;
use Moose;
use Test::More;
- use Test::Fatal;
- ok ! exception {
+ use Test::Exception;
+ lives_ok {
extends qw( OtherClass SubClassUseBase );
- },
+ }
'Can extend one Moose class and one non-Moose class';
}
package MultiParent4;
use Moose;
use Test::More;
- use Test::Fatal;
- ok ! exception {
+ use Test::Exception;
+ lives_ok {
extends qw( SubClassUseBase OtherClass );
- },
+ }
'Can extend one non-Moose class and one Moose class';
}
package MultiChild1;
use Moose;
use Test::More;
- use Test::Fatal;
- ok ! exception {
+ use Test::Exception;
+ lives_ok {
extends 'MultiParent1';
- },
+ }
'Can extend class that itself extends two non-Moose classes with Moose parents';
}
package MultiChild2;
use Moose;
use Test::More;
- use Test::Fatal;
- ok ! exception {
+ use Test::Exception;
+ lives_ok {
extends 'MultiParent2';
- },
+ }
'Can extend class that itself extends two non-Moose classes with Moose parents (reverse order)';
}
package MultiChild3;
use Moose;
use Test::More;
- use Test::Fatal;
- ok ! exception {
+ use Test::Exception;
+ lives_ok {
extends 'MultiParent3';
- },
+ }
'Can extend class that itself extends one Moose and one non-Moose parent';
}
package MultiChild4;
use Moose;
use Test::More;
- use Test::Fatal;
- ok ! exception {
+ use Test::Exception;
+ lives_ok {
extends 'MultiParent4';
- },
+ }
'Can extend class that itself extends one non-Moose and one Moose parent';
}
use strict;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Test::Moose;
{
for => __PACKAGE__,
class_metaroles => { class => ['Foo::Role', 'Bar::Role'] },
);
- ::ok ! ::exception { extends 'Parent' };
+ ::lives_ok { extends 'Parent' };
}
with_immutable {
use Moose::Util::TypeConstraints;
use NoInlineAttribute;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Test::Moose;
{
ok( !$obj->is_empty, 'values is not empty' );
is( $obj->count, 3, 'count returns 3' );
- like exception { $obj->count(22) },
+ throws_ok { $obj->count(22) }
qr/Cannot call count with any arguments/,
'throws an error when passing an argument passed to count';
- ok ! exception { $obj->push( 1, 2, 3 ) },
+ lives_ok { $obj->push( 1, 2, 3 ) }
'pushed three new values and lived';
- ok ! exception { $obj->push() }, 'call to push without arguments lives';
+ lives_ok { $obj->push() } 'call to push without arguments lives';
- ok ! exception {
+ lives_and {
is( $obj->unshift( 101, 22 ), 8,
'unshift returns size of the new array' );
- },
+ }
'unshifted two values and lived';
is_deeply(
'unshift changed the value of the array in the object'
);
- ok ! exception { $obj->unshift() },
+ lives_ok { $obj->unshift() }
'call to unshift without arguments lives';
is( $obj->pop, 3, 'pop returns the last value in the array' );
'pop changed the value of the array in the object'
);
- like exception { $obj->pop(42) },
+ throws_ok { $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' );
- like exception { $obj->shift(42) },
+ throws_ok { $obj->shift(42) }
qr/Cannot call shift with any arguments/,
'call to shift with arguments dies';
'call to elements returns values as a list'
);
- like exception { $obj->elements(22) },
+ throws_ok { $obj->elements(22) }
qr/Cannot call elements with any arguments/,
'throws an error when passing an argument passed to elements';
is( $obj->get(2), 3, 'get values at index 2' );
is( $obj->get_curried, 2, 'get_curried returns value at index 1' );
- like exception { $obj->get() },
+ 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( {} ) },
+ 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(2.2) },
+ 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('foo') },
+ 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_curried(2) },
+ 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';
- ok ! exception {
+ lives_and {
is( $obj->set( 1, 100 ), 100, 'set returns new value' );
- },
+ }
'set value at index 1 lives';
is( $obj->get(1), 100, 'get value at index 1 returns new value' );
- like exception { $obj->set( 1, 99, 42 ) },
+ 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';
- ok ! exception { $obj->set_curried_1(99) }, 'set_curried_1 lives';
+ lives_ok { $obj->set_curried_1(99) } 'set_curried_1 lives';
is( $obj->get(1), 99, 'get value at index 1 returns new value' );
- like exception { $obj->set_curried_1( 99, 42 ) },
+ 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';
- ok ! exception { $obj->set_curried_2 }, 'set_curried_2 lives';
+ lives_ok { $obj->set_curried_2 } 'set_curried_2 lives';
is( $obj->get(1), 98, 'get value at index 1 returns new value' );
- like exception { $obj->set_curried_2(42) },
+ 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';
'accessor with one argument returns value at index 1'
);
- ok ! exception {
+ lives_and {
is( $obj->accessor( 1 => 97 ), 97, 'accessor returns new value' );
- },
+ }
'accessor as writer lives';
is(
'accessor set value at index 1'
);
- like exception { $obj->accessor( 1, 96, 42 ) },
+ 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';
'accessor_curried_1 returns expected value when called with no arguments'
);
- ok ! exception { $obj->accessor_curried_1(95) },
+ lives_ok { $obj->accessor_curried_1(95) }
'accessor_curried_1 as writer lives';
is(
'accessor_curried_1 set value at index 1'
);
- like exception { $obj->accessor_curried_1( 96, 42 ) },
+ 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';
- ok ! exception { $obj->accessor_curried_2 },
+ lives_ok { $obj->accessor_curried_2 }
'accessor_curried_2 as writer lives';
is(
'accessor_curried_2 set value at index 1'
);
- like exception { $obj->accessor_curried_2(42) },
+ 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';
- ok ! exception { $obj->clear }, 'clear lives';
+ lives_ok { $obj->clear } 'clear lives';
ok( $obj->is_empty, 'values is empty after call to clear' );
$obj->set( 0 => 42 );
- like exception { $obj->clear(50) },
+ throws_ok { $obj->clear(50) }
qr/Cannot call clear with any arguments/,
'throws an error when clear is called with an argument';
'values is not empty after failed call to clear'
);
- like exception { $obj->is_empty(50) },
+ 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';
'pushed 4 elements, got number of elements in the array back'
);
- ok ! exception {
+ lives_and {
is( $obj->delete(2), 10, 'delete returns deleted value' );
- },
+ }
'delete lives';
is_deeply(
'delete removed the specified element'
);
- like exception { $obj->delete( 2, 3 ) },
+ 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';
- ok ! exception { $obj->delete_curried }, 'delete_curried lives';
+ lives_ok { $obj->delete_curried } 'delete_curried lives';
is_deeply(
$obj->_values, [ 1, 42 ],
'delete removed the specified element'
);
- like exception { $obj->delete_curried(2) },
+ 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';
- ok ! exception { $obj->insert( 1, 21 ) }, 'insert lives';
+ lives_ok { $obj->insert( 1, 21 ) } 'insert lives';
is_deeply(
$obj->_values, [ 1, 21, 42 ],
'insert added the specified element'
);
- like exception { $obj->insert( 1, 22, 44 ) },
+ 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';
- ok ! exception {
+ lives_and {
is_deeply(
[ $obj->splice( 1, 0, 2, 3 ) ],
[],
'return value of splice is empty list when not removing elements'
);
- },
+ }
'splice lives';
is_deeply(
'splice added the specified elements'
);
- ok ! exception {
+ lives_and {
is_deeply(
[ $obj->splice( 1, 2, 99 ) ],
[ 2, 3 ],
'splice returns list of removed values'
);
- },
+ }
'splice lives';
is_deeply(
'splice added the specified elements'
);
- like exception { $obj->splice() },
+ 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( 1, 'foo', ) },
+ 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';
- ok ! exception { $obj->splice_curried_1( 2, 101 ) },
+ lives_ok { $obj->splice_curried_1( 2, 101 ) }
'splice_curried_1 lives';
is_deeply(
'splice added the specified elements'
);
- ok ! exception { $obj->splice_curried_2(102) }, 'splice_curried_2 lives';
+ lives_ok { $obj->splice_curried_2(102) } 'splice_curried_2 lives';
is_deeply(
$obj->_values, [ 1, 102 ],
'splice added the specified elements'
);
- ok ! exception { $obj->splice_curried_all }, 'splice_curried_all lives';
+ lives_ok { $obj->splice_curried_all } 'splice_curried_all lives';
is_deeply(
$obj->_values, [ 1, 3, 4, 5 ],
'sort returns values sorted by provided function'
);
- like exception { $obj->sort(1) },
+ 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 {
+ throws_ok {
$obj->sort( sub { }, 27 );
- },
+ }
qr/Cannot call sort with more than 1 argument/,
'throws an error when passing two arguments to sort';
'sort_in_place with function sorts values'
);
- like exception {
+ throws_ok {
$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';
- like exception {
+ throws_ok {
$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';
'sort_in_place_curried sorts values'
);
- like exception { $obj->sort_in_place_curried(27) },
+ 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';
'map returns the expected values'
);
- like exception { $obj->map },
+ throws_ok { $obj->map }
qr/Cannot call map without at least 1 argument/,
'throws an error when passing no arguments to map';
- like exception {
+ throws_ok {
$obj->map( sub { }, 2 );
- },
+ }
qr/Cannot call map with more than 1 argument/,
'throws an error when passing two arguments to map';
- like exception { $obj->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';
'map_curried returns the expected values'
);
- like exception {
+ throws_ok {
$obj->map_curried( sub { } );
- },
+ }
qr/Cannot call map with more than 1 argument/,
'throws an error when passing one argument passed to map_curried';
'grep returns the expected values'
);
- like exception { $obj->grep },
+ throws_ok { $obj->grep }
qr/Cannot call grep without at least 1 argument/,
'throws an error when passing no arguments to grep';
- like exception {
+ throws_ok {
$obj->grep( sub { }, 2 );
- },
+ }
qr/Cannot call grep with more than 1 argument/,
'throws an error when passing two arguments to grep';
- like exception { $obj->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';
'grep_curried returns the expected values'
);
- like exception {
+ throws_ok {
$obj->grep_curried( sub { } );
- },
+ }
qr/Cannot call grep with more than 1 argument/,
'throws an error when passing one argument passed to grep_curried';
'first returns expected value'
);
- like exception { $obj->first },
+ throws_ok { $obj->first }
qr/Cannot call first without at least 1 argument/,
'throws an error when passing no arguments to first';
- like exception {
+ throws_ok {
$obj->first( sub { }, 2 );
- },
+ }
qr/Cannot call first with more than 1 argument/,
'throws an error when passing two arguments to first';
- like exception { $obj->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';
'first_curried returns expected value'
);
- like exception {
+ throws_ok {
$obj->first_curried( sub { } );
- },
+ }
qr/Cannot call first with more than 1 argument/,
'throws an error when passing one argument passed to first_curried';
'join returns expected result when joining with empty string'
);
- like exception { $obj->join },
+ 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( '-', 2 ) },
+ 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( {} ) },
+ throws_ok { $obj->join( {} ) }
qr/The argument passed to join must be a string/,
'throws an error when passing a non string to join';
'shuffle returns all values (cannot check for a random order)'
);
- like exception { $obj->shuffle(2) },
+ throws_ok { $obj->shuffle(2) }
qr/Cannot call shuffle with any arguments/,
'throws an error when passing an argument passed to shuffle';
'uniq returns expected values (in original order)'
);
- like exception { $obj->uniq(2) },
+ throws_ok { $obj->uniq(2) }
qr/Cannot call uniq with any arguments/,
'throws an error when passing an argument passed to uniq';
'reduce returns expected value'
);
- like exception { $obj->reduce },
+ throws_ok { $obj->reduce }
qr/Cannot call reduce without at least 1 argument/,
'throws an error when passing no arguments to reduce';
- like exception {
+ throws_ok {
$obj->reduce( sub { }, 2 );
- },
+ }
qr/Cannot call reduce with more than 1 argument/,
'throws an error when passing two arguments to reduce';
- like exception { $obj->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';
'reduce_curried returns expected value'
);
- like exception {
+ throws_ok {
$obj->reduce_curried( sub { } );
- },
+ }
qr/Cannot call reduce with more than 1 argument/,
'throws an error when passing one argument passed to reduce_curried';
'natatime with function returns expected value'
);
- like exception { $obj->natatime( {} ) },
+ 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( 2, {} ) },
+ 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';
'natatime_curried with function returns expected value'
);
- like exception { $obj->natatime_curried( {} ) },
+ 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';
use strict;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
use Moose::Util::TypeConstraints;
$foo->array_int( [] );
is_deeply( $foo->array_int, [], "array_int - correct contents" );
- ok exception { $foo->push_array_int('foo') },
+ dies_ok { $foo->push_array_int('foo') }
"array_int - can't push wrong type";
is_deeply( $foo->array_int, [], "array_int - correct contents" );
}
{
- ok exception { $foo->push_a1('foo') }, "a1 - can't push onto undef";
+ dies_ok { $foo->push_a1('foo') } "a1 - can't push onto undef";
$foo->a1( [] );
is_deeply( $foo->a1, [], "a1 - correct contents" );
- ok exception { $foo->push_a1('foo') }, "a1 - can't push wrong type";
+ dies_ok { $foo->push_a1('foo') } "a1 - can't push wrong type";
is_deeply( $foo->a1, [], "a1 - correct contents" );
}
{
- ok exception { $foo->push_a2('foo') }, "a2 - can't push onto undef";
+ dies_ok { $foo->push_a2('foo') } "a2 - can't push onto undef";
$foo->a2( [] );
is_deeply( $foo->a2, [], "a2 - correct contents" );
$foo->push_a2('foo');
is_deeply( $foo->a2, ['foo'], "a2 - correct contents" );
- ok exception { $foo->push_a2('bar') }, "a2 - can't push more than one element";
+ dies_ok { $foo->push_a2('bar') } "a2 - can't push more than one element";
is_deeply( $foo->a2, ['foo'], "a2 - correct contents" );
}
{
- ok exception { $foo->push_a3(1) }, "a3 - can't push onto undef";
+ dies_ok { $foo->push_a3(1) } "a3 - can't push onto undef";
$foo->a3( [] );
is_deeply( $foo->a3, [], "a3 - correct contents" );
- ok exception { $foo->push_a3('foo') }, "a3 - can't push non-int";
+ dies_ok { $foo->push_a3('foo') } "a3 - can't push non-int";
- ok exception { $foo->push_a3(100) },
+ dies_ok { $foo->push_a3(100) }
"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" );
- ok exception { $foo->push_a3(100) },
+ dies_ok { $foo->push_a3(100) }
"a3 - can't violate overall type constraint";
is_deeply( $foo->a3, [1], "a3 - correct contents" );
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
use Moose::Util::TypeConstraints;
use NoInlineAttribute;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Test::Moose;
{
ok( $obj->is_lit, 'set is_lit to 1 using ->illuminate' );
ok( !$obj->is_dark, 'check if is_dark does the right thing' );
- like exception { $obj->illuminate(1) },
+ throws_ok { $obj->illuminate(1) }
qr/Cannot call set with any arguments/,
'set throws an error when an argument is passed';
ok( !$obj->is_lit, 'set is_lit to 0 using ->darken' );
ok( $obj->is_dark, 'check if is_dark does the right thing' );
- like exception { $obj->darken(1) },
+ throws_ok { $obj->darken(1) }
qr/Cannot call unset with any arguments/,
'unset throws an error when an argument is passed';
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' );
- like exception { $obj->flip_switch(1) },
+ throws_ok { $obj->flip_switch(1) }
qr/Cannot call toggle with any arguments/,
'toggle throws an error when an argument is passed';
use Moose ();
use Moose::Util::TypeConstraints;
use NoInlineAttribute;
-use Test::Fatal;
+use Test::Exception;
use Test::More;
use Test::Moose;
is( $obj->inc_counter, 2, 'inc returns new value' );
is( $obj->counter, 2, '... got the incremented value (again)' );
- like exception { $obj->inc_counter( 1, 2 ) },
+ 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';
is( $obj->dec_counter, 1, 'dec returns new value' );
is( $obj->counter, 1, '... got the decremented value' );
- like exception { $obj->dec_counter( 1, 2 ) },
+ 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';
is( $obj->reset_counter, 0, 'reset returns new value' );
is( $obj->counter, 0, '... got the original value' );
- like exception { $obj->reset_counter(2) },
+ throws_ok { $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' );
- like exception { $obj->set_counter( 1, 2 ) },
+ 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';
use Moose ();
use Moose::Util::TypeConstraints;
use NoInlineAttribute;
-use Test::Fatal;
+use Test::Exception;
use Test::More;
use Test::Moose;
is_deeply( $obj->options, {}, '... no options yet' );
ok( !$obj->has_option('foo'), '... we have no foo option' );
- ok ! exception {
+ lives_and {
is(
$obj->set_option( foo => 'bar' ),
'bar',
'set return single new value in scalar context'
);
- },
+ }
'... set the option okay';
ok( $obj->is_defined('foo'), '... foo is defined' );
ok( $obj->has_option('foo'), '... we have a foo option' );
is_deeply( $obj->options, { foo => 'bar' }, '... got options now' );
- ok ! exception {
+ lives_ok {
$obj->set_option( bar => 'baz' );
- },
+ }
'... set the option okay';
is( $obj->num_options, 2, '... we have 2 option(s)' );
'... got last option in scalar context'
);
- ok ! exception {
+ lives_ok {
$obj->set_option( oink => "blah", xxy => "flop" );
- },
+ }
'... set the option okay';
is( $obj->num_options, 4, "4 options" );
[qw(bar baz blah flop)], "get multiple options at once"
);
- ok ! exception {
+ lives_and {
is( scalar $obj->delete_option('bar'), 'baz',
'delete returns deleted value' );
- },
+ }
'... deleted the option okay';
- ok ! exception {
+ lives_ok {
is_deeply(
[ $obj->delete_option( 'oink', 'xxy' ) ],
[ 'blah', 'flop' ],
'delete returns all deleted values in list context'
);
- },
+ }
'... deleted multiple option okay';
is( $obj->num_options, 1, '... we have 1 option(s)' );
is_deeply( $obj->options, {}, "... cleared options" );
- ok ! exception {
+ lives_ok {
$obj->quantity(4);
- },
+ }
'... options added okay with defaults';
is( $obj->quantity, 4, 'reader part of curried accessor works' );
'... returns what we expect'
);
- ok ! exception {
+ lives_ok {
$class->new( options => { foo => 'BAR' } );
- },
+ }
'... good constructor params';
- ok exception {
+ dies_ok {
$obj->set_option( bar => {} );
- },
+ }
'... could not add a hash ref where an string is expected';
- ok exception {
+ dies_ok {
$class->new( options => { foo => [] } );
- },
+ }
'... bad constructor params';
is_deeply(
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
use Moose::Util::TypeConstraints;
$foo->hash_int( {} );
is_deeply( $foo->hash_int, {}, "hash_int - correct contents" );
- ok exception { $foo->set_hash_int( x => 'foo' ) },
+ dies_ok { $foo->set_hash_int( x => 'foo' ) }
"hash_int - can't set wrong type";
is_deeply( $foo->hash_int, {}, "hash_int - correct contents" );
}
{
- ok exception { $foo->set_h1('foo') }, "h1 - can't set onto undef";
+ dies_ok { $foo->set_h1('foo') } "h1 - can't set onto undef";
$foo->h1( {} );
is_deeply( $foo->h1, {}, "h1 - correct contents" );
- ok exception { $foo->set_h1( x => 'foo' ) }, "h1 - can't set wrong type";
+ dies_ok { $foo->set_h1( x => 'foo' ) } "h1 - can't set wrong type";
is_deeply( $foo->h1, {}, "h1 - correct contents" );
}
{
- ok exception { $foo->set_h2('foo') }, "h2 - can't set onto undef";
+ dies_ok { $foo->set_h2('foo') } "h2 - can't set onto undef";
$foo->h2( {} );
is_deeply( $foo->h2, {}, "h2 - correct contents" );
$foo->set_h2( x => 'foo' );
is_deeply( $foo->h2, { x => 'foo' }, "h2 - correct contents" );
- ok exception { $foo->set_h2( y => 'bar' ) },
+ dies_ok { $foo->set_h2( y => 'bar' ) }
"h2 - can't set more than one element";
is_deeply( $foo->h2, { x => 'foo' }, "h2 - correct contents" );
}
{
- ok exception { $foo->set_h3(1) }, "h3 - can't set onto undef";
+ dies_ok { $foo->set_h3(1) } "h3 - can't set onto undef";
$foo->h3( {} );
is_deeply( $foo->h3, {}, "h3 - correct contents" );
- ok exception { $foo->set_h3( x => 'foo' ) }, "h3 - can't set non-int";
+ dies_ok { $foo->set_h3( x => 'foo' ) } "h3 - can't set non-int";
- ok exception { $foo->set_h3( x => 100 ) },
+ dies_ok { $foo->set_h3( x => 100 ) }
"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" );
- ok exception { $foo->set_h3( x => 100 ) },
+ dies_ok { $foo->set_h3( x => 100 ) }
"h3 - can't violate overall type constraint";
is_deeply( $foo->h3, { x => 1 }, "h3 - correct contents" );
use Moose ();
use Moose::Util::TypeConstraints;
use NoInlineAttribute;
-use Test::Fatal;
+use Test::Exception;
use Test::More;
use Test::Moose;
is( $obj->integer, 15, 'Add ten for fithteen' );
- like exception { $obj->add( 10, 2 ) },
+ throws_ok { $obj->add( 10, 2 ) }
qr/Cannot call add with more than 1 argument/,
'add throws an error when 2 arguments are passed';
is( $obj->integer, 12, 'Subtract three for 12' );
- like exception { $obj->sub( 10, 2 ) },
+ throws_ok { $obj->sub( 10, 2 ) }
qr/Cannot call sub with more than 1 argument/,
'sub throws an error when 2 arguments are passed';
is( $obj->integer, 10, 'Set to ten' );
- like exception { $obj->set( 10, 2 ) },
+ throws_ok { $obj->set( 10, 2 ) }
qr/Cannot call set with more than 1 argument/,
'set throws an error when 2 arguments are passed';
is( $obj->integer, 5, 'divide by 2' );
- like exception { $obj->div( 10, 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';
is( $obj->integer, 10, 'multiplied by 2' );
- like exception { $obj->mul( 10, 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';
is( $obj->integer, 0, 'Mod by 2' );
- like exception { $obj->mod( 10, 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';
is( $obj->abs, 1, 'abs returns new value' );
- like exception { $obj->abs(10) },
+ throws_ok { $obj->abs(10) }
qr/Cannot call abs with any arguments/,
'abs throws an error when an argument is passed';
use Moose::Util::TypeConstraints;
use NoInlineAttribute;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Test::Moose;
{
$obj->_string('a');
is( $obj->length, 1, 'length returns 1 for new string' );
- like exception { $obj->length(42) },
+ throws_ok { $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' );
- like exception { $obj->inc(42) },
+ throws_ok { $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' );
- like exception { $obj->append( 'foo', 2 ) },
+ throws_ok { $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' );
- like exception { $obj->append_curried('foo') },
+ 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';
'chomp is a no-op when string has no line ending'
);
- like exception { $obj->chomp(42) },
+ throws_ok { $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' );
- like exception { $obj->chop(42) },
+ throws_ok { $obj->chop(42) }
qr/Cannot call chop with any arguments/,
'chop throws an error when an argument is passed';
is( $obj->_string, 'af',
'replace accepts an empty string as first argument' );
- like exception { $obj->replace( {}, 'x' ) },
+ 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( qr/x/, {} ) },
+ 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';
'match with empty string as argument returns true'
);
- like exception { $obj->match },
+ 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( {} ) },
+ 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';
$obj->clear;
is( $obj->_string, q{}, 'clear' );
- like exception { $obj->clear(42) },
+ throws_ok { $obj->clear(42) }
qr/Cannot call clear with any arguments/,
'clear throws an error when an argument is passed';
'substr as setter with three arguments, replacment is empty string'
);
- like exception { $obj->substr },
+ 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( 1, 2, 3, 4 ) },
+ 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( {} ) },
+ 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( 1, {} ) },
+ 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, 2, {} ) },
+ 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';
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package Foo;
package Stuff;
use Moose;
- ::ok ! ::exception { with 'Stuffed::Role';
- }, '... this should work correctly';
+ ::lives_ok{ with 'Stuffed::Role';
+ } '... this should work correctly';
- ::ok ! ::exception { with 'Bulkie::Role';
- }, '... this should work correctly';
+ ::lives_ok{ with 'Bulkie::Role';
+ } '... this should work correctly';
}
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package MyHomePage;
reset_counter
];
-ok ! exception {
+lives_ok {
$page->meta->remove_attribute('counter');
-},
+}
'... removed the counter attribute okay';
ok( !$page->meta->has_attribute('counter'),
use strict;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Test::Moose;
{
}
);
- ::ok ! ::exception {
+ ::lives_ok {
has array => (
traits => ['Array'],
isa => 'ArrayRef',
array_natatime_curried => [ natatime => 2 ],
},
);
- }, "native array trait inlines properly";
+ } "native array trait inlines properly";
- ::ok ! ::exception {
+ ::lives_ok {
has bool => (
traits => ['Bool'],
isa => 'Bool',
bool_is_dark => 'not',
},
);
- }, "native bool trait inlines properly";
+ } "native bool trait inlines properly";
- ::ok ! ::exception {
+ ::lives_ok {
has code => (
traits => ['Code'],
isa => 'CodeRef',
code_execute_method => 'execute_method',
},
);
- }, "native code trait inlines properly";
+ } "native code trait inlines properly";
- ::ok ! ::exception {
+ ::lives_ok {
has counter => (
traits => ['Counter'],
isa => 'Int',
set_counter_42 => [ set => 42 ],
},
);
- }, "native counter trait inlines properly";
+ } "native counter trait inlines properly";
- ::ok ! ::exception {
+ ::lives_ok {
has hash => (
traits => ['Hash'],
isa => 'HashRef',
hash_set_option => 'set',
},
);
- }, "native hash trait inlines properly";
+ } "native hash trait inlines properly";
- ::ok ! ::exception {
+ ::lives_ok {
has number => (
traits => ['Number'],
isa => 'Num',
num_dec => [ sub => 1 ],
},
);
- }, "native number trait inlines properly";
+ } "native number trait inlines properly";
- ::ok ! ::exception {
+ ::lives_ok {
has string => (
traits => ['String'],
is => 'ro',
string_substr_curried_3 => [ substr => ( 1, 3, 'ong' ) ],
},
);
- }, "native string trait inlines properly";
+ } "native string trait inlines properly";
}
with_immutable {
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
=pod
package Foo;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
has 'bar' => (
is => 'ro',
isa => 'Int',
lazy => 1,
default => 10,
);
- }, '... this didnt die';
+ } '... this didnt die';
}
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package Foo;
package Bar;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
has 'baz' => (
is => 'ro',
isa => 'Foo',
default => sub { Foo->new() },
handles => qr/^a$/,
);
- }, '... can create the attribute with delegations';
+ } '... can create the attribute with delegations';
}
my $bar;
-ok ! exception {
+lives_ok {
$bar = Bar->new;
-}, '... created the object ok';
+} '... created the object ok';
isa_ok($bar, 'Bar');
is($bar->a, 'Foo::a', '... got the right delgated value');
package Baz;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
has 'bar' => (
is => 'ro',
isa => 'Foo',
default => sub { Foo->new() },
handles => qr/.*/,
);
- }, '... can create the attribute with delegations';
+ } '... can create the attribute with delegations';
}
my $baz;
-ok ! exception {
+lives_ok {
$baz = Baz->new;
-}, '... created the object ok';
+} '... created the object ok';
isa_ok($baz, 'Baz');
is($baz->a, 'Foo::a', '... got the right delgated value');
package Blart;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
has 'bar' => (
is => 'ro',
isa => 'Foo',
default => sub { Foo->new() },
handles => [qw(a new)],
);
- }, '... can create the attribute with delegations';
+ } '... can create the attribute with delegations';
}
my $blart;
-ok ! exception {
+lives_ok {
$blart = Blart->new;
-}, '... created the object ok';
+} '... created the object ok';
isa_ok($blart, 'Blart');
is($blart->a, 'Foo::a', '... got the right delgated value');
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package My::Class;
use Moose;
- ::like ::exception {
+ ::throws_ok {
extends 'My::Role';
- }, qr/You cannot inherit from a Moose Role \(My\:\:Role\)/,
+ } qr/You cannot inherit from a Moose Role \(My\:\:Role\)/,
'... this croaks correctly';
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
# RT #37569
my $foo = Foo->new;
my $obj = MyObject->new;
-like exception {
+throws_ok {
$foo->ar( [] );
-},
+}
qr/Attribute \(ar\) does not pass the type constraint because: ref: ARRAY/,
'... got the right error message';
-like exception {
+throws_ok {
$foo->obj($foo); # Doh!
-},
+}
qr/Attribute \(obj\) does not pass the type constraint because: Well it is an object/,
'... got the right error message';
-like exception {
+throws_ok {
$foo->nt($foo); # scalar
-},
+}
qr/Attribute \(nt\) does not pass the type constraint because: blessed/,
'... got the right error message';
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
BEGIN {
ok( MyClass->meta->meta->does_role('MyRole'), 'metaclass does MyRole' );
is( MyClass->meta->foo, 'i am foo', '... foo method returns expected value' );
-ok ! exception {
+lives_ok {
MyClass->meta->make_immutable;
-}, '... make MyClass immutable okay';
+} '... 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');
ok( MyClass->meta->meta->does_role('MyRole'), 'metaclass does MyRole' );
is( MyClass->meta->foo, 'i am foo', '... foo method returns expected value' );
-ok ! exception {
+lives_ok {
MyClass->meta->make_mutable;
-}, '... make MyClass mutable okay';
+} '... 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');
ok( MyClass->meta->meta->does_role('MyRole'), 'metaclass does MyRole' );
is( MyClass->meta->foo, 'i am foo', '... foo method returns expected value' );
-ok ! exception {
+lives_ok {
MyMetaclass->meta->make_immutable;
-}, '... make MyMetaclass immutable okay';
+} '... 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');
ok( MyClass->meta->meta->does_role('MyRole'), 'metaclass does MyRole' );
is( MyClass->meta->foo, 'i am foo', '... foo method returns expected value' );
-ok ! exception {
+lives_ok {
MyClass->meta->make_immutable;
-}, '... make MyClass immutable (again) okay';
+} '... 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');
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package MyClass;
# The bug happened when DEMOLISHALL called
# Class::MOP::class_of($object) and did not get a metaclass object
# back.
-ok ! exception { $object->DESTROY },
+lives_ok { $object->DESTROY }
'can call DESTROY on an object without a metaclass object in the CMOP cache';
# The bug didn't manifest for immutable objects, but this test should
# help us prevent it happening in the future.
-ok ! exception { $object->DESTROY },
+lives_ok { $object->DESTROY }
'can call DESTROY on an object without a metaclass object in the CMOP cache (immutable version)';
done_testing;
use strict;
use warnings;
-use Test::Fatal;
+use Test::Exception;
use Test::More;
{
local $TODO = 'UNIVERSAL methods should be wrappable';
- ::ok ! ::exception { with 'FakeBar' }, 'applied role';
+ ::lives_ok { with 'FakeBar' } 'applied role';
my $foo = Foo->new;
::isa_ok $foo, 'Bar';
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Meta::Class;
= 'Loading Moose::Meta::Class without loading Moose.pm causes weird problems';
my $meta;
- ok ! exception {
+ lives_ok {
$meta = Moose::Meta::Class->create_anon_class(
superclasses => [ 'Moose::Object', ],
);
- },
+ }
'Class is created successfully';
}
use strict;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package MyRole1;
ok (($instance_with_role1->does('MyRole1')),
'role was applied to the correct instance');
-ok ! exception {
+lives_and {
is $instance_with_role1->a_role_method, 'foo'
-}, 'instance has correct role method';
+} 'instance has correct role method';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Test::Moose;
{
}
with_immutable {
- ok ! exception { Foo->new( x => {} ) },
+ lives_ok { Foo->new( x => {} ) }
'Setting coerce => 1 without a coercion on the type does not cause an error in the constructor';
- ok ! exception { Foo->new->x( {} ) },
+ lives_ok { Foo->new->x( {} ) }
'Setting coerce => 1 without a coercion on the type does not cause an error when setting the attribut';
- like exception { Foo->new( x => 42 ) },
+ 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) },
+ 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';
}
'DateTime::Format::MySQL' => '0.01',
};
-use Test::Fatal;
+use Test::Exception;
BEGIN {
# in case there are leftovers
my $article_ref;
{
my $article;
- ok ! exception {
+ lives_ok {
$article = Newswriter::Article->new(
headline => 'Home Office Redecorated',
summary => 'The home office was recently redecorated to match the new company colors',
status => 'pending'
);
- }, '... created my article successfully';
+ } '... created my article successfully';
isa_ok($article, 'Newswriter::Article');
isa_ok($article, 'MooseX::POOP::Object');
- ok ! exception {
+ lives_ok {
$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';
+ } '... add the article date-time stuff';
## check some meta stuff
my $article2_ref;
{
my $article2;
- ok ! exception {
+ lives_ok {
$article2 = Newswriter::Article->new(
headline => 'Company wins Lottery',
summary => 'An email was received today that informed the company we have won the lottery',
status => 'posted'
);
- }, '... created my article successfully';
+ } '... created my article successfully';
isa_ok($article2, 'Newswriter::Article');
isa_ok($article2, 'MooseX::POOP::Object');
## orig-article
my $article;
- ok ! exception {
+ lives_ok {
$article = Newswriter::Article->new(oid => $article_oid);
- }, '... (re)-created my article successfully';
+ } '... (re)-created my article successfully';
isa_ok($article, 'Newswriter::Article');
isa_ok($article, 'MooseX::POOP::Object');
is($article->author->first_name, 'Truman', '... got the right author first name');
is($article->author->last_name, 'Capote', '... got the right author last name');
- ok ! exception {
+ lives_ok {
$article->author->first_name('Dan');
$article->author->last_name('Rather');
- }, '... changed the value ok';
+ } '... 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');
{
my $article;
- ok ! exception {
+ lives_ok {
$article = Newswriter::Article->new(oid => $article_oid);
- }, '... (re)-created my article successfully';
+ } '... (re)-created my article successfully';
isa_ok($article, 'Newswriter::Article');
isa_ok($article, 'MooseX::POOP::Object');
is($article->status, 'pending', '... got the right status');
my $article2;
- ok ! exception {
+ lives_ok {
$article2 = Newswriter::Article->new(oid => $article2_oid);
- }, '... (re)-created my article successfully';
+ } '... (re)-created my article successfully';
isa_ok($article2, 'Newswriter::Article');
isa_ok($article2, 'MooseX::POOP::Object');
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
sub U {
my $f = shift;
package My::List1;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'List', 'List::Immutable';
- }, '... successfully composed roles together';
+ } '... successfully composed roles together';
package My::List2;
use Moose;
- ::ok ! ::exception {
+ ::lives_ok {
with 'List::Immutable', 'List';
- }, '... successfully composed roles together';
+ } '... successfully composed roles together';
}
'Declare::Constraints::Simple' => '0.01', # skip all if not installed
};
-use Test::Fatal;
+use Test::Exception;
{
package Foo;
my $array_of_ints = [ 1 .. 10 ];
my $foo;
-ok ! exception {
+lives_ok {
$foo = Foo->new(
'bar' => $hash_of_arrays_of_objs,
'baz' => $array_of_ints,
);
-}, '... construction succeeded';
+} '... 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');
-ok exception {
+dies_ok {
$foo->bar([]);
-}, '... validation failed correctly';
+} '... validation failed correctly';
-ok exception {
+dies_ok {
$foo->bar({ foo => 3 });
-}, '... validation failed correctly';
+} '... validation failed correctly';
-ok exception {
+dies_ok {
$foo->bar({ foo => [ 1, 2, 3 ] });
-}, '... validation failed correctly';
+} '... validation failed correctly';
-ok exception {
+dies_ok {
$foo->baz([ "foo" ]);
-}, '... validation failed correctly';
+} '... validation failed correctly';
-ok exception {
+dies_ok {
$foo->baz({});
-}, '... validation failed correctly';
+} '... validation failed correctly';
done_testing;
'Test::Deep' => '0.01', # skip all if not installed
};
-use Test::Fatal;
+use Test::Exception;
{
package Foo;
];
my $foo;
-ok ! exception {
+lives_ok {
$foo = Foo->new('bar' => $array_of_hashes);
-}, '... construction succeeded';
+} '... construction succeeded';
isa_ok($foo, 'Foo');
is_deeply($foo->bar, $array_of_hashes, '... got our value correctly');
-ok exception {
+dies_ok {
$foo->bar({});
-}, '... validation failed correctly';
+} '... validation failed correctly';
-ok exception {
+dies_ok {
$foo->bar([{ foo => 3 }]);
-}, '... validation failed correctly';
+} '... validation failed correctly';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Meta::Role;
my $foo_role = Moose::Meta::Role->initialize('FooRole');
my $meta = Foo->meta;
- ok ! exception { Foo->new }, "lazy_build works";
+ lives_ok { Foo->new } "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" );
- ok ! exception { $meta->make_immutable }, "Foo is imutable";
- ok ! exception { $meta->identifier }, "->identifier on metaclass lives";
- ok exception { $meta->add_role($foo_role) }, "Add Role is locked";
- ok ! exception { Foo->new }, "Inlined constructor works with lazy_build";
+ 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( 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" );
- ok ! exception { $meta->make_mutable }, "Foo is mutable";
- ok ! exception { $meta->add_role($foo_role) }, "Add Role is unlocked";
+ lives_ok { $meta->make_mutable } "Foo is mutable";
+ lives_ok { $meta->add_role($foo_role) } "Add Role is unlocked";
}
sub BUILD { 'baz' }
}
-ok ! exception { Bar->meta->make_immutable },
+lives_ok { Bar->meta->make_immutable }
'Immutable meta with single BUILD';
-ok ! exception { Baz->meta->make_immutable },
+lives_ok { Baz->meta->make_immutable }
'Immutable meta with multiple BUILDs';
=pod
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
is($foo->baz, 'Foo::baz', '... got the right value');
-ok ! exception {
+lives_ok {
My::Role->meta->apply($foo)
-}, '... successfully applied the role to immutable instance';
+} '... successfully applied the role to immutable instance';
is($foo->baz, 'My::Role::baz(Foo::baz)', '... got the right value');
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
);
}
-ok ! exception {
+lives_ok {
My::Meta->meta()->make_immutable(debug => 0)
-}, '... can make a meta class immutable';
+} '... can make a meta class immutable';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
=pod
for (1..2) {
my $is_immutable = Foo->meta->is_immutable;
my $mutable_string = $is_immutable ? 'immutable' : 'mutable';
- ok ! exception {
+ lives_ok {
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)";
+ } "... this passes the constuctor correctly ($mutable_string)";
- ok ! exception {
+ lives_ok {
Foo->new(foo => 10, bar => "Hello World", baz => 10, zot => "not an int");
- }, "... the constructor doesn't care about 'zot' ($mutable_string)";
+ } "... the constructor doesn't care about 'zot' ($mutable_string)";
- ok exception {
+ dies_ok {
Foo->new(foo => "Hello World", bar => 100, baz => "Hello World");
- }, "... this fails the constuctor correctly ($mutable_string)";
+ } "... this fails the constuctor correctly ($mutable_string)";
Foo->meta->make_immutable(debug => 0) unless $is_immutable;
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
sub DEMOLISH { }
}
-ok ! exception {
+lives_ok {
Bar->new();
-}, 'Bar->new()';
+} 'Bar->new()';
-ok ! exception {
+lives_ok {
Bar->meta->make_immutable;
-}, 'Bar->meta->make_immutable';
+} 'Bar->meta->make_immutable';
is( Bar->meta->get_method('DESTROY')->package_name, 'Bar',
'Bar has a DESTROY method in the Bar class (not inherited)' );
-ok ! exception {
+lives_ok {
Foo->meta->make_immutable;
-}, 'Foo->meta->make_immutable';
+} 'Foo->meta->make_immutable';
is( Foo->meta->get_method('DESTROY')->package_name, 'Foo',
'Foo has a DESTROY method in the Bar class (not inherited)' );
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
eval { AClass->new(baz => 'bar') };
like ($@, qr/^Pulling the Baz trigger/, "trigger from immutable constructor");
-ok ! exception { AClass->new(bar => 'bar') }, '... no triggers called';
+lives_ok { AClass->new(bar => 'bar') } '... no triggers called';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
=pod
}
my $scalar = 1;
-like exception { Foo->new($scalar) }, qr/\QSingle parameters to new() must be a HASH ref/,
+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';
-like exception { Foo->new(\$scalar) }, qr/\QSingle parameters to new() must be a HASH ref/,
+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';
-like exception { Foo->new(undef) }, qr/\QSingle parameters to new() must be a HASH ref/,
+throws_ok { Foo->new(undef) } qr/\QSingle parameters to new() must be a HASH ref/,
'undef provided to immutable constructor gives useful error message';
done_testing;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
has 'buz' => ( is => 'rw', default => q{"'\\} );
has 'faz' => ( is => 'rw', default => qq{\0} );
- ::ok ! ::exception { __PACKAGE__->meta->make_immutable },
+ ::lives_ok { __PACKAGE__->meta->make_immutable }
'no errors making a package immutable when it has default values that could break quoting';
}
has 'buz' => ( is => 'rw', default => q{"'\\}, lazy => 1 );
has 'faz' => ( is => 'rw', default => qq{\0}, lazy => 1 );
- ::ok ! ::exception { __PACKAGE__->meta->make_immutable },
+ ::lives_ok { __PACKAGE__->meta->make_immutable }
'no errors making a package immutable when it has lazy default values that could break quoting';
}
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
use Moose::Util qw( add_method_modifier );
my $COUNT = 0;
sub bar { }
}
-ok ! exception {
+lives_ok {
add_method_modifier('Foo', 'before', [ ['foo', 'bar'], sub { $COUNT++ } ]);
-}, 'method modifier with an arrayref';
+} 'method modifier with an arrayref';
-ok exception {
+dies_ok {
add_method_modifier('Foo', 'before', [ {'foo' => 'bar'}, sub { $COUNT++ } ]);
-}, 'method modifier with a hashref';
+} 'method modifier with a hashref';
my $foo = Foo->new;
$foo->foo;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
BEGIN {
use_ok('Moose::Util::TypeConstraints');
}
-ok ! exception {
+lives_ok {
subtype 'ParentConstraint' => as 'Str' => where {0};
-}, 'specified parent type constraint';
+} 'specified parent type constraint';
my $tc;
-ok ! exception {
+lives_ok {
$tc = subtype 'ChildConstraint' => as 'ParentConstraint' => where {1};
-}, 'specified child type constraint';
+} 'specified child type constraint';
{
my $errmsg = $tc->validate();
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
sub req_or_has ($$) {
my ( $role, $method ) = @_;
# this doesn't fail but it produces a requires in the role
# the order doesn't matter
has twist => ( is => "rw" );
- ::ok ! ::exception { with qw(Dancer) };
+ ::lives_ok { with qw(Dancer) };
package Dancer::Something;
use Moose;
has twist => ( is => "rw" );
{
- ::ok ! ::exception { with qw(Dancer) };
+ ::lives_ok { with qw(Dancer) };
}
package Dancer::80s;
# but due to the deferrence logic that doesn't actually work
{
local our $TODO = "attribute accessor in role doesn't satisfy role requires";
- ::ok ! ::exception { with qw(Dancer::Robot) };
+ ::lives_ok { with qw(Dancer::Robot) };
}
package Foo;
{
local our $TODO = "attrs and methods from a role should clash";
- ::ok ::exception { with qw(Tree Dog) },
+ ::dies_ok { with qw(Tree Dog) }
}
}
use strict;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
{
package Foo::API;
package Foo::Class;
use Moose;
{ our $TODO; local $TODO = "role accessors don't satisfy other role requires";
- ::ok ! ::exception { with 'Foo' }, 'requirements are satisfied properly';
+ ::lives_ok { with 'Foo' } 'requirements are satisfied properly';
}
}
use Moose;
{ our $TODO; local $TODO = "role accessors don't satisfy other role requires";
- ::ok ! ::exception { with qw(Bar Baz) }, 'requirements are satisfied properly';
+ ::lives_ok { with qw(Bar Baz) } 'requirements are satisfied properly';
}
}
use strict;
use warnings;
use Test::More;
-use Test::Fatal;
+use Test::Exception;
BEGIN {
{
package Child;
use Moose -traits => 'Bar';
{ our $TODO; local $TODO = "no idea what's going on here";
- ::ok ! ::exception { extends 'Parent' };
+ ::lives_ok { extends 'Parent' };
}
}