convert to using Test::Requires
[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 use Test::Exception;
8
9 use Test::Requires {
10     'Getopt::Long::Descriptive' => 0.01, # skip all if not installed
11 };
12
13 use_ok('MooseX::Getopt');
14
15 {
16     package Engine::Foo;
17     use Moose;
18
19     with 'MooseX::Getopt';
20
21     has 'nproc' => (
22         metaclass   => 'Getopt',
23         is          => 'ro',
24         isa         => 'Int',
25         default     => sub { 1 },
26         cmd_aliases => 'n',
27     );
28 }
29
30 @ARGV = ();
31
32 {
33     my $foo = Engine::Foo->new_with_options(nproc => 10);
34     isa_ok($foo, 'Engine::Foo');
35
36     is($foo->nproc, 10, '... got the right value (10), not the default (1)');
37 }
38
39 {
40     my $foo = Engine::Foo->new_with_options();
41     isa_ok($foo, 'Engine::Foo');
42
43     is($foo->nproc, 1, '... got the right value (1), without GLD needing to handle defaults');
44 }
45
46
47