X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F104_override_usage.t;h=9820614facdce25d1432002a561c748ef2379a83;hb=8aa34615d0ebc43eb9bff930bff754e9e1b2093d;hp=d3d08685d979d546173ec122d974da53c058531d;hpb=81b19ed83c9e345f960ccefbcd639dd0e3c2de06;p=gitmo%2FMooseX-Getopt.git diff --git a/t/104_override_usage.t b/t/104_override_usage.t index d3d0868..9820614 100644 --- a/t/104_override_usage.t +++ b/t/104_override_usage.t @@ -1,7 +1,9 @@ use strict; use warnings; -use Test::More 0.88; -use Test::Exception; + +use Test::More tests => 5; +use Test::Trap; +use Test::NoWarnings 1.04 ':early'; { package MyScript; @@ -10,47 +12,31 @@ use Test::Exception; with 'MooseX::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()) }; } + +# FIXME - it looks like we have a spacing issue in Getopt::Long? +my $usage = <new_with_options; - ok $i; - is $i->foo, 1; - is $MyScript::usage, undef; + my $i = trap { MyScript->new_with_options }; + is($i->foo, 1, 'attr is set'); + is($trap->stdout, '', 'nothing printed when option is accepted'); } + { - 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; + trap { MyScript->new_with_options }; + is($trap->stdout, $usage, 'usage is printed on --help'); } + { - 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-? --usage --help Prints this usage information. -\t--foo A foo -} - ]; - - is_deeply \@MyScript::exception, $exp; + trap { MyScript->new_with_options }; + is($trap->die, join("\n", 'Unknown option: q', $usage), 'usage is printed on unknown option'); } -done_testing; -