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