3237cd9040b634a8ff5f6dc9a098732c1b01ba36
[gitmo/MooseX-Getopt.git] / t / 100_gld_default_bug.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 5;
7
8 use Test::Requires {
9     'Getopt::Long::Descriptive' => 0.01, # skip all if not installed
10 };
11
12 use_ok('MooseX::Getopt');
13
14 {
15     package Engine::Foo;
16     use Moose;
17
18     with 'MooseX::Getopt';
19
20     has 'nproc' => (
21         metaclass   => 'Getopt',
22         is          => 'ro',
23         isa         => 'Int',
24         default     => sub { 1 },
25         cmd_aliases => 'n',
26     );
27 }
28
29 @ARGV = ();
30
31 {
32     my $foo = Engine::Foo->new_with_options(nproc => 10);
33     isa_ok($foo, 'Engine::Foo');
34
35     is($foo->nproc, 10, '... got the right value (10), not the default (1)');
36 }
37
38 {
39     my $foo = Engine::Foo->new_with_options();
40     isa_ok($foo, 'Engine::Foo');
41
42     is($foo->nproc, 1, '... got the right value (1), without GLD needing to handle defaults');
43 }
44
45
46