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