* MooseX::Getopt: Combine new options also from old options.
[gitmo/MooseX-Getopt.git] / t / 009_gld_and_explicit_options.t
CommitLineData
0df9248e 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
630657d5 6use Test::More;
0df9248e 7use Test::Exception;
8
053fa19e 9BEGIN {
630657d5 10 eval 'use Getopt::Long::Descriptive;';
11 plan skip_all => "Getopt::Long::Descriptive required for this test" if $@;
053fa19e 12 plan tests => 10;
630657d5 13 use_ok('MooseX::Getopt');
14}
0df9248e 15
16{
17 package Testing::Foo;
18 use Moose;
053fa19e 19
0df9248e 20 with 'MooseX::Getopt';
053fa19e 21
0df9248e 22 has 'bar' => (
23 is => 'ro',
053fa19e 24 isa => 'Int',
0df9248e 25 required => 1,
26 );
053fa19e 27
0df9248e 28 has 'baz' => (
29 is => 'ro',
053fa19e 30 isa => 'Int',
31 required => 1,
32 );
0df9248e 33}
34
053fa19e 35# Explicite parser
36{
37 local @ARGV = qw(--bar 10);
0df9248e 38
053fa19e 39 my $parser = MooseX::Getopt::Parser::Descriptive->new;
40 isa_ok($parser, 'MooseX::Getopt::Parser::Descriptive');
0df9248e 41
10ed52cb 42 my $getopt = MooseX::Getopt::Session->new(parser => $parser, options => {baz => 100});
0df9248e 43
053fa19e 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');
0df9248e 49
053fa19e 50 is($foo->bar, 10, '... got the right values');
51 is($foo->baz, 100, '... got the right values');
52}
0df9248e 53
053fa19e 54# Default parser
55{
56 local @ARGV = qw(--bar 10);
0df9248e 57
053fa19e 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');
0df9248e 63
053fa19e 64 is($foo->bar, 10, '... got the right values');
65 is($foo->baz, 100, '... got the right values');
66}