+
+{
+
+ package Bar;
+ use Moose;
+ use MooseX::Types::Path::Class qw( ExistingDir ExistingFile );
+
+ has 'dir' => (
+ is => 'ro',
+ isa => ExistingDir,
+ coerce => 1,
+ );
+
+ has 'file' => (
+ is => 'ro',
+ isa => ExistingFile,
+ coerce => 1,
+ );
+}
+
+package main;
+
use strict;
use warnings;
use Test::More;
+use Test::Exception;
+
+my $no_exist = '/should/not/exist';
plan skip_all => "Preconditions failed; your filesystem is strange"
- unless -d "/etc" && -e "/etc/passwd";
+ unless -d "/etc" && -e "/etc/passwd";
+
+plan skip_all => "Preconditions failed"
+ if -e $no_exist;
use MooseX::Types::Path::Class qw(ExistingFile ExistingDir);
ok is_ExistingDir(to_ExistingDir("/etc/")), '/etc/ is an existing directory';
+throws_ok { Bar->new( dir => $no_exist ); }
+ qr/Directory .* must exist/, 'no exist dir throws';
+throws_ok { Bar->new( file => "$no_exist/either" ); }
+ qr/File .* must exist/, 'no exist file throws';
+
done_testing;
+