use warnings tester with fewer dependencies, issues
[gitmo/MooseX-Getopt.git] / t / 007_nogetopt_trait.t
CommitLineData
adbe3e57 1use strict;
aec09248 2use warnings FATAL => 'all';
adbe3e57 3
9fbb5be9 4use Test::More tests => 10;
aabf4179 5use Test::Fatal;
25eb430d 6use Test::Warnings;
adbe3e57 7
8BEGIN {
9 use_ok('MooseX::Getopt');
10}
11
12{
13 package App;
14 use Moose;
15
16 with 'MooseX::Getopt';
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 traits => ['NoGetopt'],
68 is => 'ro',
69 isa => 'Int',
70 default => 713
71 );
72
73 has '_private_stuff_cmdline' => (
74 traits => ['Getopt'],
75 is => 'ro',
76 isa => 'Int',
77 default => 832,
78 cmd_flag => 'p',
79 );
adbe3e57 80}
81
82{
83 local @ARGV = ();
84
85 my $app = App->new_with_options;
86 isa_ok( $app, 'App' );
87
88 ok( !$app->verbose, '... verbosity is off as expected' );
89 is( $app->length, 24, '... length is 24 as expected' );
90 is( $app->data, 'file.dat', '... data is file.dat as expected' );
91 is_deeply( $app->libs, [], '... libs is [] as expected' );
92 is_deeply( $app->details, {}, '... details is {} as expected' );
93 is($app->private_stuff, 713, '... private stuff is 713 as expected');
94}
95
96{
97 local @ARGV = (qw/--private_stuff 317/);
98
aabf4179 99 like exception { App->new_with_options }, qr/Unknown option: private_stuff/;
adbe3e57 100}