Я пишу тест для функции, которая получает список всех *.pm
файлов в текущем каталоге.
Вот функция:
sub get_inspected_modules_list {
my ( $dir ) = @_;
opendir(my $dh, $dir) or die $!;
my @files;
while (my $file = readdir($dh)) {
next unless (-f "$dir/$file"); # skip nested dirs
next unless ($file =~ m/\.pm$/); # push only *.pm
push @files, $file;
}
closedir($dh);
return \@files
}
Я пытался использовать Тест:: MockFile :: DirHandle для теста, но он печатает No such file or directory
ошибка:
subtest "get_inspected_modules_list" => sub {
my $handle = Test::MockFile::DirHandle->new(
"/fake/path",
[qw/Foo.pm Bar.pm Baz.pm test.txt 1.pl/]
);
warn Dumper get_inspected_modules_list( '/fake/path' ); # error
};
Как смоделировать вызовы opendir / readdir?