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