X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F104_override_usage.t;h=173c632c932bfb8bf420d7bf0595ab6f71b81952;hb=3421d9c27e5a12656326ac9dd6c0dd9451b793ac;hp=be005bc13d016e24287a29be61fc3791ed28e15d;hpb=175b83f5692393946086f048dd8a0c1cdc28431b;p=gitmo%2FMooseX-Getopt.git diff --git a/t/104_override_usage.t b/t/104_override_usage.t index be005bc..173c632 100644 --- a/t/104_override_usage.t +++ b/t/104_override_usage.t @@ -14,18 +14,44 @@ use Test::Exception; 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, 0; + 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 +', + qq{usage: 104_override_usage.t [long options...] +\t--help Help +\t--foo A foo +} + ]; + + is_deeply \@MyScript::exception, $exp; +} + done_testing;