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 | |
418e3618 |
15 | BEGIN { |
3b06ca5a |
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 | } |
418e3618 |
21 | } |
8e026f54 |
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 | |
8e026f54 |
44 | no Moose; |
45 | 1; |
46 | } |
47 | |
84a58315 |
48 | use Test::Warn; |
49 | use Test::Exception; |
8e026f54 |
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'); |
84a58315 |
60 | |
61 | warning_like { |
62 | throws_ok { Class->new_with_options } |
81b19ed8 |
63 | #usage: 107_no_auto_help.t [-?] [long options...] |
2a27f1ac |
64 | qr/^usage: [\d\w]+\Q.t [-?] [long options...]\E.\s+\Q-? --usage --help Prints this usage information.\E.\s+--configfile/ms, |
84a58315 |
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'; |
8e026f54 |
69 | |