revert d08ef824 - test_requires wrong
[gitmo/MooseX-Getopt.git] / t / 107_no_auto_help.t
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)
9 # when --help is passed (and MooseX::ConfigFromFile is in use).
10 use strict;
11 use warnings;
12
13 use Test::More;
14
15 use Test::Requires {
16     'MooseX::SimpleConfig' => 0.07, # skip all if not installed
17 };
18
19 my $fail_on_exit = 1;
20 {
21     package Class;
22     use strict; use warnings;
23
24     use Moose;
25     with
26         'MooseX::SimpleConfig',
27         'MooseX::Getopt';
28
29     # this is a hacky way of being able to check that we made it past the
30     # $opt_parser->getoptions() call in new_with_options, because it is
31     # still going to bail out later on, on seeing the --help flag
32     has configfile => (
33         is => 'ro', isa => 'Str',
34         default => sub {
35             $fail_on_exit = 0;
36             'this_value_unimportant',
37         },
38     );
39
40     no Moose;
41     1;
42 }
43
44 use Test::Warn 0.21;
45 use Test::Fatal 0.003;
46
47 END {
48     ok(!$fail_on_exit, 'getoptions() lives');
49
50     done_testing;
51
52     # cancel the non-zero exit status from _getopt_full_usage()
53     exit 0;
54 }
55
56
57 @ARGV = ('--help');
58
59 warning_like {
60     like exception { Class->new_with_options },
61            #usage: 107_no_auto_help.t [-?] [long options...]
62         qr/^usage: [\d\w]+\Q.t [-?] [long options...]\E.\s+\Q-? --usage --help  Prints this usage information.\E.\s+--configfile/ms,
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';
67