* t/*.t: Fixed test plans.
[gitmo/MooseX-Getopt.git] / t / 004_nogetop.t
index 03b09db..e13b877 100644 (file)
@@ -3,21 +3,21 @@
 use strict;
 use warnings;
 
-use Test::More tests => 8;
+use Test::More tests => 37;
+use Test::Exception;
 
 BEGIN {
     use_ok('MooseX::Getopt');
 }
 
 {
-
     package App;
     use Moose;
 
     with 'MooseX::Getopt';
 
     has 'data' => (
-        metaclass => 'MooseX::Getopt::Meta::Attribute',
+        metaclass => 'Getopt',
         is        => 'ro',
         isa       => 'Str',
         default   => 'file.dat',
@@ -33,7 +33,7 @@ BEGIN {
     );
 
     has 'horse' => (
-        metaclass   => 'MooseX::Getopt::Meta::Attribute',
+        metaclass   => 'Getopt',
         is          => 'ro',
         isa         => 'Str',
         default     => 'bray',
@@ -65,14 +65,14 @@ BEGIN {
     );
 
     has 'private_stuff' => (
-        metaclass => 'MooseX::Getopt::Meta::NoGetopt',
+        metaclass => 'NoGetopt',
         is       => 'ro',
         isa      => 'Int',
         default  => 713
     );
 
     has '_private_stuff_cmdline' => (
-        metaclass => 'MooseX::Getopt::Meta::Attribute',
+        metaclass => 'Getopt',
         is        => 'ro',
         isa       => 'Int',
         default   => 832,
@@ -81,16 +81,46 @@ BEGIN {
 
 }
 
-{
-    local @ARGV = ();
+foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser::Descriptive MooseX::Getopt::Parser::Default)) {
+    SKIP: {
+        if ($parser_name eq 'MooseX::Getopt::Parser::Descriptive') {
+            eval { require Getopt::Long::Descriptive };
+            skip "Getopt::Long::Descriptive not installed", 12 if $@;
+        }
+
+        {
+            local @ARGV = ();
+
+            my $parser = $parser_name->new;
+            ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created');
+
+            my $getopt = MooseX::Getopt::Session->new( parser => $parser );
+            isa_ok($getopt, 'MooseX::Getopt::Session');
+
+            my $app = App->new_with_options( getopt => $getopt );
+            isa_ok( $app, 'App' );
+
+            ok( !$app->verbose, '... verbosity is off as expected' );
+            is( $app->length, 24,         '... length is 24 as expected' );
+            is( $app->data,   'file.dat', '... data is file.dat as expected' );
+            is_deeply( $app->libs, [], '... libs is [] as expected' );
+            is_deeply( $app->details, {}, '... details is {} as expected' );
+            is($app->private_stuff, 713, '... private stuff is 713 as expected');
+        }
+
+        {
+            local @ARGV = (qw/--private_stuff 317/);
+
+            throws_ok {
+                my $parser = $parser_name->new;
+                ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created');
+
+                my $getopt = MooseX::Getopt::Session->new( parser => $parser );
+                isa_ok($getopt, 'MooseX::Getopt::Session');
 
-    my $app = App->new_with_options;
-    isa_ok( $app, 'App' );
+                App->new_with_options( getopt => $getopt )
+            } qr/Unknown option: private_stuff/;
+        }
 
-    ok( !$app->verbose, '... verbosity is off as expected' );
-    is( $app->length, 24,         '... length is 24 as expected' );
-    is( $app->data,   'file.dat', '... data is file.dat as expected' );
-    is_deeply( $app->libs, [], '... libs is [] as expected' );
-    is_deeply( $app->details, {}, '... details is {} as expected' );
-    is($app->private_stuff, 713, '... private stuff is 713 as expected');
+    }
 }