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