make all warnings fatal in tests
[gitmo/MooseX-Getopt.git] / t / 107_union_bug.t
CommitLineData
416dcb2e 1use strict;
aec09248 2use warnings FATAL => 'all';
416dcb2e 3
9fbb5be9 4use Test::More tests => 6;
5use Test::NoWarnings 1.04 ':early';
416dcb2e 6
7{
8 package example;
86fa042d 9
416dcb2e 10 use Moose;
11 use Moose::Util::TypeConstraints;
12 with qw(
13 MooseX::Getopt
14 );
86fa042d 15
16 subtype 'ResultSet'
416dcb2e 17 => as 'DBIx::Class::ResultSet';
86fa042d 18
19 subtype 'ResultList'
416dcb2e 20 => as 'ArrayRef[Int]';
21
22 MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
23 'ResultList' => '=s',
24 );
86fa042d 25
26 coerce 'ResultList'
27 => from 'Str'
416dcb2e 28 => via {
29 return [ grep { m/^\d+$/ } split /\D/,$_ ]; # <- split string into arrayref
30 };
86fa042d 31
416dcb2e 32 has 'results' => (
33 is => 'rw',
34 isa => 'ResultList | ResultSet', # <- union constraint
35 coerce => 1,
36 );
86fa042d 37
416dcb2e 38 has 'other' => (
39 is => 'rw',
40 isa => 'Str',
41 );
42}
43
44# Without MooseX::Getopt
45{
46 my $example = example->new({
47 results => '1234,5678,9012',
48 other => 'test',
49 });
50 isa_ok($example, 'example');
8fb3af53 51 is_deeply($example->results, [qw(1234 5678 9012)], 'result as expected');
416dcb2e 52}
53
54# With MooseX::Getopt
55{
56 local @ARGV = ('--results','1234,5678,9012','--other','test');
57 my $example = example->new_with_options;
58 isa_ok($example, 'example');
86fa042d 59
416dcb2e 60 is($example->other,'test');
8fb3af53 61 is_deeply($example->results, [qw(1234 5678 9012)], 'result as expected');
86fa042d 62}
8fb3af53 63