X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F002_basic_list.t;h=75e0629ee59164b434b33d4dc78767b4d647c14d;hb=4f39bb799797bb8da9d57bca85874be3432f9391;hp=b248919b1693f1f90417e23eb66cbd441c53bf5c;hpb=d9d1529df9e8c52248cdd0bac2de23d235af3a0b;p=gitmo%2FMooseX-Params-Validate.git diff --git a/t/002_basic_list.t b/t/002_basic_list.t index b248919..75e0629 100644 --- a/t/002_basic_list.t +++ b/t/002_basic_list.t @@ -3,8 +3,8 @@ use strict; use warnings; -use Test::More tests => 27; -use Test::Exception; +use Test::More; +use Test::Fatal; { package Roles::Blah; @@ -44,7 +44,7 @@ use Test::Exception; 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 }, @@ -61,46 +61,77 @@ my $foo = Foo->new; 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 ), @@ -120,15 +151,24 @@ is_deeply( '... 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();