expose print_usage_text() as public method
[gitmo/MooseX-Getopt.git] / t / 107_no_auto_help.t
CommitLineData
8e026f54 1# Related information:
2# https://rt.cpan.org/Public/Bug/Display.html?id=47865
3# https://rt.cpan.org/Public/Bug/Display.html?id=52474
4# https://rt.cpan.org/Public/Bug/Display.html?id=57683
5# http://www.nntp.perl.org/group/perl.moose/2010/06/msg1767.html
6
7# Summary: If we disable the "auto_help" option in Getopt::Long, then
8# getoptions() will not call into pod2usage() (causing program termination)
13f71373 9# when --help is passed (and MooseX::ConfigFromFile is in use).
1f314cdc 10
a2dee8c2 11use strict;
12use warnings;
8e026f54 13
9fbb5be9 14use Test::More tests => 2;
15
6a378fbd 16use Test::Requires {
17 'MooseX::SimpleConfig' => 0.07, # skip all if not installed
18};
9fbb5be9 19use Test::NoWarnings 1.04 ':early';
8e026f54 20
21my $fail_on_exit = 1;
22{
23 package Class;
24 use strict; use warnings;
25
26 use Moose;
27 with
28 'MooseX::SimpleConfig',
29 'MooseX::Getopt';
30
31 # this is a hacky way of being able to check that we made it past the
32 # $opt_parser->getoptions() call in new_with_options, because it is
33 # still going to bail out later on, on seeing the --help flag
34 has configfile => (
35 is => 'ro', isa => 'Str',
36 default => sub {
37 $fail_on_exit = 0;
38 'this_value_unimportant',
39 },
40 );
41
8e026f54 42 no Moose;
43 1;
44}
45
d08ef824 46use Test::Warn 0.21;
7d634446 47use Test::Fatal 0.003;
8e026f54 48
49END {
50 ok(!$fail_on_exit, 'getoptions() lives');
51
83446b78 52 # cancel the non-zero exit status from print_usage_text()
8e026f54 53 exit 0;
54}
55
56
57@ARGV = ('--help');
84a58315 58
59warning_like {
aabf4179 60 like exception { Class->new_with_options },
81b19ed8 61 #usage: 107_no_auto_help.t [-?] [long options...]
2a27f1ac 62 qr/^usage: [\d\w]+\Q.t [-?] [long options...]\E.\s+\Q-? --usage --help Prints this usage information.\E.\s+--configfile/ms,
84a58315 63 'usage information looks good';
64 }
65 qr/^Specified configfile \'this_value_unimportant\' does not exist, is empty, or is not readable$/,
66 'Our dummy config file doesn\'t exist';
8e026f54 67