From: Jesse Luehrs Date: Wed, 12 May 2010 19:26:18 +0000 (-0500) Subject: fix failing tests X-Git-Tag: 1.04~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8c063f8ed8d83d893e4571a3fb64c664e40bdd3e;p=gitmo%2FMoose.git fix failing tests come on people, run the test suite before committing d: --- diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index deed8f5..27dc2eb 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -199,7 +199,7 @@ sub add_attribute { my $class = ref $_[0]; Moose->throw_error( "Cannot add a $class as an attribute to a role" ); } - elsif (!blessed($_[0]) && $_[0] =~ /^\+(.*)/) { + elsif (!blessed($_[0]) && defined($_[0]) && $_[0] =~ /^\+(.*)/) { Moose->throw_error( "has '+attr' is not supported in roles" ); } diff --git a/lib/Moose/Meta/TypeConstraint/Class.pm b/lib/Moose/Meta/TypeConstraint/Class.pm index e457204..d954b03 100644 --- a/lib/Moose/Meta/TypeConstraint/Class.pm +++ b/lib/Moose/Meta/TypeConstraint/Class.pm @@ -116,7 +116,7 @@ sub get_message { } $value = (defined $value ? overload::StrVal($value) : 'undef'); - return "Validation failed for '" . $self->name . "' failed with value $value (not isa " . $self->class . ")"; + return "Validation failed for '" . $self->name . "' with value $value (not isa " . $self->class . ")"; } 1; diff --git a/t/010_basics/012_rebless.t b/t/010_basics/012_rebless.t index 77ed3eb..2ec0c20 100644 --- a/t/010_basics/012_rebless.t +++ b/t/010_basics/012_rebless.t @@ -62,10 +62,10 @@ lives_ok { $foo->type_constrained(10.5) } "Num type constraint for now.."; # try to rebless, except it will fail due to Child's stricter type constraint throws_ok { Child->meta->rebless_instance($foo) } -qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' failed with value 10\.5/, +qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/, '... this failed cause of type check'; throws_ok { Child->meta->rebless_instance($bar) } -qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' failed with value 5\.5/, +qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 5\.5/, '... this failed cause of type check';; $foo->type_constrained(10); @@ -81,7 +81,7 @@ is($foo->lazy_classname, 'Parent', "lazy attribute was already initialized"); is($bar->lazy_classname, 'Child', "lazy attribute just now initialized"); throws_ok { $foo->type_constrained(10.5) } -qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' failed with value 10\.5/, +qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/, '... this failed cause of type check'; done_testing; diff --git a/t/020_attributes/012_misc_attribute_tests.t b/t/020_attributes/012_misc_attribute_tests.t index 80c2330..7f855a3 100644 --- a/t/020_attributes/012_misc_attribute_tests.t +++ b/t/020_attributes/012_misc_attribute_tests.t @@ -140,7 +140,7 @@ use Test::Exception; 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'; } @@ -155,7 +155,7 @@ use Test::Exception; 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 c34d9c9..16bc2e7 100644 --- a/t/030_roles/017_extending_role_attrs.t +++ b/t/030_roles/017_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"); -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"); @@ -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"); -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"); @@ -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"); -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"); diff --git a/t/040_type_constraints/001_util_type_constraints.t b/t/040_type_constraints/001_util_type_constraints.t index b0e6069..e4e8119 100644 --- a/t/040_type_constraints/001_util_type_constraints.t +++ b/t/040_type_constraints/001_util_type_constraints.t @@ -104,7 +104,7 @@ ok(!$natural->has_message, '... it does not have a message'); ok(!defined($natural->validate(5)), '... validated successfully (no error)'); is($natural->validate(-5), - "Validation failed for 'Natural' failed with value -5", + "Validation failed for 'Natural' with value -5", '... validated unsuccessfully (got error)'); my $string = find_type_constraint('String'); diff --git a/t/040_type_constraints/008_union_types.t b/t/040_type_constraints/008_union_types.t index 9dc3ece..58e0b26 100644 --- a/t/040_type_constraints/008_union_types.t +++ b/t/040_type_constraints/008_union_types.t @@ -71,15 +71,15 @@ 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\' failed with value SCALAR\(0x.+?\) and Validation failed for \'HashRef\' failed with value SCALAR\(0x.+?\) in \(ArrayRef\|HashRef\)/, +qr/Validation failed for \'ArrayRef\' with value SCALAR\(0x.+?\) and Validation failed for \'HashRef\' with value SCALAR\(0x.+?\) in \(ArrayRef\|HashRef\)/, '... (ArrayRef | HashRef) cannot accept scalar refs'); like($HashOrArray->validate(sub {}), -qr/Validation failed for \'ArrayRef\' failed with value CODE\(0x.+?\) and Validation failed for \'HashRef\' failed with value CODE\(0x.+?\) in \(ArrayRef\|HashRef\)/, +qr/Validation failed for \'ArrayRef\' with value CODE\(0x.+?\) and Validation failed for \'HashRef\' with value CODE\(0x.+?\) in \(ArrayRef\|HashRef\)/, '... (ArrayRef | HashRef) cannot accept code refs'); is($HashOrArray->validate(50), -'Validation failed for \'ArrayRef\' failed with value 50 and Validation failed for \'HashRef\' failed with value 50 in (ArrayRef|HashRef)', +'Validation failed for \'ArrayRef\' with value 50 and Validation failed for \'HashRef\' with value 50 in (ArrayRef|HashRef)', '... (ArrayRef | HashRef) cannot accept Numbers'); done_testing; diff --git a/t/040_type_constraints/030_class_subtypes.t b/t/040_type_constraints/030_class_subtypes.t index 509d224..ec9a156 100644 --- a/t/040_type_constraints/030_class_subtypes.t +++ b/t/040_type_constraints/030_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' failed 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=HASH\(0x\w+\) \(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' failed 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=HASH\(0x\w+\)$/, "Subtypes do not automatically inherit parent type's message"; # Implicit types @@ -100,7 +100,7 @@ like $isa_foo->get_message( Baz->new ), qr/^Validation failed for 'IsaFoo' faile throws_ok { Quux->new(age => 3) -} qr/^Attribute \(age\) does not pass the type constraint because: Validation failed for 'Positive' failed with value 3 \(not isa Positive\)/; +} qr/^Attribute \(age\) does not pass the type constraint because: Validation failed for 'Positive' with value 3 \(not isa Positive\)/; lives_ok { Quux->new(age => (bless {}, 'Positive')); @@ -113,7 +113,7 @@ eval " throws_ok { Quux->new(age => 3) -} qr/^Attribute \(age\) does not pass the type constraint because: Validation failed for 'Positive' failed with value 3 \(not isa Positive\)/; +} qr/^Attribute \(age\) does not pass the type constraint because: Validation failed for 'Positive' with value 3 \(not isa Positive\)/; lives_ok { Quux->new(age => Positive->new)