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