Blame t/mkdir.t

Packit 6427f8
#!/usr/bin/perl -w
Packit 6427f8
use strict;
Packit 6427f8
use Test::More;
Packit 6427f8
use FindBin qw($Bin);
Packit 6427f8
use constant TMPDIR => "$Bin/mkdir_test_delete_me";
Packit 6427f8
use constant ERROR_REGEXP => qr{Can't mkdir\('${\(TMPDIR)}', 0777\):};
Packit 6427f8
use constant SINGLE_DIGIT_ERROR_REGEXP => qr{Can't mkdir\('${\(TMPDIR)}', 0010\):};
Packit 6427f8
Packit 6427f8
# Delete our directory if it's there
Packit 6427f8
rmdir TMPDIR;
Packit 6427f8
Packit 6427f8
# See if we can create directories and remove them
Packit 6427f8
mkdir TMPDIR or plan skip_all => "Failed to make test directory";
Packit 6427f8
Packit 6427f8
# Test the directory was created
Packit 6427f8
-d TMPDIR or plan skip_all => "Failed to make test directory";
Packit 6427f8
Packit 6427f8
# Try making it a second time (this should fail)
Packit 6427f8
if(mkdir TMPDIR) { plan skip_all => "Attempt to remake a directory succeeded";}
Packit 6427f8
Packit 6427f8
# See if we can remove the directory
Packit 6427f8
rmdir TMPDIR or plan skip_all => "Failed to remove directory";
Packit 6427f8
Packit 6427f8
# Check that the directory was removed
Packit 6427f8
if(-d TMPDIR) { plan skip_all => "Failed to delete test directory"; }
Packit 6427f8
Packit 6427f8
# Try to delete second time
Packit 6427f8
if(rmdir TMPDIR) { plan skip_all => "Able to rmdir directory twice"; }
Packit 6427f8
Packit 6427f8
plan tests => 18;
Packit 6427f8
Packit 6427f8
# Create a directory (this should succeed)
Packit 6427f8
eval {
Packit 6427f8
	use autodie;
Packit 6427f8
Packit 6427f8
	mkdir TMPDIR;
Packit 6427f8
};
Packit 6427f8
is($@, "", "mkdir returned success");
Packit 6427f8
ok(-d TMPDIR, "Successfully created test directory");
Packit 6427f8
Packit 6427f8
# Try to create it again (this should fail)
Packit 6427f8
eval {
Packit 6427f8
	use autodie;
Packit 6427f8
Packit 6427f8
	mkdir TMPDIR, 0777;
Packit 6427f8
};
Packit 6427f8
ok($@, "Re-creating directory causes failure.");
Packit 6427f8
isa_ok($@, "autodie::exception", "... errors are of the correct type");
Packit 6427f8
ok($@->matches("mkdir"), "... it's also a mkdir object");
Packit 6427f8
ok($@->matches(":filesys"), "... and a filesys object");
Packit 6427f8
like($@, ERROR_REGEXP, "Message should include numeric mask in octal form");
Packit 6427f8
Packit 6427f8
eval {
Packit 6427f8
        use autodie;
Packit 6427f8
Packit 6427f8
        mkdir TMPDIR, 8;
Packit 6427f8
};
Packit 6427f8
ok($@, "Re-creating directory causes failure.");
Packit 6427f8
isa_ok($@, "autodie::exception", "... errors are of the correct type");
Packit 6427f8
ok($@->matches("mkdir"), "... it's also a mkdir object");
Packit 6427f8
ok($@->matches(":filesys"), "... and a filesys object");
Packit 6427f8
like($@, SINGLE_DIGIT_ERROR_REGEXP, "Message should include numeric mask in octal form");
Packit 6427f8
Packit 6427f8
# Try to delete directory (this should succeed)
Packit 6427f8
eval {
Packit 6427f8
	use autodie;
Packit 6427f8
Packit 6427f8
	rmdir TMPDIR;
Packit 6427f8
};
Packit 6427f8
is($@, "", "rmdir returned success");
Packit 6427f8
ok(! -d TMPDIR, "Successfully removed test directory");
Packit 6427f8
Packit 6427f8
# Try to delete directory again (this should fail)
Packit 6427f8
eval {
Packit 6427f8
	use autodie;
Packit 6427f8
Packit 6427f8
	rmdir TMPDIR;
Packit 6427f8
};
Packit 6427f8
ok($@, "Re-deleting directory causes failure.");
Packit 6427f8
isa_ok($@, "autodie::exception", "... errors are of the correct type");
Packit 6427f8
ok($@->matches("rmdir"), "... it's also a rmdir object");
Packit 6427f8
ok($@->matches(":filesys"), "... and a filesys object");
Packit 6427f8