also treat "-h" as a request for help
[gitmo/MooseX-Getopt.git] / t / 110_sort_usage_by_attr_order.t
1
2 # The usage information prints the 'documentation' value for all Getopt
3 # attributes, except the order is not deterministic (rather, it uses the order
4 # in which the attributes are stored in the metaclass 'attributes' hash).
5 # Let's sort them by insertion order, which should lead to nicer output:
6 # If MooseX::Getopt is applied early, the help options will be on top
7 # the help options will always be on top (assuming this role is applied
8 # early), followed by options added by parent classes and roles, and then
9 # options added by this class.
10
11 use strict; use warnings;
12 use Test::More tests => 1;
13
14 {
15     package MyClass;
16     use strict; use warnings;
17     use Moose;
18     with 'MooseX::Getopt';
19
20     has $_ => (
21         is => 'ro', isa => 'Str',
22         traits => ['Getopt'],
23         documentation => 'Documentation for "' . $_ . '"',
24     ) foreach qw(foo bar baz);
25 }
26
27 my $obj = MyClass->new_with_options();
28
29 my $expected = <<"USAGE";
30 usage: 110_sort_usage_by_attr_order.t [-?h] [long options...]
31 \t-h -? --usage --help  Prints this usage information.
32 \t--foo                Documentation for "foo"
33 \t--bar                Documentation for "bar"
34 \t--baz                Documentation for "baz"
35 USAGE
36
37 is($obj->usage->text, $expected, 'Usage text has nicely sorted options');