Commit | Line | Data |
bff3807b |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6ac028c4 |
6 | use Test::More tests => 10; |
aabf4179 |
7 | use Test::Fatal; |
bff3807b |
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' => ( |
0f8232b6 |
21 | metaclass => 'Getopt', |
bff3807b |
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' => ( |
eb404494 |
37 | traits => ['Getopt'], |
bff3807b |
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 | ); |
bff3807b |
73 | } |
74 | |
75 | { |
76 | local @ARGV = (); |
77 | |
78 | my $app = App->new_with_options; |
79 | isa_ok( $app, 'App' ); |
80 | |
81 | ok( !$app->verbose, '... verbosity is off as expected' ); |
82 | is( $app->length, 24, '... length is 24 as expected' ); |
83 | is( $app->data, 'file.dat', '... data is file.dat as expected' ); |
84 | is_deeply( $app->libs, [], '... libs is [] as expected' ); |
85 | is_deeply( $app->details, {}, '... details is {} as expected' ); |
86 | is($app->private_stuff, 713, '... private stuff is 713 as expected'); |
87 | } |
88 | |
89 | { |
90 | local @ARGV = (qw/--private_stuff 317/); |
91 | |
aabf4179 |
92 | like exception { App->new_with_options }, qr/Unknown option: private_stuff/; |
bff3807b |
93 | } |
6ac028c4 |
94 | |
95 | { |
96 | local @ARGV = (qw/--length 100/); |
97 | |
aabf4179 |
98 | like exception { App->new_with_options }, qr/Unknown option: length/; |
6ac028c4 |
99 | } |
100 | |