rearranging. need to redo with dzil
[gitmo/MooseX-Types-Path-Class.git] / t / 04.existing.t
index 8292d9c..5d8f63e 100644 (file)
@@ -1,9 +1,37 @@
+
+{
+
+    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);
 
@@ -11,4 +39,10 @@ ok is_ExistingFile(to_ExistingFile("/etc/passwd")), '/etc/passwd is an existing
 
 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;
+