* MooseX::Getopt: _get_options_from_configfile renamed to get_options_from_configfile.
[gitmo/MooseX-Getopt.git] / t / 009_gld_and_explicit_options.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Exception;
8
9 BEGIN {
10     eval 'use Getopt::Long::Descriptive;';
11     plan skip_all => "Getopt::Long::Descriptive required for this test" if $@;
12     plan tests => 10;
13     use_ok('MooseX::Getopt');
14 }
15
16 {
17     package Testing::Foo;
18     use Moose;
19
20     with 'MooseX::Getopt';
21
22     has 'bar' => (
23         is       => 'ro',
24         isa      => 'Int',
25         required => 1,
26     );
27
28     has 'baz' => (
29         is       => 'ro',
30         isa      => 'Int',
31         required => 1,
32     );
33 }
34
35 # Explicite parser
36 {
37     local @ARGV = qw(--bar 10);
38
39     my $parser = MooseX::Getopt::Parser::Descriptive->new;
40     isa_ok($parser, 'MooseX::Getopt::Parser::Descriptive');
41
42     my $getopt = MooseX::Getopt::Session->new(parser => $parser, options => {baz => 100});
43
44     my $foo;
45     lives_ok {
46         $foo = Testing::Foo->new_with_options(getopt => $getopt);
47     } '... this should work';
48     isa_ok($foo, 'Testing::Foo');
49
50     is($foo->bar, 10, '... got the right values');
51     is($foo->baz, 100, '... got the right values');
52 }
53
54 # Default parser
55 {
56     local @ARGV = qw(--bar 10);
57
58     my $foo;
59     lives_ok {
60         $foo = Testing::Foo->new_with_options(baz => 100);
61     } '... this should work';
62     isa_ok($foo, 'Testing::Foo');
63
64     is($foo->bar, 10, '... got the right values');
65     is($foo->baz, 100, '... got the right values');
66 }