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