Commit | Line | Data |
7fdec4ec |
1 | |
2 | { |
3 | |
4 | package Bar; |
5 | use Moose; |
6 | use MooseX::Types::Path::Class qw( ExistingDir ExistingFile ); |
7 | |
8 | has 'dir' => ( |
9 | is => 'ro', |
10 | isa => ExistingDir, |
11 | coerce => 1, |
12 | ); |
13 | |
14 | has 'file' => ( |
15 | is => 'ro', |
16 | isa => ExistingFile, |
17 | coerce => 1, |
18 | ); |
19 | } |
20 | |
21 | package main; |
22 | |
4b3d0bfc |
23 | use strict; |
24 | use warnings; |
25 | use Test::More; |
7fdec4ec |
26 | use Test::Exception; |
27 | |
28 | my $no_exist = '/should/not/exist'; |
4b3d0bfc |
29 | |
30 | plan skip_all => "Preconditions failed; your filesystem is strange" |
7fdec4ec |
31 | unless -d "/etc" && -e "/etc/passwd"; |
32 | |
33 | plan skip_all => "Preconditions failed" |
34 | if -e $no_exist; |
4b3d0bfc |
35 | |
36 | use MooseX::Types::Path::Class qw(ExistingFile ExistingDir); |
37 | |
38 | ok is_ExistingFile(to_ExistingFile("/etc/passwd")), '/etc/passwd is an existing file'; |
39 | |
40 | ok is_ExistingDir(to_ExistingDir("/etc/")), '/etc/ is an existing directory'; |
41 | |
7fdec4ec |
42 | throws_ok { Bar->new( dir => $no_exist ); } |
43 | qr/Directory .* must exist/, 'no exist dir throws'; |
44 | throws_ok { Bar->new( file => "$no_exist/either" ); } |
45 | qr/File .* must exist/, 'no exist file throws'; |
46 | |
4b3d0bfc |
47 | done_testing; |
7fdec4ec |
48 | |