converted to Test::Fatal
[gitmo/MooseX-Types-Path-Class.git] / t / 04.existing.t
CommitLineData
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
21package main;
22
4b3d0bfc 23use strict;
24use warnings;
25use Test::More;
e78a9794 26use Test::Fatal;
7fdec4ec 27
28my $no_exist = '/should/not/exist';
4b3d0bfc 29
30plan skip_all => "Preconditions failed; your filesystem is strange"
7fdec4ec 31 unless -d "/etc" && -e "/etc/passwd";
32
33plan skip_all => "Preconditions failed"
34 if -e $no_exist;
4b3d0bfc 35
36use MooseX::Types::Path::Class qw(ExistingFile ExistingDir);
37
38ok is_ExistingFile(to_ExistingFile("/etc/passwd")), '/etc/passwd is an existing file';
39
40ok is_ExistingDir(to_ExistingDir("/etc/")), '/etc/ is an existing directory';
41
e78a9794 42like(
43 exception { Bar->new(dir => $no_exist); },
44 qr/Directory .* must exist/,
45 'no exist dir throws',
46);
47like(
48 exception { Bar->new(file => "$no_exist/either"); },
49 qr/File .* must exist/,
50 'no exist file throws',
51);
7fdec4ec 52
4b3d0bfc 53done_testing;
7fdec4ec 54