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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
use strict;
use warnings;
use Test::More tests => 22;
use File::Spec::Functions ':ALL';
use File::Find::Rule ();
use File::Find::Rule::Perl ();
use constant FFR => 'File::Find::Rule';
#####################################################################
# Run four variations of the standard query
SCOPE: {
my @params = (
[ ],
[ curdir() ],
[ 'META.yml' ],
[ { directory => [ 'inc', 't', 'xt' ] } ],
);
foreach my $p ( @params ) {
my $rule = FFR->relative->no_index(@$p)->file;
isa_ok( $rule, 'File::Find::Rule' );
my %ignore = map { $_ => 1 } qw{
Makefile
MANIFEST
MANIFEST.SKIP
LICENSE
README
pm_to_blib
MYMETA.yml
MYMETA.json
};
my @files = sort grep {
! /^debian\b/
and
! /(?:^|\W)\.\w/
and
! /^\.pc\b/
and
! /\bblib\b/
and
! /\b_eumm\b/
and
! $ignore{$_}
} $rule->in( curdir() );
SKIP: {
skip 'running under autopkgtest', 1 if -e 'lib/Debian/pkgperl/Foobar.pm';
is_deeply( \@files, [ qw{
Changes
META.json
META.yml
Makefile.PL
lib/File/Find/Rule/Perl.pm
} ], 'Found the expected files' );
}
}
}
###################################################################
# Several variations of absolute path and relative path , both
# in no_index and in search prefix.
SCOPE: {
my @params = (
{
name => 'Relative Path',
path => 'lib/File/Find/Rule/Perl.pm',
dir => curdir(),
check => [ 'Rule', 'Perl.pm' ],
},
{
name => 'Absolute path, Absolute Dir',
path => rel2abs(curdir())
. '/lib/File/Find/Rule/Perl.pm',
dir => rel2abs(curdir()),
check => [ 'Rule', 'Perl.pm' ],
},
);
foreach my $p ( @params ) {
my $check = quotemeta File::Spec->catfile( @{$p->{check}} );
my $regex = qr/$check/;
my $rule = FFR->relative->no_index( {
file => [ $p->{path} ]
} )->file;
my @files = sort grep {
$_ !~ m/\bblib\b/ and $_ =~ $regex
} $rule->in( $p->{dir} );
if ( @files ) {
ok( 0, 'No_index + filename ' . $p->{name} );
for ( @files ) {
diag( "File Found: $_ \n , no_index file was <$p->{path}>");
}
} else {
ok( 1, 'No_index + filename ' . $p->{name} );
}
}
}
#####################################################################
# Run a test in a relative subdirectory
# Test with and without ->relative, and with and without a relative ->in
# With relative enabled
SCOPE: {
my $dir = catdir('t', 'dist');
ok( -d $dir, 'Found testing directory' );
my $rule = FFR->relative->no_index->file;
isa_ok( $rule, 'File::Find::Rule' );
my @files = sort grep {
! /\.svn\b/
and
! /\bblib\b/
} $rule->in($dir);
is_deeply( \@files, [ qw{
META.yml
lib/Foo.pm
} ], 'Found the expected files' );
}
# With relative disabled
SCOPE: {
my $dir = catdir('t', 'dist');
ok( -d $dir, 'Found testing directory' );
my $rule = FFR->no_index->file;
isa_ok( $rule, 'File::Find::Rule' );
my @files = sort grep {
! /\.svn\b/
and
! /\bblib\b/
} $rule->in($dir);
is( scalar(@files), 2, 'Found the same file quantity' );
}
# With relative enabled
SCOPE: {
my $dir = rel2abs(catdir('t', 'dist'));
ok( -d $dir, 'Found testing directory' );
my $rule = FFR->relative->no_index->file;
isa_ok( $rule, 'File::Find::Rule' );
my @files = sort grep {
! /\.svn\b/
and
! /\bblib\b/
} $rule->in($dir);
is_deeply( \@files, [ qw{
META.yml
lib/Foo.pm
} ], 'Found the expected files' );
}
# With relative disabled
SCOPE: {
my $dir = rel2abs(catdir('t', 'dist'));
ok( -d $dir, 'Found testing directory' );
my $rule = FFR->no_index->file;
isa_ok( $rule, 'File::Find::Rule' );
my @files = sort grep {
! /\.svn\b/
and
! /\bblib\b/
} $rule->in($dir);
is( scalar(@files), 2, 'Found the same file quantity' );
}
|