1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
use strict;
use warnings;
use FindBin ();
use File::Spec;
use Test::More tests => 14;
# Load the module.
use_ok 'Test::Fixme';
{ # Check that listing a directory that does not exist dies.
local $SIG{__WARN__} = sub { 1 };
eval { my @files = Test::Fixme::list_files('t/i/do/not/exist'); };
ok $@, 'list_files died';
ok $@ =~ m:^'t/i/do/not/exist' does not exist:,
"check that non-existent directory causes 'die'";
}
{ # Test that sub croaks unless a path is passed.
local $SIG{__WARN__} = sub { 1 };
eval { my @files = Test::Fixme::list_files(); };
ok $@, 'list_files died';
like $@,
qr{^You must specify a single directory, or reference to a list of directories},
"check that no directory causes 'die'";
}
{ # Test the list_files function.
my $dir = 't/dirs/normal';
my @files = Test::Fixme::list_files($dir);
my @wanted = sort map { "$dir/$_" } qw( one.txt two.pl three.pm four.pod );
is_deeply( \@files, \@wanted, "check correct files returned from '$dir'" );
}
{ # Check that the search descends into sub folders.
my $dir = 't/dirs/deep';
my @files = Test::Fixme::list_files($dir);
my @wanted = sort map { "$dir/$_" }
map { "$_.txt" }
qw'deep_a deep_b
one/deep_one_a one/deep_one_b
two/deep_two_a two/deep_two_b';
is_deeply( \@files, \@wanted, "check correct files returned from '$dir'" );
}
{ # Check that we can scan a reference to a list of dirnames
my @dirs = qw( t/dirs/normal t/dirs/deep/one );
my @files = Test::Fixme::list_files( \@dirs );
my @wanted =
sort qw(t/dirs/deep/one/deep_one_a.txt t/dirs/deep/one/deep_one_b.txt ),
map { "t/dirs/normal/$_" } qw( one.txt two.pl three.pm four.pod );
is_deeply( \@files, \@wanted,
"check correct files returned from " . join( ', ', @dirs ) );
}
{ # Test the list_files function with a filename_match regex
my $dir = 't/dirs/normal';
my @files = Test::Fixme::list_files( $dir, qr/\.(?:pl|pm)$/ );
my @wanted = sort map { "$dir/$_" } qw( two.pl three.pm );
is_deeply( \@files, \@wanted, "check correct files returned from '$dir'" );
}
SKIP: { # Check that non files do not get returned.
skip( "cannot create symlink", 4 ) unless eval { symlink( "", "" ); 1 };
my $dir = "t/dirs/types";
my $target = "normal.txt";
my $target_file = "$dir/$target";
my $symlink = "$dir/symlink";
# Make a symbolic link
ok symlink( $target, $symlink ), "create symlinked file";
ok -e $symlink, "symlink now exists";
my @files = Test::Fixme::list_files($dir);
my @wanted = ($target_file);
is_deeply( \@files, \@wanted,
"check that non files are not returned from '$dir'" );
ok unlink($symlink), "delete symlinked file";
}
{ # Test that you can pass in just a file
my @list = eval { Test::Fixme::list_files(File::Spec->catfile($FindBin::Bin, 'dirs', 'normal', 'three.pm')) };
diag $@ if $@;
like $list[0], qr{three.pm$}, "can give list_files directories or files";
}
|