Implements feature suggestion RT#58715 by storing the Usage object, fixes
[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).
8e026f54 10
11
12my $fail_on_exit = 1;
13{
14 package Class;
15 use strict; use warnings;
16
17 use Moose;
18 with
19 'MooseX::SimpleConfig',
20 'MooseX::Getopt';
21
22 # this is a hacky way of being able to check that we made it past the
23 # $opt_parser->getoptions() call in new_with_options, because it is
24 # still going to bail out later on, on seeing the --help flag
25 has configfile => (
26 is => 'ro', isa => 'Str',
27 default => sub {
28 $fail_on_exit = 0;
29 'this_value_unimportant',
30 },
31 );
32
8e026f54 33 no Moose;
34 1;
35}
36
84a58315 37use Test::More tests => 3;
38use Test::Warn;
39use Test::Exception;
8e026f54 40
41END {
42 ok(!$fail_on_exit, 'getoptions() lives');
43
44 # cancel the non-zero exit status from _getopt_full_usage()
45 exit 0;
46}
47
48
49@ARGV = ('--help');
84a58315 50
51warning_like {
52 throws_ok { Class->new_with_options }
81b19ed8 53 #usage: 107_no_auto_help.t [-?] [long options...]
54 qr/^usage: [\d\w]+\Q.t [-?] [long options...]\E.\t--configfile\s*.\t\Q-? --usage --help Prints this usage information.\E/ms,
84a58315 55 'usage information looks good';
56 }
57 qr/^Specified configfile \'this_value_unimportant\' does not exist, is empty, or is not readable$/,
58 'Our dummy config file doesn\'t exist';
8e026f54 59