Convert all tests to done_testing.
[gitmo/Moose.git] / t / 040_type_constraints / 010_misc_type_tests.t
CommitLineData
86629f93 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
a28e50e4 6use Test::More;
86629f93 7use Test::Exception;
8
9BEGIN {
d03bd989 10 use_ok('Moose::Util::TypeConstraints');
86629f93 11}
12
13# subtype 'aliasing' ...
14
15lives_ok {
16 subtype 'Numb3rs' => as 'Num';
17} '... create bare subtype fine';
18
19my $numb3rs = find_type_constraint('Numb3rs');
9c434902 20isa_ok($numb3rs, 'Moose::Meta::TypeConstraint');
21
22# subtype with unions
23
24{
25 package Test::Moose::Meta::TypeConstraint::Union;
d4d3bd09 26
27 use overload '""' => sub {'Broken|Test'}, fallback => 1;
9c434902 28 use Moose;
d4d3bd09 29
9c434902 30 extends 'Moose::Meta::TypeConstraint';
31}
32
d4d3bd09 33my $dummy_instance = Test::Moose::Meta::TypeConstraint::Union->new;
34
35ok $dummy_instance => "Created Instance";
36
37isa_ok $dummy_instance,
38 'Test::Moose::Meta::TypeConstraint::Union' => 'isa correct type';
39
40is "$dummy_instance", "Broken|Test" =>
41 'Got expected stringification result';
42
43my $subtype1 = subtype 'New1' => as $dummy_instance;
44
45ok $subtype1 => 'made a subtype from our type object';
9c434902 46
d4d3bd09 47my $subtype2 = subtype 'New2' => as $subtype1;
9c434902 48
d4d3bd09 49ok $subtype2 => 'made a subtype of our subtype';
c24269b3 50
51# assert_valid
52
53{
54 my $type = find_type_constraint('Num');
55
56 my $ok_1 = eval { $type->assert_valid(1); };
57 ok($ok_1, "we can assert_valid that 1 is of type $type");
58
59 my $ok_2 = eval { $type->assert_valid('foo'); };
60 my $error = $@;
61 ok(! $ok_2, "'foo' is not of type $type");
62 like(
63 $error,
64 qr{validation failed for .\Q$type\E.}i,
65 "correct error thrown"
66 );
67}
a28e50e4 68
69done_testing;