convert all uses of Test::Exception to Test::Fatal.
[gitmo/MooseX-Getopt.git] / t / 104_override_usage.t
CommitLineData
175b83f5 1use strict;
2use warnings;
3use Test::More 0.88;
aabf4179 4use Test::Fatal;
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');
aabf4179 32 like exception { MyScript->new_with_options }, qr/A foo/;
175b83f5 33 is $MyScript::usage, 1;
34}
9b7f80a2 35{
36 local $MyScript::usage; local @MyScript::warnings; local @MyScript::exception;
37 local @ARGV = ('-q'); # Does not exist
aabf4179 38 like exception { MyScript->new_with_options }, qr/A foo/;
9b7f80a2 39 is_deeply \@MyScript::warnings, [
40 'Unknown option: q
41'
42 ];
43 my $exp = [
44 'Unknown option: q
45',
81b19ed8 46 qq{usage: 104_override_usage.t [-?] [long options...]
47\t-? --usage --help Prints this usage information.
48\t--foo A foo
9b7f80a2 49}
50 ];
51
52 is_deeply \@MyScript::exception, $exp;
53}
54
175b83f5 55done_testing;
56