X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F104_override_usage.t;h=517d8aa4323a5780e2c7b8f10977c22cef7ea68b;hb=83446b781bbe89f41f87f2c03f07065bda919f43;hp=887844b9d9f1c60ddc8004a02a74a9120bb243ac;hpb=aabf4179f74c8607d8c9de5a1da07a5f2cb48b3b;p=gitmo%2FMooseX-Getopt.git diff --git a/t/104_override_usage.t b/t/104_override_usage.t index 887844b..517d8aa 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::Fatal; + +use Test::More tests => 6; +use Test::Trap; +use Test::NoWarnings 1.04 ':early'; { package MyScript; @@ -10,47 +12,47 @@ use Test::Fatal; 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'); - like exception { 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 - like exception { 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 + trap { MyScript->new_with_options }; + is($trap->die, join("\n", 'Unknown option: q', $usage), 'usage is printed on unknown option'); } - ]; - is_deeply \@MyScript::exception, $exp; -} +{ + Class::MOP::class_of('MyScript')->add_before_method_modifier( + print_usage_text => sub { + print "--- DOCUMENTATION ---\n"; + }, + ); -done_testing; + local @ARGV = ('--help'); + trap { MyScript->new_with_options }; + is( + $trap->stdout, + join("\n", '--- DOCUMENTATION ---', $usage), + 'additional text included before normal usage string', + ); +}