Enable the argv argument to the constructor.
[gitmo/MooseX-Getopt.git] / t / 101_argv_bug.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 7;
7
8 BEGIN {
9     # TEST
10     use_ok('MooseX::Getopt');
11 }
12
13 {
14     package App;
15     use Moose;
16     
17     with 'MooseX::Getopt';
18
19     has 'data' => (
20         metaclass => 'MooseX::Getopt::Meta::Attribute',        
21         is        => 'ro',
22         isa       => 'Str',
23         default   => 'file.dat',
24         cmd_flag  => 'f',
25     );
26
27     has 'cow' => (
28         metaclass   => 'Getopt',        
29         is          => 'ro',
30         isa         => 'Str',
31         default     => 'moo',
32         cmd_aliases => [qw/ moocow m c /],
33     );
34
35     has 'horse' => (
36         metaclass   => 'MooseX::Getopt::Meta::Attribute',        
37         is          => 'ro',
38         isa         => 'Str',
39         default     => 'bray',
40         cmd_flag    => 'horsey',
41         cmd_aliases => 'x',
42     );
43
44     has 'length' => (
45         is      => 'ro',
46         isa     => 'Int',
47         default => 24
48     );
49
50     has 'verbose' => (
51         is     => 'ro',
52         isa    => 'Bool',       
53     );
54     
55     has 'libs' => (
56         is      => 'ro',
57         isa     => 'ArrayRef',
58         default => sub { [] },
59     ); 
60     
61     has 'details' => (
62         is      => 'ro',
63         isa     => 'HashRef',
64         default => sub { {} },
65     );
66
67     has '_private_stuff' => (
68         is      => 'ro',
69         isa     => 'Int',
70         default => 713
71     );
72
73     has '_private_stuff_cmdline' => (
74         metaclass => 'MooseX::Getopt::Meta::Attribute',        
75         is        => 'ro',
76         isa       => 'Int',
77         default   => 832,
78         cmd_flag  => 'p',
79     );
80   
81 }
82
83 {
84     my $app = App->new_with_options(argv => [ '--verbose', '--length', 50 ]);
85     # TEST
86     isa_ok($app, 'App');
87
88     # TEST
89     ok($app->verbose, '... verbosity is turned on as expected');
90     # TEST
91     is($app->length, 50, '... length is 50 as expected');    
92     # TEST
93     is($app->data, 'file.dat', '... data is file.dat as expected'); 
94     # TEST
95     is_deeply($app->libs, [], '... libs is [] as expected');  
96     # TEST
97     is_deeply($app->details, {}, '... details is {} as expected');                            
98 }
99