From: Tomas Doran Date: Thu, 26 Nov 2009 03:18:05 +0000 (+0000) Subject: Basic test for hooking the usage method X-Git-Tag: 0.25~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Getopt.git;a=commitdiff_plain;h=175b83f5692393946086f048dd8a0c1cdc28431b Basic test for hooking the usage method --- diff --git a/t/104_override_usage.t b/t/104_override_usage.t new file mode 100644 index 0000000..be005bc --- /dev/null +++ b/t/104_override_usage.t @@ -0,0 +1,31 @@ +use strict; +use warnings; +use Test::More 0.88; +use Test::Exception; + +{ + package MyScript; + use Moose; + + with 'MooseX::Getopt'; + + has foo => ( isa => 'Int', is => 'ro', documentation => 'A foo' ); + has help => ( isa => 'Bool', is => 'ro', default => 0, documentation => 'Help'); + + our $usage = 0; + before _getopt_full_usage => sub { $usage++; }; +} +{ + local @ARGV = ('--foo', '1'); + my $i = MyScript->new_with_options; + ok $i; + is $i->foo, 1; + is $MyScript::usage, 0; +} +{ + local @ARGV = ('--help'); + throws_ok { MyScript->new_with_options } qr/A foo/; + is $MyScript::usage, 1; +} +done_testing; +