added files
[gitmo/MooseX-Types-Path-Class.git] / t / 02.getopt.t
CommitLineData
6d4d954d 1
2use warnings FATAL => 'all';
3use strict;
4use English qw(-no_match_vars);
5
6eval { require MooseX::Getopt; };
7if ($EVAL_ERROR) {
8 plan( skip_all => 'MooseX::Getopt required for this test' );
9}
10
11package Foo;
12use Moose;
13with 'MooseX::Getopt';
14use MooseX::Types::Path::Class;
15
16has 'dir' => (
17 is => 'ro',
18 isa => 'Path::Class::Dir',
19 required => 1,
20 coerce => 1,
21);
22
23has 'file' => (
24 is => 'ro',
25 isa => 'Path::Class::File',
26 required => 1,
27 coerce => 1,
28);
29
30package Bar;
31use Moose;
32with 'MooseX::Getopt';
33use MooseX::Types::Path::Class qw( Dir File );
34
35has 'dir' => (
36 is => 'ro',
37 isa => Dir,
38 required => 1,
39 coerce => 1,
40);
41
42has 'file' => (
43 is => 'ro',
44 isa => File,
45 required => 1,
46 coerce => 1,
47);
48
49package main;
50
51use Test::More;
52use Path::Class;
53plan tests => 20;
54
55my $dir = dir('', 'tmp');
56my $file = file('', 'tmp', 'foo');
57
58my $check = sub {
59 my $o = shift;
60 isa_ok( $o->dir, 'Path::Class::Dir' );
61 cmp_ok( $o->dir, 'eq', "$dir", "dir is $dir" );
62 isa_ok( $o->file, 'Path::Class::File' );
63 cmp_ok( $o->file, 'eq', "$file", "file is $file" );
64};
65
66for my $class (qw(Foo Bar)) {
67 my $o;
68
69 $o = $class->new( dir => "$dir", file => [ '', 'tmp', 'foo' ] );
70 isa_ok( $o, $class );
71 $check->($o);
72 @ARGV = qw(
73 --dir
74 /tmp
75 --file
76 /tmp/foo
77 );
78 $o = $class->new_with_options;
79 isa_ok( $o, $class );
80 $check->($o);
81}
82