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