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