X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F109_help_flag.t;h=15b6ac1b2b1cd9f03db40be54788db2d4df42df5;hb=986fb4690bc00c860b1f728b986e39b412100854;hp=70a95abe8d9052dab3b92ca1f71672b99699928f;hpb=aabf4179f74c8607d8c9de5a1da07a5f2cb48b3b;p=gitmo%2FMooseX-Getopt.git diff --git a/t/109_help_flag.t b/t/109_help_flag.t index 70a95ab..15b6ac1 100644 --- a/t/109_help_flag.t +++ b/t/109_help_flag.t @@ -1,5 +1,3 @@ -#!/usr/bin/env perl - # The documentation claims: # If Getopt::Long::Descriptive is installed and any of the following command # line params are passed (--help, --usage, --?), the program will exit with @@ -16,13 +14,17 @@ # This inconsistency is the underlying cause of RT#52474, RT#57683, RT#47865. -use strict; use warnings; -use Test::More tests => 6; -use Test::Fatal; +# Update: since 0.41, usage info is printed to stdout, not stderr. + +use strict; +use warnings FATAL => 'all'; +use Test::More tests => 23; +use Test::Warnings; +use Test::Trap; { package MyClass; - use strict; use warnings; + use strict; use warnings FATAL => 'all'; use Moose; with 'MooseX::Getopt'; } @@ -31,21 +33,29 @@ use Test::Fatal; #Unknown option: ? #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. -foreach my $args ( ['--help'], ['--usage'], ['--?'], ['-?'] ) +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'], ['--?'], ['-?'], ['-h'] ) { local @ARGV = @$args; - - like exception { 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'); -