Commit | Line | Data |
5f78e881 |
1 | use strict; |
2 | use warnings; |
3 | |
aabf4179 |
4 | use Test::More tests => 7; |
5 | use Test::Fatal; |
5f78e881 |
6 | |
7 | |
8 | BEGIN { |
fe193b81 |
9 | use_ok('MooseX::Getopt'); |
5f78e881 |
10 | } |
11 | |
12 | { |
fe193b81 |
13 | package App; |
14 | use Moose; |
5f78e881 |
15 | |
fe193b81 |
16 | with 'MooseX::Getopt::Dashes'; |
5f78e881 |
17 | |
fe193b81 |
18 | has 'some_thingy' => ( is => 'ro', isa => 'Str', default => 'foo' ); |
19 | has 'another_thingy' => ( is => 'ro', isa => 'Str', default => 'foo', cmd_flag => 'another_thingy', traits => [ 'Getopt' ], ); |
5f78e881 |
20 | } |
21 | |
22 | { |
fe193b81 |
23 | local @ARGV = (qw/--some-thingy bar/); |
aabf4179 |
24 | ok ! exception { is( App->new_with_options->some_thingy, 'bar') }, 'Dash in option name'; |
5f78e881 |
25 | } |
26 | |
27 | { |
fe193b81 |
28 | local @ARGV = (qw/--some_thingy bar/); |
aabf4179 |
29 | like exception { App->new_with_options }, qr/Unknown option: some_thingy/; |
ceeaabeb |
30 | } |
31 | |
32 | { |
fe193b81 |
33 | local @ARGV = (qw/--another_thingy bar/); |
aabf4179 |
34 | ok ! exception { is( App->new_with_options->another_thingy, 'bar' ) }, 'Underscore in option name'; |
ceeaabeb |
35 | } |
36 | |
37 | { |
fe193b81 |
38 | local @ARGV = (qw/--another-thingy bar/); |
aabf4179 |
39 | like exception { App->new_with_options }, qr/Unknown option: another-thingy/; |
5f78e881 |
40 | } |