* MooseX::Getopt::Parser::Descriptive: fixed regression: does not require CLI param...
[gitmo/MooseX-Getopt.git] / t / 009_gld_and_explicit_options.t
index 266ff8c..e99a216 100644 (file)
@@ -6,44 +6,62 @@ use warnings;
 use Test::More;
 use Test::Exception;
 
-BEGIN { 
+BEGIN {
     eval 'use Getopt::Long::Descriptive;';
     plan skip_all => "Getopt::Long::Descriptive required for this test" if $@;
-    plan tests => 5;
+    plan tests => 10;
     use_ok('MooseX::Getopt');
 }
 
 {
     package Testing::Foo;
     use Moose;
-    
+
     with 'MooseX::Getopt';
-    
+
     has 'bar' => (
         is       => 'ro',
-        isa      => 'Int',   
+        isa      => 'Int',
         required => 1,
     );
-    
+
     has 'baz' => (
         is       => 'ro',
-        isa      => 'Int',   
-        required => 1,        
-    );    
+        isa      => 'Int',
+        required => 1,
+    );
 }
 
-@ARGV = qw(--bar 10);
+# Explicite parser
+{
+    local @ARGV = qw(--bar 10);
 
-my $foo;
-lives_ok {
-    $foo = Testing::Foo->new_with_options(baz => 100);
-} '... this should work';
-isa_ok($foo, 'Testing::Foo');
+    my $parser = MooseX::Getopt::Parser::Descriptive->new;
+    isa_ok($parser, 'MooseX::Getopt::Parser::Descriptive');
 
-is($foo->bar, 10, '... got the right values');
-is($foo->baz, 100, '... got the right values');
+    my %params = (baz => 100);
+    my $getopt = MooseX::Getopt::Session->new(parser => $parser, params => \%params);
 
+    my $foo;
+    lives_ok {
+        $foo = Testing::Foo->new_with_options(getopt => $getopt);
+    } '... this should work';
+    isa_ok($foo, 'Testing::Foo');
 
+    is($foo->bar, 10, '... got the right values');
+    is($foo->baz, 100, '... got the right values');
+}
 
+# Default parser
+{
+    local @ARGV = qw(--bar 10);
 
+    my $foo;
+    lives_ok {
+        $foo = Testing::Foo->new_with_options(baz => 100);
+    } '... this should work';
+    isa_ok($foo, 'Testing::Foo');
 
+    is($foo->bar, 10, '... got the right values');
+    is($foo->baz, 100, '... got the right values');
+}