Convert all tests to done_testing.
[gitmo/Moose.git] / t / 010_basics / 011_moose_respects_type_constraints.t
CommitLineData
bbd2fe69 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
a28e50e4 6use Test::More;
bbd2fe69 7use Test::Exception;
8
7ff56534 9use Moose::Util::TypeConstraints;
bbd2fe69 10
11=pod
12
d03bd989 13This tests demonstrates that Moose will not override
14a preexisting type constraint of the same name when
bbd2fe69 15making constraints for a Moose-class.
16
17It also tests that an attribute which uses a 'Foo' for
d03bd989 18it's isa option will get the subtype Foo, and not a
bbd2fe69 19type representing the Foo moose class.
20
21=cut
22
d03bd989 23BEGIN {
bbd2fe69 24 # create this subtype first (in BEGIN)
d03bd989 25 subtype Foo
26 => as 'Value'
bbd2fe69 27 => where { $_ eq 'Foo' };
28}
29
30{ # now seee if Moose will override it
31 package Foo;
bbd2fe69 32 use Moose;
33}
34
35my $foo_constraint = find_type_constraint('Foo');
36isa_ok($foo_constraint, 'Moose::Meta::TypeConstraint');
37
38is($foo_constraint->parent->name, 'Value', '... got the Value subtype for Foo');
39
40ok($foo_constraint->check('Foo'), '... my constraint passed correctly');
41ok(!$foo_constraint->check('Bar'), '... my constraint failed correctly');
42
43{
44 package Bar;
bbd2fe69 45 use Moose;
d03bd989 46
bbd2fe69 47 has 'foo' => (is => 'rw', isa => 'Foo');
48}
49
50my $bar = Bar->new;
51isa_ok($bar, 'Bar');
52
53lives_ok {
d03bd989 54 $bar->foo('Foo');
bbd2fe69 55} '... checked the type constraint correctly';
56
57dies_ok {
d03bd989 58 $bar->foo(Foo->new);
bbd2fe69 59} '... checked the type constraint correctly';
60
a28e50e4 61done_testing;