X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F109_help_flag.t;h=eb75961fb4dc6b2be6727ab0a18fe77e33b97f07;hb=c885acae4797dc3ce50e91445ceb96c971e87671;hp=c60c272d6f04ea02b0a594d47c7acc7143d0e48f;hpb=81b19ed83c9e345f960ccefbcd639dd0e3c2de06;p=gitmo%2FMooseX-Getopt.git diff --git a/t/109_help_flag.t b/t/109_help_flag.t index c60c272..eb75961 100644 --- a/t/109_help_flag.t +++ b/t/109_help_flag.t @@ -16,9 +16,11 @@ # This inconsistency is the underlying cause of RT#52474, RT#57683, RT#47865. +# Update: since 0.41, usage info is printed to stdout, not stderr. + use strict; use warnings; -use Test::More tests => 6; -use Test::Exception; +use Test::More tests => 18; +use Test::Trap; { package MyClass; @@ -29,23 +31,31 @@ use Test::Exception; # before fix, prints this on stderr: #Unknown option: ? -#usage: test1.t +#usage: test1.t -# after fix, prints this on stderr: +# after fix, prints this on stdout (formerly stderr): #usage: test1.t [-?] [long options...] # -? --usage --help Prints this usage information. +my $obj = MyClass->new_with_options; +ok($obj->meta->has_attribute('usage'), 'class has usage attribute'); +isa_ok($obj->usage, 'Getopt::Long::Descriptive::Usage'); +my $usage_text = $obj->usage->text; + foreach my $args ( ['--help'], ['--usage'], ['--?'], ['-?'] ) { local @ARGV = @$args; - - throws_ok { MyClass->new_with_options() } - qr/^usage: (?:[\d\w]+)\Q.t [-?] [long options...]\E.^\t\Q-? --usage --help Prints this usage information.\E$/ms, - 'Help request detected; usage information properly printed'; + note "Setting \@ARGV to @$args"; + + trap { MyClass->new_with_options() }; + + is($trap->leaveby, 'exit', 'bailed with an exit code'); + is($trap->exit, 0, '...of 0'); + is( + $trap->stdout, + $usage_text, + 'Usage information printed to STDOUT', + ); + is($trap->stderr, '', 'there was no STDERR output'); } -# now call again, and ensure we got the usage info. -my $obj = MyClass->new_with_options(); -ok($obj->meta->has_attribute('usage'), 'class has usage attribute'); -isa_ok($obj->usage, 'Getopt::Long::Descriptive::Usage'); -