some doc fixes
[gitmo/MooseX-Getopt.git] / t / 005_strict.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 10;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('MooseX::Getopt');
11 }
12
13 {
14
15     package App;
16     use Moose;
17
18     with 'MooseX::Getopt::Strict';
19
20     has 'data' => (
21         metaclass => 'Getopt',
22         is        => 'ro',
23         isa       => 'Str',
24         default   => 'file.dat',
25         cmd_flag  => 'f',
26     );
27
28     has 'cow' => (
29         metaclass   => 'Getopt',
30         is          => 'ro',
31         isa         => 'Str',
32         default     => 'moo',
33         cmd_aliases => [qw/ moocow m c /],
34     );
35
36     has 'horse' => (
37         metaclass   => 'Getopt',
38         is          => 'ro',
39         isa         => 'Str',
40         default     => 'bray',
41         cmd_flag    => 'horsey',
42         cmd_aliases => 'x',
43     );
44
45     has 'length' => (
46         is      => 'ro',
47         isa     => 'Int',
48         default => 24
49     );
50
51     has 'verbose' => (
52         is  => 'ro',
53         isa => 'Bool',
54     );
55
56     has 'libs' => (
57         is      => 'ro',
58         isa     => 'ArrayRef',
59         default => sub { [] },
60     );
61
62     has 'details' => (
63         is      => 'ro',
64         isa     => 'HashRef',
65         default => sub { {} },
66     );
67
68     has 'private_stuff' => (
69         is       => 'ro',
70         isa      => 'Int',
71         default  => 713
72     );
73
74     has '_private_stuff_cmdline' => (
75         is        => 'ro',
76         isa       => 'Int',
77         default   => 832,
78         cmd_flag  => 'p',
79     );
80
81 }
82
83 {
84     local @ARGV = ();
85
86     my $app = App->new_with_options;
87     isa_ok( $app, 'App' );
88
89     ok( !$app->verbose, '... verbosity is off as expected' );
90     is( $app->length, 24,         '... length is 24 as expected' );
91     is( $app->data,   'file.dat', '... data is file.dat as expected' );
92     is_deeply( $app->libs, [], '... libs is [] as expected' );
93     is_deeply( $app->details, {}, '... details is {} as expected' );
94     is($app->private_stuff, 713, '... private stuff is 713 as expected');
95 }
96
97 {
98     local @ARGV = (qw/--private_stuff 317/);
99
100     throws_ok { App->new_with_options } qr/Unknown option: private_stuff/;
101 }
102
103 {
104     local @ARGV = (qw/--length 100/);
105
106     throws_ok { App->new_with_options } qr/Unknown option: length/;
107 }
108