Commit | Line | Data |
a01f08fb |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
bff3807b |
6 | use Test::More tests => 9; |
aabf4179 |
7 | use Test::Fatal; |
a01f08fb |
8 | |
9 | BEGIN { |
10 | use_ok('MooseX::Getopt'); |
11 | } |
12 | |
13 | { |
a01f08fb |
14 | package App; |
15 | use Moose; |
16 | |
17 | with 'MooseX::Getopt'; |
18 | |
19 | has 'data' => ( |
0f8232b6 |
20 | metaclass => 'Getopt', |
a01f08fb |
21 | is => 'ro', |
22 | isa => 'Str', |
23 | default => 'file.dat', |
24 | cmd_flag => 'f', |
25 | ); |
26 | |
27 | has 'cow' => ( |
28 | metaclass => 'Getopt', |
29 | is => 'ro', |
30 | isa => 'Str', |
31 | default => 'moo', |
32 | cmd_aliases => [qw/ moocow m c /], |
33 | ); |
34 | |
35 | has 'horse' => ( |
0f8232b6 |
36 | metaclass => 'Getopt', |
a01f08fb |
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' => ( |
0f8232b6 |
68 | metaclass => 'NoGetopt', |
a01f08fb |
69 | is => 'ro', |
70 | isa => 'Int', |
71 | default => 713 |
72 | ); |
73 | |
74 | has '_private_stuff_cmdline' => ( |
0f8232b6 |
75 | metaclass => 'Getopt', |
a01f08fb |
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 | } |
bff3807b |
97 | |
98 | { |
99 | local @ARGV = (qw/--private_stuff 317/); |
100 | |
aabf4179 |
101 | like exception { App->new_with_options }, qr/Unknown option: private_stuff/; |
bff3807b |
102 | } |