4 use Test::More tests => 69;
7 use_ok('MooseX::Getopt');
14 with 'MooseX::Getopt';
17 metaclass => 'MooseX::Getopt::Meta::Attribute',
20 default => 'file.dat',
25 metaclass => 'Getopt',
29 cmd_aliases => [qw/ moocow m c /],
33 metaclass => 'MooseX::Getopt::Meta::Attribute',
55 default => sub { [] },
61 default => sub { {} },
64 has '_private_stuff' => (
70 has '_private_stuff_cmdline' => (
71 metaclass => 'MooseX::Getopt::Meta::Attribute',
80 foreach my $attr_name (qw(data cow horse _private_stuff_cmdline)) {
81 my $attr = App->meta->get_attribute($attr_name);
82 isa_ok($attr, 'Moose::Meta::Attribute');
83 isa_ok($attr, 'MooseX::Getopt::Meta::Attribute');
84 can_ok($attr, 'cmd_flag');
85 can_ok($attr, 'cmd_aliases');
91 my $app = App->new_with_options;
94 ok(!$app->verbose, '... verbosity is off as expected');
95 is($app->length, 24, '... length is 24 as expected');
96 is($app->data, 'file.dat', '... data is file.dat as expected');
97 is_deeply($app->libs, [], '... libs is [] as expected');
98 is_deeply($app->details, {}, '... details is {} as expected');
102 local @ARGV = ('--verbose', '--length', 50);
104 my $app = App->new_with_options;
107 ok($app->verbose, '... verbosity is turned on as expected');
108 is($app->length, 50, '... length is 50 as expected');
109 is($app->data, 'file.dat', '... data is file.dat as expected');
110 is_deeply($app->libs, [], '... libs is [] as expected');
111 is_deeply($app->details, {}, '... details is {} as expected');
115 local @ARGV = ('--verbose', '-f', 'foo.txt');
117 my $app = App->new_with_options;
120 ok($app->verbose, '... verbosity is turned on as expected');
121 is($app->length, 24, '... length is 24 as expected');
122 is($app->data, 'foo.txt', '... data is foo.txt as expected');
123 is_deeply($app->libs, [], '... libs is [] as expected');
124 is_deeply($app->details, {}, '... details is {} as expected');
128 local @ARGV = ('--verbose', '--libs', 'libs/', '--libs', 'includes/lib');
130 my $app = App->new_with_options;
133 ok($app->verbose, '... verbosity is turned on as expected');
134 is($app->length, 24, '... length is 24 as expected');
135 is($app->data, 'file.dat', '... data is foo.txt as expected');
136 is_deeply($app->libs,
137 ['libs/', 'includes/lib'],
138 '... libs is [libs/, includes/lib] as expected');
139 is_deeply($app->details, {}, '... details is {} as expected');
143 local @ARGV = ('--details', 'os=mac', '--details', 'name=foo');
145 my $app = App->new_with_options;
148 ok(!$app->verbose, '... verbosity is turned on as expected');
149 is($app->length, 24, '... length is 24 as expected');
150 is($app->data, 'file.dat', '... data is foo.txt as expected');
151 is_deeply($app->libs, [], '... libs is [] as expected');
152 is_deeply($app->details,
153 { os => 'mac', name => 'foo' },
154 '... details is { os => mac, name => foo } as expected');
158 # Test negation on booleans too ...
159 local @ARGV = ('--noverbose');
161 my $app = App->new_with_options;
164 ok(!$app->verbose, '... verbosity is turned off as expected');
165 is($app->length, 24, '... length is 24 as expected');
166 is($app->data, 'file.dat', '... file is file.dat as expected');
167 is_deeply($app->libs, [], '... libs is [] as expected');
168 is_deeply($app->details, {}, '... details is {} as expected');
171 # Test cmd_alias without cmd_flag
173 local @ARGV = ('--cow', '42');
174 my $app = App->new_with_options;
176 is($app->cow, 42, 'cmd_alias, but not using it');
179 local @ARGV = ('--moocow', '88');
180 my $app = App->new_with_options;
182 is($app->cow, 88, 'cmd_alias, using long one');
185 local @ARGV = ('-c', '99');
186 my $app = App->new_with_options;
188 is($app->cow, 99, 'cmd_alias, using short one');
191 # Test cmd_alias + cmd_flag
193 local @ARGV = ('--horsey', '123');
194 my $app = App->new_with_options;
196 is($app->horse, 123, 'cmd_alias+cmd_flag, using flag');
199 local @ARGV = ('-x', '321');
200 my $app = App->new_with_options;
202 is($app->horse, 321, 'cmd_alias+cmd_flag, using alias');
205 # Test _foo + cmd_flag
207 local @ARGV = ('-p', '666');
208 my $app = App->new_with_options;
210 is($app->_private_stuff_cmdline, 666, '_foo + cmd_flag');
215 my @args = ('-p', 12345, '-c', 99, '-');
217 my $app = App->new_with_options;
219 is_deeply($app->ARGV, \@args, 'ARGV accessor');
220 is_deeply(\@ARGV, \@args, '@ARGV unmangled');
221 is_deeply($app->extra_argv, ['-'], 'extra_argv accessor');