requires 'Scalar::Util' => '0';
requires 'Sub::Exporter' => '0';
-build_requires 'Test::More' => '0.88';
-build_requires 'Test::Exception' => '0.21';
+build_requires 'Test::Fatal' => '0.001';
+build_requires 'Test::More' => '0.88';
license 'Perl';
use warnings;
use Test::More;
-use Test::Exception;
+use Test::Fatal;
{
package Roles::Blah;
my %params = validated_hash(
\@_,
foo => {
- isa => subtype( 'Object' => where { $_->isa('Foo') } ),
+ isa => subtype( 'Object' => where { $_->isa('Foo') } ),
optional => 1
},
bar => { does => 'Roles::Blah', optional => 1 },
isa_ok( $foo, 'Foo' );
is( $foo->foo, 'Horray for Moose!', '... got the right return value' );
-is( $foo->foo( bar => 'Rolsky' ), 'Horray for Rolsky!',
- '... got the right return value' );
+is(
+ $foo->foo( bar => 'Rolsky' ), 'Horray for Rolsky!',
+ '... got the right return value'
+);
is( $foo->baz( foo => $foo ), $foo, '... foo param must be a Foo instance' );
-throws_ok { $foo->baz( foo => 10 ) } qr/\QThe 'foo' parameter ("10")/,
- '... the foo param in &baz must be a Foo instance';
-throws_ok { $foo->baz( foo => "foo" ) } qr/\QThe 'foo' parameter ("foo")/,
- '... the foo param in &baz must be a Foo instance';
-throws_ok { $foo->baz( foo => [] ) } qr/\QThe 'foo' parameter/,
- '... the foo param in &baz must be a Foo instance';
+like(
+ exception { $foo->baz( foo => 10 ) }, qr/\QThe 'foo' parameter ("10")/,
+ '... the foo param in &baz must be a Foo instance'
+);
+like(
+ exception { $foo->baz( foo => "foo" ) },
+ qr/\QThe 'foo' parameter ("foo")/,
+ '... the foo param in &baz must be a Foo instance'
+);
+like(
+ exception { $foo->baz( foo => [] ) }, qr/\QThe 'foo' parameter/,
+ '... the foo param in &baz must be a Foo instance'
+);
is( $foo->baz( bar => $foo ), $foo, '... bar param must do Roles::Blah' );
-throws_ok { $foo->baz( bar => 10 ) } qr/\QThe 'bar' parameter ("10")/,
-'... the bar param in &baz must be do Roles::Blah';
-throws_ok { $foo->baz( bar => "foo" ) } qr/\QThe 'bar' parameter ("foo")/,
-'... the bar param in &baz must be do Roles::Blah';
-throws_ok { $foo->baz( bar => [] ) } qr/\QThe 'bar' parameter/,
-'... the bar param in &baz must be do Roles::Blah';
+like(
+ exception { $foo->baz( bar => 10 ) }, qr/\QThe 'bar' parameter ("10")/,
+ '... the bar param in &baz must be do Roles::Blah'
+);
+like(
+ exception { $foo->baz( bar => "foo" ) },
+ qr/\QThe 'bar' parameter ("foo")/,
+ '... the bar param in &baz must be do Roles::Blah'
+);
+like(
+ exception { $foo->baz( bar => [] ) }, qr/\QThe 'bar' parameter/,
+ '... the bar param in &baz must be do Roles::Blah'
+);
is( $foo->baz( boo => $foo ), $foo, '... boo param must do Roles::Blah' );
-throws_ok { $foo->baz( boo => 10 ) } qr/\QThe 'boo' parameter ("10")/,
-'... the boo param in &baz must be do Roles::Blah';
-throws_ok { $foo->baz( boo => "foo" ) } qr/\QThe 'boo' parameter ("foo")/,
-'... the boo param in &baz must be do Roles::Blah';
-throws_ok { $foo->baz( boo => [] ) } qr/\QThe 'boo' parameter/,
-'... the boo param in &baz must be do Roles::Blah';
-
-throws_ok { $foo->bar } qr/\QMandatory parameter 'foo'/,
- '... bar has a required param';
-throws_ok { $foo->bar( foo => 10 ) } qr/\QThe 'foo' parameter ("10")/,
- '... the foo param in &bar must be a Foo instance';
-throws_ok { $foo->bar( foo => "foo" ) } qr/\QThe 'foo' parameter ("foo")/,
- '... the foo param in &bar must be a Foo instance';
-throws_ok { $foo->bar( foo => [] ) } qr/\QThe 'foo' parameter/,
- '... the foo param in &bar must be a Foo instance';
-throws_ok { $foo->bar( baz => [] ) } qr/\QMandatory parameter 'foo'/,,
- '... bar has a required foo param';
+like(
+ exception { $foo->baz( boo => 10 ) }, qr/\QThe 'boo' parameter ("10")/,
+ '... the boo param in &baz must be do Roles::Blah'
+);
+like(
+ exception { $foo->baz( boo => "foo" ) },
+ qr/\QThe 'boo' parameter ("foo")/,
+ '... the boo param in &baz must be do Roles::Blah'
+);
+like(
+ exception { $foo->baz( boo => [] ) }, qr/\QThe 'boo' parameter/,
+ '... the boo param in &baz must be do Roles::Blah'
+);
+
+like(
+ exception { $foo->bar }, qr/\QMandatory parameter 'foo'/,
+ '... bar has a required param'
+);
+like(
+ exception { $foo->bar( foo => 10 ) }, qr/\QThe 'foo' parameter ("10")/,
+ '... the foo param in &bar must be a Foo instance'
+);
+like(
+ exception { $foo->bar( foo => "foo" ) },
+ qr/\QThe 'foo' parameter ("foo")/,
+ '... the foo param in &bar must be a Foo instance'
+);
+like(
+ exception { $foo->bar( foo => [] ) }, qr/\QThe 'foo' parameter/,
+ '... the foo param in &bar must be a Foo instance'
+);
+like( exception { $foo->bar( baz => [] ) }, qr/\QMandatory parameter 'foo'/ );
is_deeply(
$foo->bar( foo => $foo ),
'... the foo param and baz param in &bar got a correct args'
);
-throws_ok { $foo->bar( foo => $foo, baz => undef ) }
-qr/\QThe 'baz' parameter (undef)/,
- '... baz requires a ArrayRef | HashRef';
-throws_ok { $foo->bar( foo => $foo, baz => 10 ) }
-qr/\QThe 'baz' parameter ("10")/,
- '... baz requires a ArrayRef | HashRef';
-throws_ok { $foo->bar( foo => $foo, baz => 'Foo' ) }
-qr/\QThe 'baz' parameter ("Foo")/,
- '... baz requires a ArrayRef | HashRef';
-throws_ok { $foo->bar( foo => $foo, baz => \( my $var ) ) }
-qr/\QThe 'baz' parameter/,
- '... baz requires a ArrayRef | HashRef';
+like(
+ exception { $foo->bar( foo => $foo, baz => undef ) },
+ qr/\QThe 'baz' parameter (undef)/,
+ '... baz requires a ArrayRef | HashRef'
+);
+like(
+ exception { $foo->bar( foo => $foo, baz => 10 ) },
+ qr/\QThe 'baz' parameter ("10")/,
+ '... baz requires a ArrayRef | HashRef'
+);
+like(
+ exception { $foo->bar( foo => $foo, baz => 'Foo' ) },
+ qr/\QThe 'baz' parameter ("Foo")/,
+ '... baz requires a ArrayRef | HashRef'
+);
+like(
+ exception { $foo->bar( foo => $foo, baz => \( my $var ) ) },
+ qr/\QThe 'baz' parameter/, '... baz requires a ArrayRef | HashRef'
+);
is_deeply(
$foo->bar( foo => $foo, gorch => [ 1, 2, 3 ] ),
'... the foo param in &bar got a Foo instance'
);
-throws_ok { $foo->bar( foo => $foo, gorch => undef ) }
-qr/\QThe 'gorch' parameter (undef)/,
- '... gorch requires a ArrayRef[Int]';
-throws_ok { $foo->bar( foo => $foo, gorch => 10 ) }
-qr/\QThe 'gorch' parameter ("10")/,
- '... gorch requires a ArrayRef[Int]';
-throws_ok { $foo->bar( foo => $foo, gorch => 'Foo' ) }
-qr/\QThe 'gorch' parameter ("Foo")/,
- '... gorch requires a ArrayRef[Int]';
-throws_ok { $foo->bar( foo => $foo, gorch => \( my $var ) ) }
-qr/\QThe 'gorch' parameter/,
- '... gorch requires a ArrayRef[Int]';
-throws_ok { $foo->bar( foo => $foo, gorch => [qw/one two three/] ) }
-qr/\QThe 'gorch' parameter/,
- '... gorch requires a ArrayRef[Int]';
-
-throws_ok { $foo->quux( foo => '123456790' ) }
-qr/\QThe 'foo' parameter\E.+\Qchecking type constraint/,
-'... foo parameter must be an ArrayRef';
-
-throws_ok { $foo->quux( foo => [ 1, 2, 3, 4 ] ) }
-qr/\QThe 'foo' parameter\E.+\Qsome random callback/,
-'... foo parameter additional callback requires that arrayref be 0-2 elements';
+like(
+ exception { $foo->bar( foo => $foo, gorch => undef ) },
+ qr/\QThe 'gorch' parameter (undef)/,
+ '... gorch requires a ArrayRef[Int]'
+);
+like(
+ exception { $foo->bar( foo => $foo, gorch => 10 ) },
+ qr/\QThe 'gorch' parameter ("10")/,
+ '... gorch requires a ArrayRef[Int]'
+);
+like(
+ exception { $foo->bar( foo => $foo, gorch => 'Foo' ) },
+ qr/\QThe 'gorch' parameter ("Foo")/,
+ '... gorch requires a ArrayRef[Int]'
+);
+like(
+ exception { $foo->bar( foo => $foo, gorch => \( my $var ) ) },
+ qr/\QThe 'gorch' parameter/, '... gorch requires a ArrayRef[Int]'
+);
+like(
+ exception { $foo->bar( foo => $foo, gorch => [qw/one two three/] ) },
+ qr/\QThe 'gorch' parameter/, '... gorch requires a ArrayRef[Int]'
+);
+
+like(
+ exception { $foo->quux( foo => '123456790' ) },
+ qr/\QThe 'foo' parameter\E.+\Qchecking type constraint/,
+ '... foo parameter must be an ArrayRef'
+);
+
+like(
+ exception { $foo->quux( foo => [ 1, 2, 3, 4 ] ) },
+ qr/\QThe 'foo' parameter\E.+\Qsome random callback/,
+ '... foo parameter additional callback requires that arrayref be 0-2 elements'
+);
done_testing();
use warnings;
use Test::More;
-use Test::Exception;
+use Test::Fatal;
{
package Roles::Blah;
my ( $foo, $bar, $boo ) = validated_list(
\@_,
foo => {
- isa => subtype( 'Object' => where { $_->isa('Foo') } ),
+ isa => subtype( 'Object' => where { $_->isa('Foo') } ),
optional => 1
},
bar => { does => 'Roles::Blah', optional => 1 },
isa_ok( $foo, 'Foo' );
is( $foo->foo, 'Horray for Moose!', '... got the right return value' );
-is( $foo->foo( bar => 'Rolsky' ), 'Horray for Rolsky!',
- '... got the right return value' );
+is(
+ $foo->foo( bar => 'Rolsky' ), 'Horray for Rolsky!',
+ '... got the right return value'
+);
is( $foo->baz( foo => $foo ), $foo, '... foo param must be a Foo instance' );
-throws_ok { $foo->baz( foo => 10 ) } qr/\QThe 'foo' parameter ("10")/,
- '... the foo param in &baz must be a Foo instance';
-throws_ok { $foo->baz( foo => "foo" ) } qr/\QThe 'foo' parameter ("foo")/,
- '... the foo param in &baz must be a Foo instance';
-throws_ok { $foo->baz( foo => [] ) } qr/\QThe 'foo' parameter/,
- '... the foo param in &baz must be a Foo instance';
+like(
+ exception { $foo->baz( foo => 10 ) }, qr/\QThe 'foo' parameter ("10")/,
+ '... the foo param in &baz must be a Foo instance'
+);
+like(
+ exception { $foo->baz( foo => "foo" ) },
+ qr/\QThe 'foo' parameter ("foo")/,
+ '... the foo param in &baz must be a Foo instance'
+);
+like(
+ exception { $foo->baz( foo => [] ) }, qr/\QThe 'foo' parameter/,
+ '... the foo param in &baz must be a Foo instance'
+);
is( $foo->baz( bar => $foo ), $foo, '... bar param must do Roles::Blah' );
-throws_ok { $foo->baz( bar => 10 ) } qr/\QThe 'bar' parameter ("10")/,
-'... the bar param in &baz must be do Roles::Blah';
-throws_ok { $foo->baz( bar => "foo" ) } qr/\QThe 'bar' parameter ("foo")/,
-'... the bar param in &baz must be do Roles::Blah';
-throws_ok { $foo->baz( bar => [] ) } qr/\QThe 'bar' parameter/,
-'... the bar param in &baz must be do Roles::Blah';
+like(
+ exception { $foo->baz( bar => 10 ) }, qr/\QThe 'bar' parameter ("10")/,
+ '... the bar param in &baz must be do Roles::Blah'
+);
+like(
+ exception { $foo->baz( bar => "foo" ) },
+ qr/\QThe 'bar' parameter ("foo")/,
+ '... the bar param in &baz must be do Roles::Blah'
+);
+like(
+ exception { $foo->baz( bar => [] ) }, qr/\QThe 'bar' parameter/,
+ '... the bar param in &baz must be do Roles::Blah'
+);
is( $foo->baz( boo => $foo ), $foo, '... boo param must do Roles::Blah' );
-throws_ok { $foo->baz( boo => 10 ) } qr/\QThe 'boo' parameter ("10")/,
-'... the boo param in &baz must be do Roles::Blah';
-throws_ok { $foo->baz( boo => "foo" ) } qr/\QThe 'boo' parameter ("foo")/,
-'... the boo param in &baz must be do Roles::Blah';
-throws_ok { $foo->baz( boo => [] ) } qr/\QThe 'boo' parameter/,
-'... the boo param in &baz must be do Roles::Blah';
-
-throws_ok { $foo->bar } qr/\QMandatory parameter 'foo'/,
- '... bar has a required param';
-throws_ok { $foo->bar( foo => 10 ) } qr/\QThe 'foo' parameter ("10")/,
- '... the foo param in &bar must be a Foo instance';
-throws_ok { $foo->bar( foo => "foo" ) } qr/\QThe 'foo' parameter ("foo")/,
- '... the foo param in &bar must be a Foo instance';
-throws_ok { $foo->bar( foo => [] ) } qr/\QThe 'foo' parameter/,
- '... the foo param in &bar must be a Foo instance';
-throws_ok { $foo->bar( baz => [] ) } qr/\QMandatory parameter 'foo'/,,
- '... bar has a required foo param';
+like(
+ exception { $foo->baz( boo => 10 ) }, qr/\QThe 'boo' parameter ("10")/,
+ '... the boo param in &baz must be do Roles::Blah'
+);
+like(
+ exception { $foo->baz( boo => "foo" ) },
+ qr/\QThe 'boo' parameter ("foo")/,
+ '... the boo param in &baz must be do Roles::Blah'
+);
+like(
+ exception { $foo->baz( boo => [] ) }, qr/\QThe 'boo' parameter/,
+ '... the boo param in &baz must be do Roles::Blah'
+);
+
+like(
+ exception { $foo->bar }, qr/\QMandatory parameter 'foo'/,
+ '... bar has a required param'
+);
+like(
+ exception { $foo->bar( foo => 10 ) }, qr/\QThe 'foo' parameter ("10")/,
+ '... the foo param in &bar must be a Foo instance'
+);
+like(
+ exception { $foo->bar( foo => "foo" ) },
+ qr/\QThe 'foo' parameter ("foo")/,
+ '... the foo param in &bar must be a Foo instance'
+);
+like(
+ exception { $foo->bar( foo => [] ) }, qr/\QThe 'foo' parameter/,
+ '... the foo param in &bar must be a Foo instance'
+);
+like( exception { $foo->bar( baz => [] ) }, qr/\QMandatory parameter 'foo'/ );
is_deeply(
$foo->bar( foo => $foo ),
'... the foo param and baz param in &bar got a correct args'
);
-throws_ok { $foo->bar( foo => $foo, baz => undef ) }
-qr/\QThe 'baz' parameter (undef)/,
- '... baz requires a ArrayRef | HashRef';
-throws_ok { $foo->bar( foo => $foo, baz => 10 ) }
-qr/\QThe 'baz' parameter ("10")/,
- '... baz requires a ArrayRef | HashRef';
-throws_ok { $foo->bar( foo => $foo, baz => 'Foo' ) }
-qr/\QThe 'baz' parameter ("Foo")/,
- '... baz requires a ArrayRef | HashRef';
-throws_ok { $foo->bar( foo => $foo, baz => \( my $var ) ) }
-qr/\QThe 'baz' parameter/,
- '... baz requires a ArrayRef | HashRef';
+like(
+ exception { $foo->bar( foo => $foo, baz => undef ) },
+ qr/\QThe 'baz' parameter (undef)/,
+ '... baz requires a ArrayRef | HashRef'
+);
+like(
+ exception { $foo->bar( foo => $foo, baz => 10 ) },
+ qr/\QThe 'baz' parameter ("10")/,
+ '... baz requires a ArrayRef | HashRef'
+);
+like(
+ exception { $foo->bar( foo => $foo, baz => 'Foo' ) },
+ qr/\QThe 'baz' parameter ("Foo")/,
+ '... baz requires a ArrayRef | HashRef'
+);
+like(
+ exception { $foo->bar( foo => $foo, baz => \( my $var ) ) },
+ qr/\QThe 'baz' parameter/, '... baz requires a ArrayRef | HashRef'
+);
done_testing();
use warnings;
use Test::More;
-use Test::Exception;
+use Test::Fatal;
{
package Foo;
my $foo = Foo->new;
isa_ok( $foo, 'Foo' );
-lives_ok {
- $foo->bar( [ baz => 1 ], { baz => { isa => 'Int' } } );
-}
-'... successfully applied the parameter validation';
-
-lives_ok {
- $foo->bar( [ baz => [ 1, 2, 3 ] ], { baz => { isa => 'ArrayRef' } } );
-}
-'... successfully applied the parameter validation (look mah no cache)';
-
-lives_ok {
- $foo->bar( [ baz => { one => 1 } ], { baz => { isa => 'HashRef' } } );
-}
-'... successfully applied the parameter validation (look mah no cache) (just checkin)';
+is(
+ exception {
+ $foo->bar( [ baz => 1 ], { baz => { isa => 'Int' } } );
+ },
+ undef,
+ '... successfully applied the parameter validation'
+);
+
+is(
+ exception {
+ $foo->bar( [ baz => [ 1, 2, 3 ] ], { baz => { isa => 'ArrayRef' } } );
+ },
+ undef,
+ '... successfully applied the parameter validation (look mah no cache)'
+);
+
+is(
+ exception {
+ $foo->bar( [ baz => { one => 1 } ], { baz => { isa => 'HashRef' } } );
+ },
+ undef,
+ '... successfully applied the parameter validation (look mah no cache) (just checkin)'
+);
done_testing();
use warnings;
use Test::More;
-use Test::Exception;
+use Test::Fatal;
use Scalar::Util;
{
my $foo = Foo->new;
isa_ok( $foo, 'Foo' );
-lives_ok {
- $foo->bar( [ baz => 1 ], { baz => { isa => 'Int' } } );
-}
-'... successfully applied the parameter validation';
+is(
+ exception {
+ $foo->bar( [ baz => 1 ], { baz => { isa => 'Int' } } );
+ },
+ undef,
+ '... successfully applied the parameter validation'
+);
-throws_ok {
- $foo->bar( [ baz => [ 1, 2, 3 ] ], { baz => { isa => 'ArrayRef' } } );
-} qr/\QThe 'baz' parameter/,
-'... successfully re-used the parameter validation for this instance';
+like(
+ exception {
+ $foo->bar( [ baz => [ 1, 2, 3 ] ], { baz => { isa => 'ArrayRef' } } );
+ },
+ qr/\QThe 'baz' parameter/,
+ '... successfully re-used the parameter validation for this instance'
+);
my $foo2 = Foo->new;
isa_ok( $foo2, 'Foo' );
-lives_ok {
- $foo2->bar( [ baz => [ 1, 2, 3 ] ], { baz => { isa => 'ArrayRef' } } );
-}
-'... successfully applied the parameter validation';
+is(
+ exception {
+ $foo2->bar(
+ [ baz => [ 1, 2, 3 ] ],
+ { baz => { isa => 'ArrayRef' } }
+ );
+ },
+ undef,
+ '... successfully applied the parameter validation'
+);
-throws_ok {
- $foo2->bar( [ baz => 1 ], { baz => { isa => 'Int' } } );
-} qr/\QThe 'baz' parameter/,
-'... successfully re-used the parameter validation for this instance';
+like(
+ exception {
+ $foo2->bar( [ baz => 1 ], { baz => { isa => 'Int' } } );
+ },
+ qr/\QThe 'baz' parameter/,
+ '... successfully re-used the parameter validation for this instance'
+);
-lives_ok {
- $foo->bar( [ baz => 1 ], { baz => { isa => 'Int' } } );
-}
-'... successfully applied the parameter validation (just checking)';
+is(
+ exception {
+ $foo->bar( [ baz => 1 ], { baz => { isa => 'Int' } } );
+ },
+ undef,
+ '... successfully applied the parameter validation (just checking)'
+);
done_testing();
use warnings;
use Test::More;
-use Test::Exception;
+use Test::Fatal;
# Note that setting coerce => 1 for the Num type tests that we don't try to do
# coercions for a type which doesn't have any coercions.
# added to test 'optional' on validated_hash
sub baropt {
- my $self = shift;
+ my $self = shift;
my %params = validated_hash(
\@_,
size1 => { isa => 'Size', coerce => 1, optional => 1 },
[ $params{size1}, $params{size2}, $params{number} ];
}
-
sub baz {
my $self = shift;
my ( $size1, $size2, $number ) = validated_list(
[ $size1, $size2, $number ];
}
-
sub quux {
my $self = shift;
my ( $size1, $size2, $number ) = validated_list(
'got the return value right with coercions for size1'
);
-throws_ok { $foo->bar( size1 => 30, size2 => [ 1, 2, 3 ], number => 30 ) }
-qr/\QThe 'size2' parameter/,
- '... the size2 param cannot be coerced';
+like(
+ exception { $foo->bar( size1 => 30, size2 => [ 1, 2, 3 ], number => 30 ) }
+ , qr/\QThe 'size2' parameter/, '... the size2 param cannot be coerced' );
-throws_ok { $foo->bar( size1 => 30, size2 => 10, number => 'something' ) }
-qr/\QThe 'number' parameter/,
- '... the number param cannot be coerced because there is no coercion defined for Num';
+like(
+ exception { $foo->bar( size1 => 30, size2 => 10, number => 'something' ) }
+ , qr/\QThe 'number' parameter/,
+ '... the number param cannot be coerced because there is no coercion defined for Num'
+);
is_deeply(
$foo->baz( size1 => 10, size2 => 20, number => 30 ),
'got the return value right with coercions for size1'
);
-throws_ok { $foo->baz( size1 => 30, size2 => [ 1, 2, 3 ], number => 30 ) }
-qr/\QThe 'size2' parameter/,
- '... the size2 param cannot be coerced';
+like(
+ exception { $foo->baz( size1 => 30, size2 => [ 1, 2, 3 ], number => 30 ) }
+ , qr/\QThe 'size2' parameter/, '... the size2 param cannot be coerced' );
-throws_ok { $foo->baz( size1 => 30, size2 => 10, number => 'something' ) }
-qr/\QThe 'number' parameter/,
- '... the number param cannot be coerced';
+like(
+ exception { $foo->baz( size1 => 30, size2 => 10, number => 'something' ) }
+ , qr/\QThe 'number' parameter/,
+ '... the number param cannot be coerced'
+);
is_deeply(
$foo->baropt( size2 => 4 ),
'got the return value right with coercion for the first param'
);
-throws_ok { $foo->ran_out( [ 1, 2 ], [ 1, 2 ] ) }
-qr/\QParameter #2/,
- '... did not attempt to coerce the second parameter';
-
+like(
+ exception { $foo->ran_out( [ 1, 2 ], [ 1, 2 ] ) }, qr/\QParameter #2/,
+ '... did not attempt to coerce the second parameter'
+);
is_deeply(
$foo->ran_out(),
use warnings;
use Test::More;
-use Test::Exception;
eval <<'EOF';
{
$@, '',
'loading MX::Params::Validate in a non-Moose class does not blow up'
);
-ok( Foo->can('validated_hash'), 'validated_hash() sub was added to Foo package' );
+ok(
+ Foo->can('validated_hash'),
+ 'validated_hash() sub was added to Foo package'
+);
done_testing();
use warnings;
use Test::More;
-use Test::Exception;
{
package Foo;
use Moose;
use MooseX::Params::Validate qw( :deprecated );
-
}
ok( Foo->can('validate'), ':deprecated tag exports validate' );
use warnings;
use Test::More;
-use Test::Exception;
+use Test::Fatal;
{
package Roles::Blah;
my $self = shift;
return [
pos_validated_list(
- \@_,
- {
+ \@_, {
isa => subtype( 'Object' => where { $_->isa('Foo') } ),
optional => 1
},
is( $foo->baz($foo)->[0], $foo, '... first param must be a Foo instance' );
-throws_ok { $foo->baz(10) } qr/\QParameter #1 ("10")/,
- '... the first param in &baz must be a Foo instance';
-throws_ok { $foo->baz('foo') } qr/\QParameter #1 ("foo")/,
- '... the first param in &baz must be a Foo instance';
-throws_ok { $foo->baz( [] ) } qr/\QParameter #1/,
- '... the first param in &baz must be a Foo instance';
-
-is( $foo->baz( $foo, $foo )->[1], $foo,
- '... second param must do Roles::Blah' );
-
-throws_ok { $foo->baz( $foo, 10 ) } qr/\QParameter #2 ("10")/,
- '... the second param in &baz must be do Roles::Blah';
-throws_ok { $foo->baz( $foo, 'foo' ) } qr/\QParameter #2 ("foo")/,
- '... the second param in &baz must be do Roles::Blah';
-throws_ok { $foo->baz( $foo, [] ) } qr/\QParameter #2/,
- '... the second param in &baz must be do Roles::Blah';
-
-is( $foo->baz( $foo, $foo, $foo )->[2], $foo,
- '... third param must do Roles::Blah' );
-
-throws_ok { $foo->baz( $foo, $foo, 10 ) } qr/\QParameter #3 ("10")/,
- '... the third param in &baz must be do Roles::Blah';
-throws_ok { $foo->baz( $foo, $foo, "foo" ) } qr/\QParameter #3 ("foo")/,
- '... the third param in &baz must be do Roles::Blah';
-throws_ok { $foo->baz( $foo, $foo, [] ) } qr/\QParameter #3/,
- '... the third param in &baz must be do Roles::Blah';
-
-throws_ok { $foo->bar } qr/\Q0 parameters were passed/,
- '... bar has a required params';
-throws_ok { $foo->bar(10) } qr/\QParameter #1 ("10")/,
- '... the first param in &bar must be a Foo instance';
-throws_ok { $foo->bar('foo') } qr/\QParameter #1 ("foo")/,
- '... the first param in &bar must be a Foo instance';
-throws_ok { $foo->bar( [] ) } qr/\QParameter #1/,
- '... the first param in &bar must be a Foo instance';
-throws_ok { $foo->bar() } qr/\Q0 parameters were passed/,
- '... bar has a required first param';
+like(
+ exception { $foo->baz(10) }, qr/\QParameter #1 ("10")/,
+ '... the first param in &baz must be a Foo instance'
+);
+like(
+ exception { $foo->baz('foo') }, qr/\QParameter #1 ("foo")/,
+ '... the first param in &baz must be a Foo instance'
+);
+like(
+ exception { $foo->baz( [] ) }, qr/\QParameter #1/,
+ '... the first param in &baz must be a Foo instance'
+);
+
+is(
+ $foo->baz( $foo, $foo )->[1], $foo,
+ '... second param must do Roles::Blah'
+);
+
+like(
+ exception { $foo->baz( $foo, 10 ) }, qr/\QParameter #2 ("10")/,
+ '... the second param in &baz must be do Roles::Blah'
+);
+like(
+ exception { $foo->baz( $foo, 'foo' ) }, qr/\QParameter #2 ("foo")/,
+ '... the second param in &baz must be do Roles::Blah'
+);
+like(
+ exception { $foo->baz( $foo, [] ) }, qr/\QParameter #2/,
+ '... the second param in &baz must be do Roles::Blah'
+);
+
+is(
+ $foo->baz( $foo, $foo, $foo )->[2], $foo,
+ '... third param must do Roles::Blah'
+);
+
+like(
+ exception { $foo->baz( $foo, $foo, 10 ) }, qr/\QParameter #3 ("10")/,
+ '... the third param in &baz must be do Roles::Blah'
+);
+like(
+ exception { $foo->baz( $foo, $foo, "foo" ) },
+ qr/\QParameter #3 ("foo")/,
+ '... the third param in &baz must be do Roles::Blah'
+);
+like(
+ exception { $foo->baz( $foo, $foo, [] ) }, qr/\QParameter #3/,
+ '... the third param in &baz must be do Roles::Blah'
+);
+
+like(
+ exception { $foo->bar }, qr/\Q0 parameters were passed/,
+ '... bar has a required params'
+);
+like(
+ exception { $foo->bar(10) }, qr/\QParameter #1 ("10")/,
+ '... the first param in &bar must be a Foo instance'
+);
+like(
+ exception { $foo->bar('foo') }, qr/\QParameter #1 ("foo")/,
+ '... the first param in &bar must be a Foo instance'
+);
+like(
+ exception { $foo->bar( [] ) }, qr/\QParameter #1/,
+ '... the first param in &bar must be a Foo instance'
+);
+like(
+ exception { $foo->bar() }, qr/\Q0 parameters were passed/,
+ '... bar has a required first param'
+);
is_deeply(
$foo->bar($foo),
'... the first param and baz param in &bar got correct args'
);
-throws_ok { $foo->bar( $foo, undef ) } qr/\QParameter #2 (undef)/,
- '... second param requires a ArrayRef | HashRef';
-throws_ok { $foo->bar( $foo, 10 ) } qr/\QParameter #2 ("10")/,
- '... second param requires a ArrayRef | HashRef';
-throws_ok { $foo->bar( $foo, 'Foo' ) } qr/\QParameter #2 ("Foo")/,
- '... second param requires a ArrayRef | HashRef';
-throws_ok { $foo->bar( $foo, \( my $var ) ) } qr/\QParameter #2/,
- '... second param requires a ArrayRef | HashRef';
+like(
+ exception { $foo->bar( $foo, undef ) }, qr/\QParameter #2 (undef)/,
+ '... second param requires a ArrayRef | HashRef'
+);
+like(
+ exception { $foo->bar( $foo, 10 ) }, qr/\QParameter #2 ("10")/,
+ '... second param requires a ArrayRef | HashRef'
+);
+like(
+ exception { $foo->bar( $foo, 'Foo' ) }, qr/\QParameter #2 ("Foo")/,
+ '... second param requires a ArrayRef | HashRef'
+);
+like(
+ exception { $foo->bar( $foo, \( my $var ) ) }, qr/\QParameter #2/,
+ '... second param requires a ArrayRef | HashRef'
+);
is_deeply(
$foo->bar( $foo, {}, [ 1, 2, 3 ] ),
'... the first param in &bar got a Foo instance'
);
-throws_ok { $foo->bar( $foo, {}, undef ) } qr/\QParameter #3 (undef)/,
-'... third param a ArrayRef[Int]';
-throws_ok { $foo->bar( $foo, {}, 10 ) } qr/\QParameter #3 ("10")/,
-'... third param a ArrayRef[Int]';
-throws_ok { $foo->bar( $foo, {}, 'Foo' ) } qr/\QParameter #3 ("Foo")/,
-'... third param a ArrayRef[Int]';
-throws_ok { $foo->bar( $foo, {}, \( my $var ) ) } qr/\QParameter #3/,
-'... third param a ArrayRef[Int]';
-throws_ok { $foo->bar( $foo, {}, [qw/one two three/] ) } qr/\QParameter #3/,
-'... third param a ArrayRef[Int]';
+like(
+ exception { $foo->bar( $foo, {}, undef ) }, qr/\QParameter #3 (undef)/,
+ '... third param a ArrayRef[Int]'
+);
+like(
+ exception { $foo->bar( $foo, {}, 10 ) }, qr/\QParameter #3 ("10")/,
+ '... third param a ArrayRef[Int]'
+);
+like(
+ exception { $foo->bar( $foo, {}, 'Foo' ) }, qr/\QParameter #3 ("Foo")/,
+ '... third param a ArrayRef[Int]'
+);
+like(
+ exception { $foo->bar( $foo, {}, \( my $var ) ) }, qr/\QParameter #3/,
+ '... third param a ArrayRef[Int]'
+);
+like(
+ exception { $foo->bar( $foo, {}, [qw/one two three/] ) },
+ qr/\QParameter #3/, '... third param a ArrayRef[Int]'
+);
done_testing();
use warnings;
use Test::More;
-use Test::Exception;
+use Test::Fatal;
{
package Foo;
my $self = shift;
my %params = validated_hash(
\@_,
- foo => { isa => 'Str' },
+ foo => { isa => 'Str' },
);
return $params{foo};
}
my @args = ( bar => delete $p{bar} );
my %params = validated_hash(
- \@args,
- bar => { isa => 'Str' },
- );
+ \@args,
+ bar => { isa => 'Str' },
+ );
$params{bar}, $self->$orig(%p);
};
my @args = ( quux => delete $p{quux} );
my %params = validated_hash(
- \@args,
- quux => { isa => 'Str' },
- );
+ \@args,
+ quux => { isa => 'Str' },
+ );
$params{quux}, $self->$orig(%p);
};
{
my $foo = Foo->new;
- is_deeply( [ $foo->foo( foo => 1, bar => 2, quux => 3 ) ],
- [ 3, 2, 1 ],
- 'multiple around wrappers can safely be cached' );
-
- is_deeply( [ $foo->foo( foo => 1, bar => 2, quux => 3 ) ],
- [ 3, 2, 1 ],
- 'multiple around wrappers can safely be cached (2nd time)' );
+ is_deeply(
+ [ $foo->foo( foo => 1, bar => 2, quux => 3 ) ],
+ [ 3, 2, 1 ],
+ 'multiple around wrappers can safely be cached'
+ );
+
+ is_deeply(
+ [ $foo->foo( foo => 1, bar => 2, quux => 3 ) ],
+ [ 3, 2, 1 ],
+ 'multiple around wrappers can safely be cached (2nd time)'
+ );
}
done_testing();
# 1.10.100 => 0001.0010.0100
my $id
= $args{padded}
- ? join( '.',
- map { sprintf( "%04d", $_ ) } split( /\./, $self->id ) )
+ ? join(
+ '.',
+ map { sprintf( "%04d", $_ ) } split( /\./, $self->id )
+ )
: $self->id;
return $id;