make all warnings fatal in tests
[gitmo/MooseX-Getopt.git] / t / 004_nogetop.t
CommitLineData
a01f08fb 1use strict;
aec09248 2use warnings FATAL => 'all';
a01f08fb 3
9fbb5be9 4use Test::More tests => 10;
7d634446 5use Test::Fatal 0.003;
9fbb5be9 6use Test::NoWarnings 1.04 ':early';
a01f08fb 7
8BEGIN {
9 use_ok('MooseX::Getopt');
10}
11
12{
a01f08fb 13 package App;
14 use Moose;
15
16 with 'MooseX::Getopt';
17
18 has 'data' => (
195fb408 19 traits => ['Getopt'],
a01f08fb 20 is => 'ro',
21 isa => 'Str',
22 default => 'file.dat',
23 cmd_flag => 'f',
24 );
25
26 has 'cow' => (
195fb408 27 traits => ['Getopt'],
a01f08fb 28 is => 'ro',
29 isa => 'Str',
30 default => 'moo',
31 cmd_aliases => [qw/ moocow m c /],
32 );
33
34 has 'horse' => (
195fb408 35 traits => ['Getopt'],
a01f08fb 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' => (
195fb408 67 traits => ['NoGetopt'],
a01f08fb 68 is => 'ro',
69 isa => 'Int',
70 default => 713
71 );
72
73 has '_private_stuff_cmdline' => (
195fb408 74 traits => ['Getopt'],
a01f08fb 75 is => 'ro',
76 isa => 'Int',
77 default => 832,
78 cmd_flag => 'p',
79 );
a01f08fb 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}
bff3807b 95
96{
97 local @ARGV = (qw/--private_stuff 317/);
98
aabf4179 99 like exception { App->new_with_options }, qr/Unknown option: private_stuff/;
bff3807b 100}