2be04b13eaf6aa922315eba9d0506844c37f9330
[gitmo/MooseX-Getopt.git] / t / 001_basic.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More no_plan => 1;
7
8 BEGIN {
9     use_ok('MooseX::Getopt');
10 }
11
12 {
13     package App;
14     use Moose;
15     
16     with 'MooseX::Getopt';
17
18     has 'data' => (
19         metaclass => 'MooseX::Getopt::Meta::Attribute',        
20         is        => 'ro',
21         isa       => 'Str',
22         default   => 'file.dat',
23         cmd_flag  => 'f',
24     );
25
26     has 'length' => (
27         is      => 'ro',
28         isa     => 'Int',
29         default => 24
30     );
31
32     has 'verbose' => (
33         is     => 'ro',
34         isa    => 'Bool',       
35     ); 
36   
37 }
38
39 {
40     local @ARGV = ();
41
42     my $app = App->new_with_options;
43     isa_ok($app, 'App');
44
45     ok(!$app->verbose, '... verbosity is off as expected');
46     is($app->length, 24, '... length is 24 as expected');    
47     is($app->data, 'file.dat', '... data is file.dat as expected');        
48 }
49
50 {
51     local @ARGV = ('-verbose', '-length', 50);
52
53     my $app = App->new_with_options;
54     isa_ok($app, 'App');
55
56     ok($app->verbose, '... verbosity is turned on as expected');
57     is($app->length, 50, '... length is 50 as expected');    
58     is($app->data, 'file.dat', '... data is file.dat as expected');     
59 }
60
61 {
62     local @ARGV = ('-verbose', '-f', 'foo.txt');
63
64     my $app = App->new_with_options;
65     isa_ok($app, 'App');
66
67     ok($app->verbose, '... verbosity is turned on as expected');
68     is($app->length, 24, '... length is 24 as expected');    
69     is($app->data, 'foo.txt', '... data is foo.txt as expected');        
70 }
71
72 {
73     local @ARGV = ('-noverbose');
74
75     my $app = App->new_with_options;
76     isa_ok($app, 'App');
77
78     ok(!$app->verbose, '... verbosity is turned off as expected');
79     is($app->length, 24, '... length is 24 as expected');    
80     is($app->data, 'file.dat', '... file is file.dat as expected');        
81 }
82
83
84