X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F001_basic.t;h=6c1c1fa4e1fd0b814267f4dab93b1fb8fba9c3a2;hb=config_from_file_cli;hp=c7eaa361adace8ced5f6715b2628cecdee24c00f;hpb=de75868f0e8c3865b3f207b7ea84920760a6c8d3;p=gitmo%2FMooseX-Getopt.git diff --git a/t/001_basic.t b/t/001_basic.t index c7eaa36..6c1c1fa 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 47; +use Test::More tests => 69; BEGIN { use_ok('MooseX::Getopt'); @@ -24,7 +24,7 @@ BEGIN { ); has 'cow' => ( - metaclass => 'MooseX::Getopt::Meta::Attribute', + metaclass => 'Getopt', is => 'ro', isa => 'Str', default => 'moo', @@ -37,7 +37,7 @@ BEGIN { isa => 'Str', default => 'bray', cmd_flag => 'horsey', - cmd_aliases => ['x'], + cmd_aliases => 'x', ); has 'length' => ( @@ -61,10 +61,32 @@ BEGIN { is => 'ro', isa => 'HashRef', default => sub { {} }, - ); + ); + + has '_private_stuff' => ( + is => 'ro', + isa => 'Int', + default => 713 + ); + + has '_private_stuff_cmdline' => ( + metaclass => 'MooseX::Getopt::Meta::Attribute', + is => 'ro', + isa => 'Int', + default => 832, + cmd_flag => 'p', + ); } +foreach my $attr_name (qw(data cow horse _private_stuff_cmdline)) { + my $attr = App->meta->get_attribute($attr_name); + isa_ok($attr, 'Moose::Meta::Attribute'); + isa_ok($attr, 'MooseX::Getopt::Meta::Attribute'); + can_ok($attr, 'cmd_flag'); + can_ok($attr, 'cmd_aliases'); +} + { local @ARGV = (); @@ -181,3 +203,22 @@ BEGIN { isa_ok($app, 'App'); is($app->horse, 321, 'cmd_alias+cmd_flag, using alias'); } + +# Test _foo + cmd_flag +{ + local @ARGV = ('-p', '666'); + my $app = App->new_with_options; + isa_ok($app, 'App'); + is($app->_private_stuff_cmdline, 666, '_foo + cmd_flag'); +} + +# Test ARGV support +{ + my @args = ('-p', 12345, '-c', 99, '-'); + local @ARGV = @args; + my $app = App->new_with_options; + isa_ok($app, 'App'); + is_deeply($app->ARGV, \@args, 'ARGV accessor'); + is_deeply(\@ARGV, \@args, '@ARGV unmangled'); + is_deeply($app->extra_argv, ['-'], 'extra_argv accessor'); +}