X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F007_nogetopt_trait.t;fp=t%2F007_nogetopt_trait.t;h=5ccef57799186df4ac985ea2c9888cee3ef93e93;hb=adbe3e57810b57a425b78c327cc08ec3ab602a97;hp=0000000000000000000000000000000000000000;hpb=41d0ab091f0df3e2c1eae2401545c07c3798f76f;p=gitmo%2FMooseX-Getopt.git diff --git a/t/007_nogetopt_trait.t b/t/007_nogetopt_trait.t new file mode 100644 index 0000000..5ccef57 --- /dev/null +++ b/t/007_nogetopt_trait.t @@ -0,0 +1,102 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 9; +use Test::Exception; + +BEGIN { + use_ok('MooseX::Getopt'); +} + +{ + package App; + use Moose; + + with 'MooseX::Getopt'; + + has 'data' => ( + traits => ['Getopt'], + is => 'ro', + isa => 'Str', + default => 'file.dat', + cmd_flag => 'f', + ); + + has 'cow' => ( + traits => ['Getopt'], + is => 'ro', + isa => 'Str', + default => 'moo', + cmd_aliases => [qw/ moocow m c /], + ); + + has 'horse' => ( + traits => ['Getopt'], + is => 'ro', + isa => 'Str', + default => 'bray', + cmd_flag => 'horsey', + cmd_aliases => 'x', + ); + + has 'length' => ( + is => 'ro', + isa => 'Int', + default => 24 + ); + + has 'verbose' => ( + is => 'ro', + isa => 'Bool', + ); + + has 'libs' => ( + is => 'ro', + isa => 'ArrayRef', + default => sub { [] }, + ); + + has 'details' => ( + is => 'ro', + isa => 'HashRef', + default => sub { {} }, + ); + + has 'private_stuff' => ( + traits => ['NoGetopt'], + is => 'ro', + isa => 'Int', + default => 713 + ); + + has '_private_stuff_cmdline' => ( + traits => ['Getopt'], + is => 'ro', + isa => 'Int', + default => 832, + cmd_flag => 'p', + ); + +} + +{ + local @ARGV = (); + + my $app = App->new_with_options; + isa_ok( $app, 'App' ); + + ok( !$app->verbose, '... verbosity is off as expected' ); + is( $app->length, 24, '... length is 24 as expected' ); + is( $app->data, 'file.dat', '... data is file.dat as expected' ); + is_deeply( $app->libs, [], '... libs is [] as expected' ); + is_deeply( $app->details, {}, '... details is {} as expected' ); + is($app->private_stuff, 713, '... private stuff is 713 as expected'); +} + +{ + local @ARGV = (qw/--private_stuff 317/); + + throws_ok { App->new_with_options } qr/Unknown option: private_stuff/; +}