1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
use strict;
use warnings;
use Test::More 0.88;
use Test::Exception;
{
package MyScript;
use Mouse;
with 'MouseX::Getopt';
has foo => ( isa => 'Int', is => 'ro', documentation => 'A foo' );
our $usage = 0;
before _getopt_full_usage => sub { $usage++; };
our @warnings;
before _getopt_spec_warnings => sub { shift; push(@warnings, @_) };
our @exception;
before _getopt_spec_exception => sub { shift; push(@exception, @{ shift() }, shift()) };
}
{
local $MyScript::usage; local @MyScript::warnings; local @MyScript::exception;
local @ARGV = ('--foo', '1');
my $i = MyScript->new_with_options;
ok $i;
is $i->foo, 1;
is $MyScript::usage, undef;
}
{
local $MyScript::usage; local @MyScript::warnings; local @MyScript::exception;
local @ARGV = ('--help');
throws_ok { MyScript->new_with_options } qr/A foo/;
is $MyScript::usage, 1;
}
{
local $MyScript::usage; local @MyScript::warnings; local @MyScript::exception;
local @ARGV = ('-q'); # Does not exist
throws_ok { MyScript->new_with_options } qr/A foo/;
is_deeply \@MyScript::warnings, [
'Unknown option: q
'
];
my $exp = [
'Unknown option: q
',
$Getopt::Long::Descriptive::VERSION < 0.099 ?
qq{usage: 104_override_usage.t [-?] [long options...]
\t-? --usage --help Prints this usage information.
\t--foo A foo
}
:
$Getopt::Long::Descriptive::VERSION == 0.099 ?
qq{usage: 104_override_usage.t [-?] [long options...]
\t-? --usage --help Prints this usage information.
\t--foo INT A foo
}
:
$Getopt::Long::Descriptive::VERSION < 0.103 ?
qq{usage: 104_override_usage.t [-?] [long options...]
\t-? --usage --help Prints this usage information.
\t--foo INT A foo
}
:
# Note: Getopt::Long::Descriptive 0.106 not supported
$Getopt::Long::Descriptive::VERSION < 0.107 ?
qq{usage: 104_override_usage.t [-?] [long options...]
\t-? --[no-]usage --[no-]help Prints this usage information.
\t--foo INT A foo
}
:
$Getopt::Long::Descriptive::VERSION < 0.113 ?
qq{usage: 104_override_usage.t [-?] [long options...]
\t--[no-]help (or -?) Prints this usage information.
\t aka --usage
\t--foo INT A foo
}
:
qq{usage: 104_override_usage.t [-?] [long options...]
--[no-]help (or -?) Prints this usage information.
aka --usage
--foo INT A foo
}
];
is_deeply \@MyScript::exception, $exp;
}
done_testing;
|