1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#!/usr/bin/perl -w
use strict;
use Test::More;
use FindBin qw($Bin);
use constant TMPDIR => "$Bin/mkdir_test_delete_me";
# Delete our directory if it's there
rmdir TMPDIR;
# See if we can create directories and remove them
mkdir TMPDIR or plan skip_all => "Failed to make test directory";
# Test the directory was created
-d TMPDIR or plan skip_all => "Failed to make test directory";
# Try making it a second time (this should fail)
if(mkdir TMPDIR) { plan skip_all => "Attempt to remake a directory succeeded";}
# See if we can remove the directory
rmdir TMPDIR or plan skip_all => "Failed to remove directory";
# Check that the directory was removed
if(-d TMPDIR) { plan skip_all => "Failed to delete test directory"; }
# Try to delete second time
if(rmdir TMPDIR) { plan skip_all => "Able to rmdir directory twice"; }
plan tests => 12;
# Create a directory (this should succeed)
eval {
use autodie;
mkdir TMPDIR;
};
is($@, "", "mkdir returned success");
ok(-d TMPDIR, "Successfully created test directory");
# Try to create it again (this should fail)
eval {
use autodie;
mkdir TMPDIR;
};
ok($@, "Re-creating directory causes failure.");
isa_ok($@, "autodie::exception", "... errors are of the correct type");
ok($@->matches("mkdir"), "... it's also a mkdir object");
ok($@->matches(":filesys"), "... and a filesys object");
# Try to delete directory (this should succeed)
eval {
use autodie;
rmdir TMPDIR;
};
is($@, "", "rmdir returned success");
ok(! -d TMPDIR, "Successfully removed test directory");
# Try to delete directory again (this should fail)
eval {
use autodie;
rmdir TMPDIR;
};
ok($@, "Re-deleting directory causes failure.");
isa_ok($@, "autodie::exception", "... errors are of the correct type");
ok($@->matches("rmdir"), "... it's also a rmdir object");
ok($@->matches(":filesys"), "... and a filesys object");
|