fix broken test
[gitmo/MooseX-Types.git] / t / 17_syntax_errors.t
CommitLineData
ca9d7442 1#!/usr/bin/env perl
2use strict;
3use warnings;
4
a344ca96 5use Test::More;
ca9d7442 6
7# remove this when CheckedUtilExports croaks instead of carps
8$SIG{__WARN__} = sub { die @_ };
9
10my $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
24eval $missing_comma_test;
25like $@, qr/forget a comma/, 'missing comma error';
26
27my $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
41eval $string_as_type_test;
42like $@, qr/String found where Type expected/, 'string instead of Type error';
43
44my $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
58eval $fully_qualified_type;
59is $@, '', "fully qualified type doesn't throw error";
60
61my $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};
75eval $class_type;
76is $@, '', "declared class_types don't throw error";
77
78my $role_type = q{
79 package TypeLib5;
80
81 use MooseX::Types -declare => ['Foo'];
82 use MooseX::Types::Moose 'Str';
83
bec8c623 84 role_type 'ypnftm';
ca9d7442 85
bec8c623 86 coerce ypnftm =>
ca9d7442 87 from Str,
bec8c623 88 via { bless \$_, 'ypnftm' };
ca9d7442 89
90 1;
91};
92eval $role_type;
93is $@, '', "declared role_types don't throw error";
a344ca96 94
95done_testing();