fix broken test
[gitmo/MooseX-Types.git] / t / 17_syntax_errors.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4
5 use Test::More;
6
7 # remove this when CheckedUtilExports croaks instead of carps
8 $SIG{__WARN__} = sub { die @_ };
9
10 my $missing_comma_test = q{
11     package TypeLib1;
12
13     use MooseX::Types -declare => ['Foo'];
14     use MooseX::Types::Moose 'Str';
15
16     subtype Foo #,
17         as Str,
18         where { /foo/ },
19         message { 'not a Foo' };
20
21     1;
22 };
23
24 eval $missing_comma_test;
25 like $@, qr/forget a comma/, 'missing comma error';
26
27 my $string_as_type_test = q{
28     package TypeLib2;
29
30     use MooseX::Types -declare => ['Foo'];
31     use MooseX::Types::Moose 'Str';
32
33     subtype Foo => # should be ,
34         as Str,
35         where { /foo/ },
36         message { 'not a Foo' };
37
38     1;
39 };
40
41 eval $string_as_type_test;
42 like $@, qr/String found where Type expected/, 'string instead of Type error';
43
44 my $fully_qualified_type = q{
45     package TypeLib3;
46
47     use MooseX::Types -declare => ['Foo'];
48     use MooseX::Types::Moose 'Str';
49
50     subtype TypeLib3::Foo =>
51         as Str,
52         where { /foo/ },
53         message { 'not a Foo' };
54
55     1;
56 };
57
58 eval $fully_qualified_type;
59 is $@, '', "fully qualified type doesn't throw error";
60
61 my $class_type = q{
62     package TypeLib4;
63
64     use MooseX::Types -declare => ['Foo'];
65     use MooseX::Types::Moose 'Str';
66
67     class_type 'mtfnpy';
68
69     coerce mtfnpy =>
70         from Str,
71         via { bless \$_, 'mtfnpy' };
72
73     1;
74 };
75 eval $class_type;
76 is $@, '', "declared class_types don't throw error";
77
78 my $role_type = q{
79     package TypeLib5;
80
81     use MooseX::Types -declare => ['Foo'];
82     use MooseX::Types::Moose 'Str';
83
84     role_type 'ypnftm';
85
86     coerce ypnftm =>
87         from Str,
88         via { bless \$_, 'ypnftm' };
89
90     1;
91 };
92 eval $role_type;
93 is $@, '', "declared role_types don't throw error";
94
95 done_testing();