Commit | Line | Data |
73038480 |
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 | |
25eb430d |
11 | use strict; |
12 | use warnings FATAL => 'all'; |
9fbb5be9 |
13 | use Test::More tests => 2; |
25eb430d |
14 | use Test::Warnings; |
73038480 |
15 | |
16 | { |
17 | package MyClass; |
aec09248 |
18 | use strict; use warnings FATAL => 'all'; |
73038480 |
19 | use Moose; |
20 | with 'MooseX::Getopt'; |
21 | |
22 | has $_ => ( |
23 | is => 'ro', isa => 'Str', |
24 | traits => ['Getopt'], |
25 | documentation => 'Documentation for "' . $_ . '"', |
26 | ) foreach qw(foo bar baz); |
27 | } |
28 | |
29 | my $obj = MyClass->new_with_options(); |
30 | |
ce93a16f |
31 | my $expected = <<"USAGE"; |
8d396d8a |
32 | usage: 110_sort_usage_by_attr_order.t [-?h] [long options...] |
33 | \t-h -? --usage --help Prints this usage information. |
34 | \t--foo Documentation for "foo" |
35 | \t--bar Documentation for "bar" |
36 | \t--baz Documentation for "baz" |
73038480 |
37 | USAGE |
38 | |
39 | is($obj->usage->text, $expected, 'Usage text has nicely sorted options'); |