Throw exceptions from new_with_options if @ARGV parsing fails
[gitmo/MooseX-Getopt.git] / t / 003_inferred_option_type.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 5;
7
8 BEGIN {
9     use_ok('MooseX::Getopt');
10 }
11
12 {
13     package App;
14     use Moose;
15     use Moose::Util::TypeConstraints;
16     
17     use Scalar::Util 'looks_like_number';
18     
19     with 'MooseX::Getopt';
20
21     subtype 'ArrayOfInts'
22         => as 'ArrayRef'
23         => where { scalar (grep { looks_like_number($_) } @$_)  };
24     
25     has 'nums' => (
26         is      => 'ro',
27         isa     => 'ArrayOfInts',
28         default => sub { [0] }
29     ); 
30   
31 }
32
33 {
34     local @ARGV = ();
35
36     my $app = App->new_with_options;
37     isa_ok($app, 'App');
38         
39     is_deeply($app->nums, [0], '... nums is [0] as expected');       
40 }
41
42 {
43     local @ARGV = ('--nums', 3, '--nums', 5);
44
45     my $app = App->new_with_options;
46     isa_ok($app, 'App');
47         
48     is_deeply($app->nums, [3, 5], '... nums is [3, 5] as expected');       
49 }
50