add test counts, obviating done_testing
[gitmo/MooseX-Getopt.git] / t / 104_override_usage.t
CommitLineData
175b83f5 1use strict;
2use warnings;
1f314cdc 3
4use Test::More tests => 8;
c885acae 5use Test::Trap;
175b83f5 6
7{
8 package MyScript;
9 use Moose;
10
11 with 'MooseX::Getopt';
12
13 has foo => ( isa => 'Int', is => 'ro', documentation => 'A foo' );
175b83f5 14
15 our $usage = 0;
16 before _getopt_full_usage => sub { $usage++; };
9b7f80a2 17 our @warnings;
18 before _getopt_spec_warnings => sub { shift; push(@warnings, @_) };
19 our @exception;
20 before _getopt_spec_exception => sub { shift; push(@exception, @{ shift() }, shift()) };
175b83f5 21}
22{
9b7f80a2 23 local $MyScript::usage; local @MyScript::warnings; local @MyScript::exception;
175b83f5 24 local @ARGV = ('--foo', '1');
25 my $i = MyScript->new_with_options;
26 ok $i;
27 is $i->foo, 1;
9b7f80a2 28 is $MyScript::usage, undef;
175b83f5 29}
30{
9b7f80a2 31 local $MyScript::usage; local @MyScript::warnings; local @MyScript::exception;
175b83f5 32 local @ARGV = ('--help');
c885acae 33 trap { MyScript->new_with_options };
34 like($trap->stdout, qr/A foo/);
175b83f5 35 is $MyScript::usage, 1;
36}
9b7f80a2 37{
38 local $MyScript::usage; local @MyScript::warnings; local @MyScript::exception;
39 local @ARGV = ('-q'); # Does not exist
c885acae 40 trap { MyScript->new_with_options };
41 like($trap->die, qr/A foo/);
9b7f80a2 42 is_deeply \@MyScript::warnings, [
43 'Unknown option: q
44'
45 ];
8d396d8a 46 # FIXME - it looks like we have a spacing issue in Getopt::Long?
9b7f80a2 47 my $exp = [
48 'Unknown option: q
49',
8d396d8a 50 qq{usage: 104_override_usage.t [-?h] [long options...]
51\t-h -? --usage --help Prints this usage information.
52\t--foo A foo
9b7f80a2 53}
54 ];
55
56 is_deeply \@MyScript::exception, $exp;
57}
58