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 | { |
13 | |
14 | package App; |
15 | use Moose; |
16 | |
17 | with 'MooseX::Getopt::Strict'; |
18 | |
19 | has 'data' => ( |
195fb408 |
20 | traits => ['Getopt'], |
bff3807b |
21 | is => 'ro', |
22 | isa => 'Str', |
23 | default => 'file.dat', |
24 | cmd_flag => 'f', |
25 | ); |
26 | |
27 | has 'cow' => ( |
195fb408 |
28 | traits => ['Getopt'], |
bff3807b |
29 | is => 'ro', |
30 | isa => 'Str', |
31 | default => 'moo', |
32 | cmd_aliases => [qw/ moocow m c /], |
33 | ); |
34 | |
35 | has 'horse' => ( |
eb404494 |
36 | traits => ['Getopt'], |
bff3807b |
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 | is => 'ro', |
69 | isa => 'Int', |
70 | default => 713 |
71 | ); |
bff3807b |
72 | } |
73 | |
74 | { |
75 | local @ARGV = (); |
76 | |
77 | my $app = App->new_with_options; |
78 | isa_ok( $app, 'App' ); |
79 | |
80 | ok( !$app->verbose, '... verbosity is off as expected' ); |
81 | is( $app->length, 24, '... length is 24 as expected' ); |
82 | is( $app->data, 'file.dat', '... data is file.dat as expected' ); |
83 | is_deeply( $app->libs, [], '... libs is [] as expected' ); |
84 | is_deeply( $app->details, {}, '... details is {} as expected' ); |
85 | is($app->private_stuff, 713, '... private stuff is 713 as expected'); |
86 | } |
87 | |
88 | { |
89 | local @ARGV = (qw/--private_stuff 317/); |
90 | |
aabf4179 |
91 | like exception { App->new_with_options }, qr/Unknown option: private_stuff/; |
bff3807b |
92 | } |
6ac028c4 |
93 | |
94 | { |
95 | local @ARGV = (qw/--length 100/); |
96 | |
aabf4179 |
97 | like exception { App->new_with_options }, qr/Unknown option: length/; |
6ac028c4 |
98 | } |
99 | |