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