X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F040_type_constraints%2F022_custom_type_errors.t;h=8a9023a7d447f63fbcd0dac219b1570b4ee807fb;hb=602dd0cbfcab9e15f24cc9ee66dbe22ea7cf9fa1;hp=f9ddf6f1f09cd11a6b5eb27785d700e63c07750d;hpb=01ed583a36c078de11d4278cf0f129121cff326d;p=gitmo%2FMoose.git diff --git a/t/040_type_constraints/022_custom_type_errors.t b/t/040_type_constraints/022_custom_type_errors.t index f9ddf6f..8a9023a 100644 --- a/t/040_type_constraints/022_custom_type_errors.t +++ b/t/040_type_constraints/022_custom_type_errors.t @@ -3,16 +3,13 @@ use strict; use warnings; -use Test::More tests => 10; -use Test::Exception; +use Test::More; +use Test::Fatal; { package Animal; use Moose; - - BEGIN { - ::use_ok("Moose::Util::TypeConstraints"); - } + use Moose::Util::TypeConstraints; subtype 'Natural' => as 'Int' => where { $_ > 0 } => message {"This number ($_) is not a positive integer!"}; @@ -28,37 +25,36 @@ use Test::Exception; ); } -lives_ok { my $goat = Animal->new( leg_count => 4 ) } +ok ! exception { my $goat = Animal->new( leg_count => 4 ) }, '... no errors thrown, value is good'; -lives_ok { my $spider = Animal->new( leg_count => 8 ) } +ok ! exception { my $spider = Animal->new( leg_count => 8 ) }, '... no errors thrown, value is good'; -throws_ok { my $fern = Animal->new( leg_count => 0 ) } +like exception { my $fern = Animal->new( leg_count => 0 ) }, qr/This number \(0\) is not less than ten!/, - "gave custom supertype error message on new"; + 'gave custom supertype error message on new'; -throws_ok { my $centipede = Animal->new( leg_count => 30 ) } +like exception { my $centipede = Animal->new( leg_count => 30 ) }, qr/This number \(30\) is not less than ten!/, - "gave custom subtype error message on new"; + 'gave custom subtype error message on new'; my $chimera; -lives_ok { $chimera = Animal->new( leg_count => 4 ) } +ok ! exception { $chimera = Animal->new( leg_count => 4 ) }, '... no errors thrown, value is good'; -# first we remove the lion's legs.. -throws_ok { $chimera->leg_count(0) } +like exception { $chimera->leg_count(0) }, qr/This number \(0\) is not less than ten!/, - "gave custom supertype error message on set_value"; + 'gave custom supertype error message on set to 0'; -# mix in a few octopodes -throws_ok { $chimera->leg_count(16) } +like exception { $chimera->leg_count(16) }, qr/This number \(16\) is not less than ten!/, - "gave custom subtype error message on set_value"; + 'gave custom subtype error message on set to 16'; + +my $gimp = eval { Animal->new() }; +is( $@, '', '... no errors thrown, value is good' ); -# try the lazy legs -my $gimp; -lives_ok { my $gimp = Animal->new() } '... no errors thrown, value is good'; -throws_ok { $gimp->leg_count } +like exception { $gimp->leg_count }, qr/This number \(0\) is not less than ten!/, - "gave custom supertype error message on set_value"; + 'gave custom supertype error message on lazy set to 0'; +done_testing;