Commit | Line | Data |
5dac17c3 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
8034a232 |
6 | use Test::More tests => 37; |
5dac17c3 |
7 | |
8 | BEGIN { |
9 | use_ok('MooseX::Getopt'); |
10 | } |
11 | |
12 | { |
13 | package App; |
14 | use Moose; |
15 | |
16 | with 'MooseX::Getopt'; |
17 | |
18 | has 'data' => ( |
19 | metaclass => 'MooseX::Getopt::Meta::Attribute', |
20 | is => 'ro', |
21 | isa => 'Str', |
22 | default => 'file.dat', |
23 | cmd_flag => 'f', |
24 | ); |
25 | |
26 | has 'length' => ( |
27 | is => 'ro', |
28 | isa => 'Int', |
29 | default => 24 |
30 | ); |
31 | |
32 | has 'verbose' => ( |
33 | is => 'ro', |
34 | isa => 'Bool', |
8034a232 |
35 | ); |
36 | |
37 | has 'libs' => ( |
38 | is => 'ro', |
39 | isa => 'ArrayRef', |
40 | default => sub { [] }, |
5dac17c3 |
41 | ); |
8034a232 |
42 | |
43 | has 'details' => ( |
44 | is => 'ro', |
45 | isa => 'HashRef', |
46 | default => sub { {} }, |
47 | ); |
5dac17c3 |
48 | |
49 | } |
50 | |
51 | { |
52 | local @ARGV = (); |
53 | |
54 | my $app = App->new_with_options; |
55 | isa_ok($app, 'App'); |
56 | |
57 | ok(!$app->verbose, '... verbosity is off as expected'); |
58 | is($app->length, 24, '... length is 24 as expected'); |
59 | is($app->data, 'file.dat', '... data is file.dat as expected'); |
8034a232 |
60 | is_deeply($app->libs, [], '... libs is [] as expected'); |
61 | is_deeply($app->details, {}, '... details is {} as expected'); |
5dac17c3 |
62 | } |
63 | |
64 | { |
8034a232 |
65 | local @ARGV = ('--verbose', '--length', 50); |
5dac17c3 |
66 | |
67 | my $app = App->new_with_options; |
68 | isa_ok($app, 'App'); |
69 | |
70 | ok($app->verbose, '... verbosity is turned on as expected'); |
71 | is($app->length, 50, '... length is 50 as expected'); |
8034a232 |
72 | is($app->data, 'file.dat', '... data is file.dat as expected'); |
73 | is_deeply($app->libs, [], '... libs is [] as expected'); |
74 | is_deeply($app->details, {}, '... details is {} as expected'); |
75 | } |
76 | |
77 | { |
78 | local @ARGV = ('--verbose', '-f', 'foo.txt'); |
79 | |
80 | my $app = App->new_with_options; |
81 | isa_ok($app, 'App'); |
82 | |
83 | ok($app->verbose, '... verbosity is turned on as expected'); |
84 | is($app->length, 24, '... length is 24 as expected'); |
85 | is($app->data, 'foo.txt', '... data is foo.txt as expected'); |
86 | is_deeply($app->libs, [], '... libs is [] as expected'); |
87 | is_deeply($app->details, {}, '... details is {} as expected'); |
5dac17c3 |
88 | } |
89 | |
90 | { |
8034a232 |
91 | local @ARGV = ('--verbose', '--libs', 'libs/', '--libs', 'includes/lib'); |
5dac17c3 |
92 | |
93 | my $app = App->new_with_options; |
94 | isa_ok($app, 'App'); |
95 | |
96 | ok($app->verbose, '... verbosity is turned on as expected'); |
97 | is($app->length, 24, '... length is 24 as expected'); |
8034a232 |
98 | is($app->data, 'file.dat', '... data is foo.txt as expected'); |
99 | is_deeply($app->libs, |
100 | ['libs/', 'includes/lib'], |
101 | '... libs is [libs/, includes/lib] as expected'); |
102 | is_deeply($app->details, {}, '... details is {} as expected'); |
103 | } |
104 | |
105 | { |
106 | local @ARGV = ('--details', 'os=mac', '--details', 'name=foo'); |
107 | |
108 | my $app = App->new_with_options; |
109 | isa_ok($app, 'App'); |
110 | |
111 | ok(!$app->verbose, '... verbosity is turned on as expected'); |
112 | is($app->length, 24, '... length is 24 as expected'); |
113 | is($app->data, 'file.dat', '... data is foo.txt as expected'); |
114 | is_deeply($app->libs, [], '... libs is [] as expected'); |
115 | is_deeply($app->details, |
116 | { os => 'mac', name => 'foo' }, |
117 | '... details is { os => mac, name => foo } as expected'); |
5dac17c3 |
118 | } |
119 | |
120 | { |
8034a232 |
121 | # Test negation on booleans too ... |
122 | local @ARGV = ('--noverbose'); |
5dac17c3 |
123 | |
124 | my $app = App->new_with_options; |
125 | isa_ok($app, 'App'); |
126 | |
127 | ok(!$app->verbose, '... verbosity is turned off as expected'); |
128 | is($app->length, 24, '... length is 24 as expected'); |
8034a232 |
129 | is($app->data, 'file.dat', '... file is file.dat as expected'); |
130 | is_deeply($app->libs, [], '... libs is [] as expected'); |
131 | is_deeply($app->details, {}, '... details is {} as expected'); |
5dac17c3 |
132 | } |
133 | |
134 | |
135 | |