use warnings tester with fewer dependencies, issues
[gitmo/MooseX-Getopt.git] / t / 005_strict.t
1 use strict;
2 use warnings FATAL => 'all';
3
4 use Test::More tests => 11;
5 use Test::Fatal;
6 use Test::Warnings;
7
8 BEGIN {
9     use_ok('MooseX::Getopt');
10 }
11
12 {
13     package App;
14     use Moose;
15
16     with 'MooseX::Getopt::Strict';
17
18     has 'data' => (
19         traits    => ['Getopt'],
20         is        => 'ro',
21         isa       => 'Str',
22         default   => 'file.dat',
23         cmd_flag  => 'f',
24     );
25
26     has 'cow' => (
27         traits      => ['Getopt'],
28         is          => 'ro',
29         isa         => 'Str',
30         default     => 'moo',
31         cmd_aliases => [qw/ moocow m c /],
32     );
33
34     has 'horse' => (
35         traits      => ['Getopt'],
36         is          => 'ro',
37         isa         => 'Str',
38         default     => 'bray',
39         cmd_flag    => 'horsey',
40         cmd_aliases => 'x',
41     );
42
43     has 'length' => (
44         is      => 'ro',
45         isa     => 'Int',
46         default => 24
47     );
48
49     has 'verbose' => (
50         is  => 'ro',
51         isa => 'Bool',
52     );
53
54     has 'libs' => (
55         is      => 'ro',
56         isa     => 'ArrayRef',
57         default => sub { [] },
58     );
59
60     has 'details' => (
61         is      => 'ro',
62         isa     => 'HashRef',
63         default => sub { {} },
64     );
65
66     has 'private_stuff' => (
67         is       => 'ro',
68         isa      => 'Int',
69         default  => 713
70     );
71 }
72
73 {
74     local @ARGV = ();
75
76     my $app = App->new_with_options;
77     isa_ok( $app, 'App' );
78
79     ok( !$app->verbose, '... verbosity is off as expected' );
80     is( $app->length, 24,         '... length is 24 as expected' );
81     is( $app->data,   'file.dat', '... data is file.dat as expected' );
82     is_deeply( $app->libs, [], '... libs is [] as expected' );
83     is_deeply( $app->details, {}, '... details is {} as expected' );
84     is($app->private_stuff, 713, '... private stuff is 713 as expected');
85 }
86
87 {
88     local @ARGV = (qw/--private_stuff 317/);
89
90     like exception { App->new_with_options }, qr/Unknown option: private_stuff/;
91 }
92
93 {
94     local @ARGV = (qw/--length 100/);
95
96     like exception { App->new_with_options }, qr/Unknown option: length/;
97 }
98