perl - 如何编写测试文件夹是否可读/可写的测试

标签 perl testing perl-module

我编写了一个模块来检查目录是否可写或可读。 但是,我该如何测试呢?

通常,在编写模块时,您可以编写一些测试来测试模块的特性。我如何创建一个目录,该目录对于实际创建模块的测试是不可写的?

我想象的是这样的:

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');

但是我该如何创建一个目录,例如将其设置为只读,然后再将其删除?

最佳答案

尝试使用 File::Path 而不是 File::Temp , 它允许您选择能够设置您的 directories's permissions模式参数.将没有读取、写入或执行权限的目录的模式设置为 0000

假设它来自 Perl 核心,它应该可以在大多数操作系统上移植。

关于perl - 如何编写测试文件夹是否可读/可写的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18407726/

相关文章:

firefox - Selenium 错误 : no display specified

perl - APR::UUID 模块生成的标识符的保证唯一性是什么

Perl 哈希值 : how to deal with duplicate keys and get possible pair

perl - 从 Perl 模块导出所有常量(只读变量)的最有效方法是什么

perl - 如何遍历Perl数组引用?

perl - 修改Moose属性方法

perl - 如何在perl中删除文件的最后10行

testing - 如何执行组件级自动化测试 android 和 ios 应用程序?

perl - 如何使用 Perl Term::Readline 防止将空格附加到制表符完整的单词上?

testing - 在什么情况下,我们使用特定的测试设计方法(黑匣子测试)?