fix typo in docs: . instead of ;
[gitmo/Moose.git] / t / 040_type_constraints / 001_util_type_constraints.t
index cf4e7e5..2b26d5f 100644 (file)
@@ -3,8 +3,8 @@
 use strict;
 use warnings;
 
-use Test::More tests => 85;
-use Test::Exception;
+use Test::More;
+use Test::Fatal;
 
 use Scalar::Util ();
 
@@ -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');
@@ -118,8 +118,7 @@ is($string->validate(5),
 "This is not a string (5)",
 '... validated unsuccessfully (got error)');
 
-lives_ok { Moose::Meta::Attribute->new('bob', isa => 'Spong') }
-  'meta-attr construction ok even when type constraint utils loaded first';
+is( exception { Moose::Meta::Attribute->new('bob', isa => 'Spong') }, undef, 'meta-attr construction ok even when type constraint utils loaded first' );
 
 # Test type constraint predicate return values.
 
@@ -130,9 +129,9 @@ foreach my $predicate (qw/equals is_subtype_of is_a_type_of/) {
 # Test adding things which don't look like types to the registry throws an exception
 
 my $r = Moose::Util::TypeConstraints->get_type_constraint_registry;
-throws_ok {$r->add_type_constraint()} qr/not a valid type constraint/, '->add_type_constraint(undef) throws';
-throws_ok {$r->add_type_constraint('foo')} qr/not a valid type constraint/, '->add_type_constraint("foo") throws';
-throws_ok {$r->add_type_constraint(bless {}, 'SomeClass')} qr/not a valid type constraint/, '->add_type_constraint(SomeClass->new) throws';
+like( exception {$r->add_type_constraint()}, qr/not a valid type constraint/, '->add_type_constraint(undef) throws' );
+like( exception {$r->add_type_constraint('foo')}, qr/not a valid type constraint/, '->add_type_constraint("foo") throws' );
+like( exception {$r->add_type_constraint(bless {}, 'SomeClass')}, qr/not a valid type constraint/, '->add_type_constraint(SomeClass->new) throws' );
 
 # Test some specific things that in the past did not work,
 # specifically weird variations on anon subtypes.
@@ -186,14 +185,18 @@ throws_ok {$r->add_type_constraint(bless {}, 'SomeClass')} qr/not a valid type c
 }
 
 {
-    throws_ok { subtype 'Foo' } qr/cannot consist solely of a name/,
-        'Cannot call subtype with a single string argument';
+    like( exception { subtype 'Foo' }, qr/cannot consist solely of a name/, 'Cannot call subtype with a single string argument' );
 }
 
 # Back-compat for being called without sugar. Previously, calling with
 # sugar was indistinguishable from calling directly.
 
 {
+    no warnings 'redefine';
+    *Moose::Deprecated::deprecated = sub { return };
+}
+
+{
     my $type = type( 'Number2', sub { Scalar::Util::looks_like_number($_) } );
 
     ok( $type->check(5), '... this is a Num' );
@@ -225,3 +228,4 @@ throws_ok {$r->add_type_constraint(bless {}, 'SomeClass')} qr/not a valid type c
     ok( ! $subtype->check('Foo'), '... this is not a Natural');
 }
 
+done_testing;