* MooseX::Getopt::Parser::Descriptive: fixed regression: does not require CLI param...
[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
053fa19e 42 my %params = (baz => 100);
43 my $getopt = MooseX::Getopt::Session->new(parser => $parser, params => \%params);
0df9248e 44
053fa19e 45 my $foo;
46 lives_ok {
47 $foo = Testing::Foo->new_with_options(getopt => $getopt);
48 } '... this should work';
49 isa_ok($foo, 'Testing::Foo');
0df9248e 50
053fa19e 51 is($foo->bar, 10, '... got the right values');
52 is($foo->baz, 100, '... got the right values');
53}
0df9248e 54
053fa19e 55# Default parser
56{
57 local @ARGV = qw(--bar 10);
0df9248e 58
053fa19e 59 my $foo;
60 lives_ok {
61 $foo = Testing::Foo->new_with_options(baz => 100);
62 } '... this should work';
63 isa_ok($foo, 'Testing::Foo');
0df9248e 64
053fa19e 65 is($foo->bar, 10, '... got the right values');
66 is($foo->baz, 100, '... got the right values');
67}