我编写了一个模块来检查目录是否可写或可读。但是,我该如何测试呢?
通常,在编写模块时,您可以编写一些测试来测试模块的功能。如何创建一个目录,该目录不可被实际创建模块的测试写入?
我想象这样的事情:
use strict;
use warnings;
use File::Temp qw/ tempdir /;
use Test::More tests => 5;
BEGIN { use_ok('My::DirCheck') };
my $readable_dir = tempdir();
my $check = My::DirCheck->new(directory => $readable_dir);
is($check->is_readable(), 1, 'temp dir is readable');
# FIXME: how to make it not readale?
isnt($check->is_readable(), 1, 'temp dir is not readable');
my $writable_dir = tempdir();
is($check->is_writeable(), 1, 'temp dir is writeable');
# FIXME: how to make it not writable?
isnt($check->is_writeable(), 1, 'temp dir is not writeable');
但是我如何创建一个目录,使其例如只读并在之后摆脱它?