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