See the test suite for File::Flat, I put a ton of work into making sure
it worked, and a lot of code doing filesystem stuff.
Adam K
James E Keenan wrote:
Let's say that I'm writing a test suite for a Perl module which creates
files and then, optionally, moves those files to predetermined
directories. To test this module's functionality, I would have to see
what happens when the user running the tests does not have write
permissions on the destination directory (e.g., test whether an
appropriate warning was issued). But to do *that*, I would have to
change permissions on a directory to forbid myself to write to it.
This code is intended to achieve that goal but doesn't DWIM:
my ($file, $workdir, $destdir);
{
$workdir = File::Temp::tempdir();
chdir $workdir or die "Cannot change to $workdir";
$file = system("touch alpha");
$destdir = "$workdir/other";
chmod 0330, ($destdir)
or die "Cannot change permissions on directory";
# dies on preceding line
rename $file, $destdir/$file or die "Cannot move $file";
}
Is there any other way to do this? Or am I mistaken in even attempting
to try it? Thanks.
Jim Keenan