X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F104_override_usage.t;h=29ec9d66e0c48a751c7e86f59a327b6e33ecd5d9;hb=ede2de16018159d8e1d70f53aedece5ae2d4f299;hp=9820614facdce25d1432002a561c748ef2379a83;hpb=8aa34615d0ebc43eb9bff930bff754e9e1b2093d;p=gitmo%2FMooseX-Getopt.git diff --git a/t/104_override_usage.t b/t/104_override_usage.t index 9820614..29ec9d6 100644 --- a/t/104_override_usage.t +++ b/t/104_override_usage.t @@ -1,9 +1,9 @@ use strict; -use warnings; +use warnings FATAL => 'all'; -use Test::More tests => 5; +use Test::More tests => 7; use Test::Trap; -use Test::NoWarnings 1.04 ':early'; +use Test::Warnings; { package MyScript; @@ -40,3 +40,46 @@ USAGE is($trap->die, join("\n", 'Unknown option: q', $usage), 'usage is printed on unknown option'); } +{ + Class::MOP::class_of('MyScript')->add_before_method_modifier( + print_usage_text => sub { + print "--- DOCUMENTATION ---\n"; + }, + ); + + local @ARGV = ('--help'); + trap { MyScript->new_with_options }; + is( + $trap->stdout, + join("\n", '--- DOCUMENTATION ---', $usage), + 'additional text included before normal usage string', + ); +} + +{ + package MyScript2; + use Moose; + + with 'MooseX::Getopt'; + has foo => ( isa => 'Int', is => 'ro', documentation => 'A foo' ); +} + +{ + # some classes (e.g. ether's darkpan and Catalyst::Runtime) overrode + # _getopt_full_usage, so we need to keep it in the call stack so we don't + # break them. + Class::MOP::class_of('MyScript2')->add_before_method_modifier( + _getopt_full_usage => sub { + print "--- DOCUMENTATION ---\n"; + }, + ); + + local @ARGV = ('--help'); + trap { MyScript2->new_with_options }; + is( + $trap->stdout, + join("\n", '--- DOCUMENTATION ---', $usage), + 'additional text included before normal usage string', + ); +} +