From: Jesse Luehrs Date: Sun, 24 Apr 2011 21:24:25 +0000 (-0500) Subject: use Devel::PartialDump to dump tc failures, if possible X-Git-Tag: 2.0100~191 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5a18346bf3bb376bf1ee3fab06043bb9c8bc6081;p=gitmo%2FMoose.git use Devel::PartialDump to dump tc failures, if possible can't dep on it, because it deps on Moose --- diff --git a/Changes b/Changes index af30c84..fe4c92a 100644 --- a/Changes +++ b/Changes @@ -10,6 +10,9 @@ for, noteworthy changes. origin)". Also, add the package that accessors are defined in to their definition context. + * Use Devel::PartialDump in type constraint error messages, if it is + installed. + [BUG FIXES] * Stop hiding warnings produced by throwing errors in DEMOLISH methods. diff --git a/dist.ini b/dist.ini index 224a884..8dab743 100644 --- a/dist.ini +++ b/dist.ini @@ -102,6 +102,11 @@ Test::LeakTrace = 0 Test::Output = 0 URI = 0 +[Prereqs / RuntimeRecommends] +; this needs to be installed *after*, since it deps on Moose +; remove this if this is an issue +Devel::PartialDump = 0 + [Conflicts] -script = bin/moose-outdated Catalyst = 5.80028 diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm index 989ed2b..f85cffb 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -12,6 +12,7 @@ use overload '0+' => sub { refaddr(shift) }, # id an object use Scalar::Util qw(blessed refaddr); use Sub::Name qw(subname); +use Try::Tiny; use base qw(Class::MOP::Object); @@ -138,7 +139,13 @@ sub get_message { return $msg->($value); } else { - $value = (defined $value ? overload::StrVal($value) : 'undef'); + # have to load it late like this, since it uses Moose itself + if (try { Class::MOP::load_class('Devel::PartialDump'); 1 }) { + $value = Devel::PartialDump->new->dump($value); + } + else { + $value = (defined $value ? overload::StrVal($value) : 'undef'); + } return "Validation failed for '" . $self->name . "' with value $value"; } } diff --git a/t/attributes/misc_attribute_tests.t b/t/attributes/misc_attribute_tests.t index ac532c6..c3d691c 100644 --- a/t/attributes/misc_attribute_tests.t +++ b/t/attributes/misc_attribute_tests.t @@ -140,7 +140,7 @@ use Test::Fatal; like( exception { $moose_obj->a_str( $moose_obj ) - }, 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' ); + }, qr/Attribute \(a_str\) does not pass the type constraint because\: Validation failed for 'Str' with value .*OverloadedStr/, '... dies without overloading the string' ); } diff --git a/t/native_traits/array_subtypes.t b/t/native_traits/array_subtypes.t index 6b38ae7..598605e 100644 --- a/t/native_traits/array_subtypes.t +++ b/t/native_traits/array_subtypes.t @@ -171,7 +171,7 @@ my $foo = Foo->new; { my $expect - = qr/\QAttribute (a4) does not pass the type constraint because: Validation failed for 'ArrayRef' with value invalid/; + = qr/\QAttribute (a4) does not pass the type constraint because: Validation failed for 'ArrayRef' with value \E.*invalid.*/; like( exception { $foo->accessor_a4(0); }, diff --git a/t/native_traits/hash_subtypes.t b/t/native_traits/hash_subtypes.t index d5f505b..98249aa 100644 --- a/t/native_traits/hash_subtypes.t +++ b/t/native_traits/hash_subtypes.t @@ -156,7 +156,7 @@ my $foo = Foo->new; { my $expect - = qr/\QAttribute (h4) does not pass the type constraint because: Validation failed for 'HashRef' with value invalid/; + = qr/\QAttribute (h4) does not pass the type constraint because: Validation failed for 'HashRef' with value \E.*invalid.*/; like( exception { $foo->accessor_h4('key'); }, diff --git a/t/roles/extending_role_attrs.t b/t/roles/extending_role_attrs.t index d9b223b..ee9e7b2 100644 --- a/t/roles/extending_role_attrs.t +++ b/t/roles/extending_role_attrs.t @@ -67,7 +67,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"); -like( exception { $bar->foo("baz") }, qr/^Attribute \(foo\) does not pass the type constraint because: Validation failed for 'Int' with value baz at / ); +like( exception { $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"); @@ -98,7 +98,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"); -like( exception { $baz->baz("zonk") }, qr/^Attribute \(baz\) does not pass the type constraint because: Validation failed for 'ClassName\|Int' with value zonk at / ); +like( exception { $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"); @@ -136,10 +136,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"); -like( exception { $quux->quux("quux") }, qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef\|Positive' with value quux at / ); +like( exception { $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"); -like( exception { $quux->quux({a => 1}) }, qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef\|Positive' with value HASH\(\w+\) at / ); +like( exception { $quux->quux({a => 1}) }, qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef\|Positive' with value .+ at / ); is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value"); diff --git a/t/type_constraints/class_subtypes.t b/t/type_constraints/class_subtypes.t index c5839c0..33b21e5 100644 --- a/t/type_constraints/class_subtypes.t +++ b/t/type_constraints/class_subtypes.t @@ -80,10 +80,10 @@ ok $isa_foo, 'Created subtype of Foo type'; ok $isa_foo->check( Foo->new ), 'Foo passes check'; ok $isa_foo->check( Bar->new ), 'Bar passes check'; ok ! $isa_foo->check( Baz->new ), 'Baz does not pass check'; -like $foo->get_message( Baz->new ), qr/^Validation failed for 'Foo' with value Baz=HASH\(0x\w+\) \(not isa Foo\)/, 'Better validation message'; +like $foo->get_message( Baz->new ), qr/^Validation failed for 'Foo' with value .*Baz.* \(not isa Foo\)/, 'Better validation message'; # Maybe in the future this *should* inherit? -like $isa_foo->get_message( Baz->new ), qr/^Validation failed for 'IsaFoo' with value Baz=HASH\(0x\w+\)$/, "Subtypes do not automatically inherit parent type's message"; +like $isa_foo->get_message( Baz->new ), qr/^Validation failed for 'IsaFoo' with value .*Baz.*/, "Subtypes do not automatically inherit parent type's message"; # Implicit types diff --git a/t/type_constraints/union_types.t b/t/type_constraints/union_types.t index 2a7fa5b..aa6e67d 100644 --- a/t/type_constraints/union_types.t +++ b/t/type_constraints/union_types.t @@ -70,11 +70,11 @@ ok(!defined($HashOrArray->validate([])), '... (ArrayRef | HashRef) can accept [] ok(!defined($HashOrArray->validate({})), '... (ArrayRef | HashRef) can accept {}'); like($HashOrArray->validate(\(my $var2)), -qr/Validation failed for \'ArrayRef\' with value SCALAR\(0x.+?\) and Validation failed for \'HashRef\' with value SCALAR\(0x.+?\) in \(ArrayRef\|HashRef\)/, +qr/Validation failed for \'ArrayRef\' with value .+ and Validation failed for \'HashRef\' with value .+ in \(ArrayRef\|HashRef\)/, '... (ArrayRef | HashRef) cannot accept scalar refs'); like($HashOrArray->validate(sub {}), -qr/Validation failed for \'ArrayRef\' with value CODE\(0x.+?\) and Validation failed for \'HashRef\' with value CODE\(0x.+?\) in \(ArrayRef\|HashRef\)/, +qr/Validation failed for \'ArrayRef\' with value .+ and Validation failed for \'HashRef\' with value .+ in \(ArrayRef\|HashRef\)/, '... (ArrayRef | HashRef) cannot accept code refs'); is($HashOrArray->validate(50),