work in progress, tests are failing, and parameterized role is not flexible enough...
[gitmo/MooseX-Getopt.git] / t / 007_nogetopt_trait.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 9;
7 use Test::Fatal;
8
9 BEGIN {
10     use_ok('MooseX::Getopt');
11 }
12
13 {
14     package App;
15     use Moose;
16
17     with 'MooseX::Getopt' => { getopt_conf => [] };
18
19     has 'data' => (
20         traits    => ['Getopt'],
21         is        => 'ro',
22         isa       => 'Str',
23         default   => 'file.dat',
24         cmd_flag  => 'f',
25     );
26
27     has 'cow' => (
28         traits      => ['Getopt'],
29         is          => 'ro',
30         isa         => 'Str',
31         default     => 'moo',
32         cmd_aliases => [qw/ moocow m c /],
33     );
34
35     has 'horse' => (
36         traits      => ['Getopt'],
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         traits   => ['NoGetopt'],
69         is       => 'ro',
70         isa      => 'Int',
71         default  => 713
72     );
73
74     has '_private_stuff_cmdline' => (
75         traits    => ['Getopt'],
76         is        => 'ro',
77         isa       => 'Int',
78         default   => 832,
79         cmd_flag  => 'p',
80     );
81
82 }
83
84 {
85     local @ARGV = ();
86
87     my $app = App->new_with_options;
88     isa_ok( $app, 'App' );
89
90     ok( !$app->verbose, '... verbosity is off as expected' );
91     is( $app->length, 24,         '... length is 24 as expected' );
92     is( $app->data,   'file.dat', '... data is file.dat as expected' );
93     is_deeply( $app->libs, [], '... libs is [] as expected' );
94     is_deeply( $app->details, {}, '... details is {} as expected' );
95     is($app->private_stuff, 713, '... private stuff is 713 as expected');
96 }
97
98 {
99     local @ARGV = (qw/--private_stuff 317/);
100
101     like exception { App->new_with_options }, qr/Unknown option: private_stuff/;
102 }