From: gfx Date: Wed, 9 Jun 2010 10:40:10 +0000 (+0900) Subject: Make type constraint messages compatible with Moose's X-Git-Tag: 0.60~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=537873b064ad328ea662e3792b128d9b016ed38a;p=gitmo%2FMouse.git Make type constraint messages compatible with Moose's index 81d5d35..2dd7afb 100644 --- a/lib/Mouse/Meta/TypeConstraint.pm +++ b/lib/Mouse/Meta/TypeConstraint.pm @@ -164,7 +164,7 @@ sub get_message { } else { $value = ( defined $value ? overload::StrVal($value) : 'undef' ); - return "Validation failed for '$self' failed with value $value"; + return "Validation failed for '$self' with value $value"; } } --- diff --git a/lib/Mouse/Meta/TypeConstraint.pm b/lib/Mouse/Meta/TypeConstraint.pm index 81d5d35..2dd7afb 100644 --- a/lib/Mouse/Meta/TypeConstraint.pm +++ b/lib/Mouse/Meta/TypeConstraint.pm @@ -164,7 +164,7 @@ sub get_message { } else { $value = ( defined $value ? overload::StrVal($value) : 'undef' ); - return "Validation failed for '$self' failed with value $value"; + return "Validation failed for '$self' with value $value"; } } diff --git a/t/001_mouse/024-isa.t b/t/001_mouse/024-isa.t index ee970db..1a0e53d 100644 --- a/t/001_mouse/024-isa.t +++ b/t/001_mouse/024-isa.t @@ -88,13 +88,13 @@ for my $type (@types) { my $via_new; throws_ok { $via_new = Class->new($type => $value); - } qr/Attribute \($type\) does not pass the type constraint because: Validation failed for '$type' failed with value \Q$display\E/; + } qr/Attribute \($type\) does not pass the type constraint because: Validation failed for '$type' with value \Q$display\E/; is($via_new, undef, "no object created"); my $via_set = Class->new; throws_ok { $via_set->$type($value); - } qr/Attribute \($type\) does not pass the type constraint because: Validation failed for '$type' failed with value \Q$display\E/; + } qr/Attribute \($type\) does not pass the type constraint because: Validation failed for '$type' with value \Q$display\E/; is($via_set->$type, undef, "value for $type not set"); } diff --git a/t/001_mouse/025-more-isa.t b/t/001_mouse/025-more-isa.t index 6e621a7..c2b69a9 100644 --- a/t/001_mouse/025-more-isa.t +++ b/t/001_mouse/025-more-isa.t @@ -38,16 +38,16 @@ lives_ok { throws_ok { Class->new(tb => 3); -} qr/Attribute \(tb\) does not pass the type constraint because: Validation failed for 'Test::Builder' failed with value 3/; +} qr/Attribute \(tb\) does not pass the type constraint because: Validation failed for 'Test::Builder' with value 3/; throws_ok { my $class = Class->new; $class->tb(3); -} qr/Attribute \(tb\) does not pass the type constraint because: Validation failed for 'Test::Builder' failed with value 3/; +} qr/Attribute \(tb\) does not pass the type constraint because: Validation failed for 'Test::Builder' with value 3/; throws_ok { Class->new(tb => Class->new); -} qr/Attribute \(tb\) does not pass the type constraint because: Validation failed for 'Test::Builder' failed with value Class=HASH\(\w+\)/; +} qr/Attribute \(tb\) does not pass the type constraint because: Validation failed for 'Test::Builder' with value Class=HASH\(\w+\)/; do { package Other; @@ -62,7 +62,7 @@ do { throws_ok { Other->new; -} qr/Attribute \(oops\) does not pass the type constraint because: Validation failed for 'Int' failed with value yikes/; +} qr/Attribute \(oops\) does not pass the type constraint because: Validation failed for 'Int' with value yikes/; lives_ok { Other->new(oops => 10); @@ -119,31 +119,31 @@ for ('Bx', 'D'..'E', 'G::H') { throws_ok { ClassNameTests->new(class => 'A'); -} qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' failed with value A/; +} qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' with value A/; throws_ok { my $obj = ClassNameTests->new; $obj->class('A'); -} qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' failed with value A/; +} qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' with value A/; throws_ok { ClassNameTests->new(class => 'C'); -} qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' failed with value C/; +} qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' with value C/; throws_ok { my $obj = ClassNameTests->new; $obj->class('C'); -} qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' failed with value C/; +} qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' with value C/; for ('F', 'G', 'I', 'Z') { throws_ok { ClassNameTests->new(class => $_); - } qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' failed with value $_/; + } qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' with value $_/; throws_ok { my $obj = ClassNameTests->new; $obj->class($_); - } qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' failed with value $_/; + } qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' with value $_/; }; @@ -175,8 +175,8 @@ lives_ok { }; throws_ok { HasSausage->new(sausage => Class->new); -} qr/^Attribute \(sausage\) does not pass the type constraint because: Validation failed for 'SausageRole' failed with value Class=/; +} qr/^Attribute \(sausage\) does not pass the type constraint because: Validation failed for 'SausageRole' with value Class=/; throws_ok { $hs->sausage(Class->new); -} qr/^Attribute \(sausage\) does not pass the type constraint because: Validation failed for 'SausageRole' failed with value Class=/; +} qr/^Attribute \(sausage\) does not pass the type constraint because: Validation failed for 'SausageRole' with value Class=/; diff --git a/t/001_mouse/041-enum.t b/t/001_mouse/041-enum.t index 8dfe9b9..1d3ccf0 100644 --- a/t/001_mouse/041-enum.t +++ b/t/001_mouse/041-enum.t @@ -31,11 +31,11 @@ for my $class ('Shirt', 'Shirt::Anon') { ok($class->new(size => 'medium')); ok($class->new(size => 'large')); - throws_ok { $class->new(size => 'extra small') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' failed with value extra small/; - throws_ok { $class->new(size => 'Small') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' failed with value Small/; - throws_ok { $class->new(size => '') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' failed with value /; - throws_ok { $class->new(size => 'small ') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' failed with value small /; - throws_ok { $class->new(size => ' small') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' failed with value small/; + throws_ok { $class->new(size => 'extra small') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' with value extra small/; + throws_ok { $class->new(size => 'Small') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' with value Small/; + throws_ok { $class->new(size => '') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' with value /; + throws_ok { $class->new(size => 'small ') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' with value small /; + throws_ok { $class->new(size => ' small') } qr/^Attribute \(size\) does not pass the type constraint because: Validation failed for '\S+' with value small/; } use Mouse::Util::TypeConstraints qw(enum); diff --git a/t/001_mouse/043-parameterized-type.t b/t/001_mouse/043-parameterized-type.t index 3e223e2..9fb344f 100644 --- a/t/001_mouse/043-parameterized-type.t +++ b/t/001_mouse/043-parameterized-type.t @@ -69,30 +69,30 @@ use Tie::Array; # check bad args throws_ok { Foo->new( foo => { a => 'b' }); - } qr/Attribute \(foo\) does not pass the type constraint because: Validation failed for 'HashRef\[Int\]' failed with value/, "Bad args for hash throws an exception"; + } qr/Attribute \(foo\) does not pass the type constraint because: Validation failed for 'HashRef\[Int\]' with value/, "Bad args for hash throws an exception"; throws_ok { Foo->new( bar => [ a => 'b' ]); - } qr/Attribute \(bar\) does not pass the type constraint because: Validation failed for 'ArrayRef\[Int\]' failed with value/, "Bad args for array throws an exception"; + } qr/Attribute \(bar\) does not pass the type constraint because: Validation failed for 'ArrayRef\[Int\]' with value/, "Bad args for array throws an exception"; throws_ok { Foo->new( complex => [ { a => 1, b => 1 }, { c => "d", e => "f" } ] ) - } qr/Attribute \(complex\) does not pass the type constraint because: Validation failed for 'ArrayRef\[HashRef\[Int\]\]' failed with value/, "Bad args for complex types throws an exception"; + } qr/Attribute \(complex\) does not pass the type constraint because: Validation failed for 'ArrayRef\[HashRef\[Int\]\]' with value/, "Bad args for complex types throws an exception"; throws_ok { Foo->new( my_class => [ 10 ] ); - } qr/Attribute \(my_class\) does not pass the type constraint because: Validation failed for 'ArrayRef\[My::Class\]' failed with value/; + } qr/Attribute \(my_class\) does not pass the type constraint because: Validation failed for 'ArrayRef\[My::Class\]' with value/; throws_ok { Foo->new( my_class => [ {foo => 'bar'} ] ); - } qr/Attribute \(my_class\) does not pass the type constraint because: Validation failed for 'ArrayRef\[My::Class\]' failed with value/; + } qr/Attribute \(my_class\) does not pass the type constraint because: Validation failed for 'ArrayRef\[My::Class\]' with value/; throws_ok { Foo->new( my_role => [ 20 ] ); - } qr/Attribute \(my_role\) does not pass the type constraint because: Validation failed for 'ArrayRef\[My::Role\]' failed with value/; + } qr/Attribute \(my_role\) does not pass the type constraint because: Validation failed for 'ArrayRef\[My::Role\]' with value/; throws_ok { Foo->new( my_role => [ {foo => 'bar'} ] ); - } qr/Attribute \(my_role\) does not pass the type constraint because: Validation failed for 'ArrayRef\[My::Role\]' failed with value/; + } qr/Attribute \(my_role\) does not pass the type constraint because: Validation failed for 'ArrayRef\[My::Role\]' with value/; } { @@ -126,7 +126,7 @@ use Tie::Array; throws_ok { Bar->new(list => [ { 1 => 2 }, 2, 3 ]); - } qr/Attribute \(list\) does not pass the type constraint because: Validation failed for 'Bar::List' failed with value/, "Bad coercion parameter throws an error"; + } qr/Attribute \(list\) does not pass the type constraint because: Validation failed for 'Bar::List' with value/, "Bad coercion parameter throws an error"; } use Mouse::Util::TypeConstraints; diff --git a/t/001_mouse/810-isa-or.t b/t/001_mouse/810-isa-or.t index aeb326a..0b59ea1 100644 --- a/t/001_mouse/810-isa-or.t +++ b/t/001_mouse/810-isa-or.t @@ -22,7 +22,7 @@ use Test::More tests => 22; eval { Foo->new( bar => +{} ); }; -like($@, qr/^Attribute \(bar\) does not pass the type constraint because: Validation failed for 'Baz\|Str\|Undef' failed with value HASH\(\w+\)/, 'type constraint and coercion failed') +like($@, qr/^Attribute \(bar\) does not pass the type constraint because: Validation failed for 'Baz\|Str\|Undef' with value HASH\(\w+\)/, 'type constraint and coercion failed') or diag "\$@='$@'"; eval { @@ -92,7 +92,7 @@ is $foo->foo, 'Name', 'foo is Name'; } eval { Funk->new( foo => 'aaa' ) }; -like $@, qr/Attribute \(foo\) does not pass the type constraint because: Validation failed for 'KLASS\|Type3\|Undef' failed with value aaa/; +like $@, qr/Attribute \(foo\) does not pass the type constraint because: Validation failed for 'KLASS\|Type3\|Undef' with value aaa/; my $k = Funk->new; ok $k, 'got an object 4'; diff --git a/t/001_mouse/814-subtype-as.t b/t/001_mouse/814-subtype-as.t index 3dc197b..44a71e2 100644 --- a/t/001_mouse/814-subtype-as.t +++ b/t/001_mouse/814-subtype-as.t @@ -45,15 +45,15 @@ use Scalar::Util qw/blessed/; } eval { Foo->new( str_obj => Obj1->new ) }; -like $@, qr/Attribute \(str_obj\) does not pass the type constraint because: Validation failed for 'Type1' failed with value Obj1=HASH/; +like $@, qr/Attribute \(str_obj\) does not pass the type constraint because: Validation failed for 'Type1' with value Obj1=HASH/; eval { Foo->new( obj_str => Obj1->new ) }; -like $@, qr/Attribute \(obj_str\) does not pass the type constraint because: Validation failed for 'Type2' failed with value Obj1=HASH/; +like $@, qr/Attribute \(obj_str\) does not pass the type constraint because: Validation failed for 'Type2' with value Obj1=HASH/; eval { Foo->new( str_obj => Obj2->new ) }; -like $@, qr/Attribute \(str_obj\) does not pass the type constraint because: Validation failed for 'Type1' failed with value Obj2=HASH/; +like $@, qr/Attribute \(str_obj\) does not pass the type constraint because: Validation failed for 'Type1' with value Obj2=HASH/; eval { Foo->new( str_obj => 'Ref' ) }; -like $@, qr/Attribute \(str_obj\) does not pass the type constraint because: Validation failed for 'Type1' failed with value Ref/; +like $@, qr/Attribute \(str_obj\) does not pass the type constraint because: Validation failed for 'Type1' with value Ref/; my $f1 = eval { Foo->new( obj_str => Obj2->new ) }; isa_ok $f1, 'Foo'; diff --git a/t/020_attributes/012_misc_attribute_tests.t b/t/020_attributes/012_misc_attribute_tests.t index ac46d5a..8dc93ed 100644 --- a/t/020_attributes/012_misc_attribute_tests.t +++ b/t/020_attributes/012_misc_attribute_tests.t @@ -142,7 +142,7 @@ use Test::Mouse; throws_ok { $moose_obj->a_str( $moose_obj ) - } qr/Attribute \(a_str\) does not pass the type constraint because\: Validation failed for 'Str' failed 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'; } @@ -157,7 +157,7 @@ use Test::Mouse; throws_ok { OverloadBreaker->new; - } qr/Attribute \(a_num\) does not pass the type constraint because\: Validation failed for 'Int' failed 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 '; lives_ok { diff --git a/t/030_roles/017_extending_role_attrs.t b/t/030_roles/017_extending_role_attrs.t index 80d14fd..79514c0 100644 --- a/t/030_roles/017_extending_role_attrs.t +++ b/t/030_roles/017_extending_role_attrs.t @@ -68,7 +68,7 @@ is($bar->foo, 42, '... got the extended attribute'); $bar->foo(100); is($bar->foo, 100, "... can change the attribute's value to an Int"); -throws_ok { $bar->foo("baz") } qr/^Attribute \(foo\) does not pass the type constraint because: Validation failed for 'Int' failed 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"); @@ -99,7 +99,7 @@ is($baz->baz, 99, '... got the extended attribute'); $baz->baz('Foo'); is($baz->baz, 'Foo', "... can change the attribute's value to a ClassName"); -throws_ok { $baz->baz("zonk") } qr/^Attribute \(baz\) does not pass the type constraint because: Validation failed for 'ClassName\|Int' failed 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"); @@ -137,10 +137,10 @@ is($quux->quux, 100, "... can change the attribute's value to an Int"); $quux->quux(["hi"]); is_deeply($quux->quux, ["hi"], "... can change the attribute's value to an ArrayRef"); -throws_ok { $quux->quux("quux") } qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef\|Positive' failed 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"); -throws_ok { $quux->quux({a => 1}) } qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef\|Positive' failed 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");