From: Dave Rolsky Date: Fri, 27 Mar 2009 20:54:48 +0000 (-0500) Subject: Make the tests run once mutable, and once immutable X-Git-Tag: 0.73_01~52 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0e9e37e56c60d8524514654b0a45b240212dd09d;p=gitmo%2FMoose.git Make the tests run once mutable, and once immutable --- diff --git a/t/040_type_constraints/022_custom_type_errors.t b/t/040_type_constraints/022_custom_type_errors.t index 6970806..3b4b4b2 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::More tests => 18; use Test::Exception; { 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,34 +25,40 @@ use Test::Exception; ); } -lives_ok { my $goat = Animal->new( leg_count => 4 ) } -'... no errors thrown, value is good'; -lives_ok { my $spider = Animal->new( leg_count => 8 ) } -'... no errors thrown, value is good'; +run_tests(); +Animal->meta->make_immutable; +run_tests(); + +sub run_tests { + lives_ok { my $goat = Animal->new( leg_count => 4 ) } + '... no errors thrown, value is good'; + lives_ok { my $spider = Animal->new( leg_count => 8 ) } + '... no errors thrown, value is good'; -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"; + 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'; -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"; + 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; -lives_ok { $chimera = Animal->new( leg_count => 4 ) } -'... no errors thrown, value is good'; + my $chimera; + lives_ok { $chimera = Animal->new( leg_count => 4 ) } + '... no errors thrown, value is good'; -throws_ok { $chimera->leg_count(0) } -qr/This number \(0\) is not less than ten!/, - "gave custom supertype error message on set_value"; + throws_ok { $chimera->leg_count(0) } + qr/This number \(0\) is not less than ten!/, + 'gave custom supertype error message on set to 0'; -throws_ok { $chimera->leg_count(16) } -qr/This number \(16\) is not less than ten!/, - "gave custom subtype error message on set_value"; + 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; -lives_ok { my $gimp = Animal->new() } '... no errors thrown, value is good'; -throws_ok { $gimp->leg_count } -qr/This number \(0\) is not less than ten!/, - "gave custom supertype error message on set_value"; + my $gimp = eval { Animal->new() }; + is( $@, '', '... no errors thrown, value is good' ); + throws_ok { $gimp->leg_count } + qr/This number \(0\) is not less than ten!/, + 'gave custom supertype error message on lazy set to 0'; +}