improved grammar in test notes; use fixed test count when not skipping tests
[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 BEGIN {
16     if (eval { require MooseX::SimpleConfig and MooseX::SimpleConfig->VERSION(0.07) }) {
17         plan tests => 3;
18     } else {
19         plan skip_all => 'This test needs MooseX::SimpleConfig 0.07';
20     }
21 }
22
23 my $fail_on_exit = 1;
24 {
25     package Class;
26     use strict; use warnings;
27
28     use Moose;
29     with
30         'MooseX::SimpleConfig',
31         'MooseX::Getopt';
32
33     # this is a hacky way of being able to check that we made it past the
34     # $opt_parser->getoptions() call in new_with_options, because it is
35     # still going to bail out later on, on seeing the --help flag
36     has configfile => (
37         is => 'ro', isa => 'Str',
38         default => sub {
39             $fail_on_exit = 0;
40             'this_value_unimportant',
41         },
42     );
43
44     no Moose;
45     1;
46 }
47
48 use Test::Warn;
49 use Test::Exception;
50
51 END {
52     ok(!$fail_on_exit, 'getoptions() lives');
53
54     # cancel the non-zero exit status from _getopt_full_usage()
55     exit 0;
56 }
57
58
59 @ARGV = ('--help');
60
61 warning_like {
62     throws_ok { Class->new_with_options }
63            #usage: 107_no_auto_help.t [-?] [long options...]
64         qr/^usage: [\d\w]+\Q.t [-?] [long options...]\E.\s+\Q-? --usage --help  Prints this usage information.\E.\s+--configfile/ms,
65         'usage information looks good';
66     }
67     qr/^Specified configfile \'this_value_unimportant\' does not exist, is empty, or is not readable$/,
68     'Our dummy config file doesn\'t exist';
69