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