6 use Test::More tests => 51;
9 use_ok('MooseX::Getopt');
16 with 'MooseX::Getopt';
19 metaclass => 'MooseX::Getopt::Meta::Attribute',
22 default => 'file.dat',
27 metaclass => 'Getopt',
31 cmd_aliases => [qw/ moocow m c /],
35 metaclass => 'MooseX::Getopt::Meta::Attribute',
57 default => sub { [] },
63 default => sub { {} },
66 has '_private_stuff' => (
72 has '_private_stuff_cmdline' => (
73 metaclass => 'MooseX::Getopt::Meta::Attribute',
85 my $app = App->new_with_options;
88 ok(!$app->verbose, '... verbosity is off as expected');
89 is($app->length, 24, '... length is 24 as expected');
90 is($app->data, 'file.dat', '... data is file.dat as expected');
91 is_deeply($app->libs, [], '... libs is [] as expected');
92 is_deeply($app->details, {}, '... details is {} as expected');
96 local @ARGV = ('--verbose', '--length', 50);
98 my $app = App->new_with_options;
101 ok($app->verbose, '... verbosity is turned on as expected');
102 is($app->length, 50, '... length is 50 as expected');
103 is($app->data, 'file.dat', '... data is file.dat as expected');
104 is_deeply($app->libs, [], '... libs is [] as expected');
105 is_deeply($app->details, {}, '... details is {} as expected');
109 local @ARGV = ('--verbose', '-f', 'foo.txt');
111 my $app = App->new_with_options;
114 ok($app->verbose, '... verbosity is turned on as expected');
115 is($app->length, 24, '... length is 24 as expected');
116 is($app->data, 'foo.txt', '... data is foo.txt as expected');
117 is_deeply($app->libs, [], '... libs is [] as expected');
118 is_deeply($app->details, {}, '... details is {} as expected');
122 local @ARGV = ('--verbose', '--libs', 'libs/', '--libs', 'includes/lib');
124 my $app = App->new_with_options;
127 ok($app->verbose, '... verbosity is turned on as expected');
128 is($app->length, 24, '... length is 24 as expected');
129 is($app->data, 'file.dat', '... data is foo.txt as expected');
130 is_deeply($app->libs,
131 ['libs/', 'includes/lib'],
132 '... libs is [libs/, includes/lib] as expected');
133 is_deeply($app->details, {}, '... details is {} as expected');
137 local @ARGV = ('--details', 'os=mac', '--details', 'name=foo');
139 my $app = App->new_with_options;
142 ok(!$app->verbose, '... verbosity is turned on as expected');
143 is($app->length, 24, '... length is 24 as expected');
144 is($app->data, 'file.dat', '... data is foo.txt as expected');
145 is_deeply($app->libs, [], '... libs is [] as expected');
146 is_deeply($app->details,
147 { os => 'mac', name => 'foo' },
148 '... details is { os => mac, name => foo } as expected');
152 # Test negation on booleans too ...
153 local @ARGV = ('--noverbose');
155 my $app = App->new_with_options;
158 ok(!$app->verbose, '... verbosity is turned off as expected');
159 is($app->length, 24, '... length is 24 as expected');
160 is($app->data, 'file.dat', '... file is file.dat as expected');
161 is_deeply($app->libs, [], '... libs is [] as expected');
162 is_deeply($app->details, {}, '... details is {} as expected');
165 # Test cmd_alias without cmd_flag
167 local @ARGV = ('--cow', '42');
168 my $app = App->new_with_options;
170 is($app->cow, 42, 'cmd_alias, but not using it');
173 local @ARGV = ('--moocow', '88');
174 my $app = App->new_with_options;
176 is($app->cow, 88, 'cmd_alias, using long one');
179 local @ARGV = ('-c', '99');
180 my $app = App->new_with_options;
182 is($app->cow, 99, 'cmd_alias, using short one');
185 # Test cmd_alias + cmd_flag
187 local @ARGV = ('--horsey', '123');
188 my $app = App->new_with_options;
190 is($app->horse, 123, 'cmd_alias+cmd_flag, using flag');
193 local @ARGV = ('-x', '321');
194 my $app = App->new_with_options;
196 is($app->horse, 321, 'cmd_alias+cmd_flag, using alias');
199 # Test _foo + cmd_flag
201 local @ARGV = ('-p', '666');
202 my $app = App->new_with_options;
204 is($app->_private_stuff_cmdline, 666, '_foo + cmd_flag');
209 my @args = ('-p', 12345, '-c', 99);
211 my $app = App->new_with_options;
213 is_deeply($app->ARGV, \@args);