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
|
use 5.006;
use strict;
use warnings;
use Test::More 0.92;
use Path::Tiny;
use File::Temp;
use Test::Deep qw/cmp_deeply/;
use File::pushd qw/pushd/;
use Config;
use lib 't/lib';
use PCNTest;
use Path::Iterator::Rule;
#--------------------------------------------------------------------------#
plan skip_all => "No symlink support"
unless $Config{d_symlink};
#--------------------------------------------------------------------------#
{
my @tree = qw(
aaaa.txt
bbbb.txt
cccc/dddd.txt
cccc/eeee/ffff.txt
gggg.txt
);
my @follow = qw(
.
aaaa.txt
bbbb.txt
cccc
gggg.txt
pppp
qqqq.txt
cccc/dddd.txt
cccc/eeee
pppp/ffff.txt
);
my @not_loop_safe = qw(
.
aaaa.txt
bbbb.txt
cccc
gggg.txt
pppp
qqqq.txt
cccc/dddd.txt
cccc/eeee
pppp/ffff.txt
cccc/eeee/ffff.txt
);
my @nofollow = qw(
.
aaaa.txt
bbbb.txt
cccc
gggg.txt
cccc/dddd.txt
cccc/eeee
cccc/eeee/ffff.txt
);
my $td = make_tree(@tree);
symlink path( $td, 'cccc', 'eeee' ), path( $td, 'pppp' );
symlink path( $td, 'aaaa.txt' ), path( $td, 'qqqq.txt' );
my ( $iter, @files );
my $rule = Path::Iterator::Rule->new;
@files = map { unixify( $_, $td ) } $rule->all($td);
cmp_deeply( \@files, \@follow, "Follow symlinks" )
or diag explain { got => \@files, expected => \@follow };
@files = map { unixify( $_, $td ) } $rule->all( $td, { loop_safe => 0 } );
cmp_deeply( \@files, \@not_loop_safe, "Follow symlinks, but loop_safe = 0" )
or diag explain { got => \@files, expected => \@not_loop_safe };
@files = map { unixify( $_, $td ) } $rule->all( { follow_symlinks => 0 }, $td );
cmp_deeply( \@files, \@nofollow, "Don't follow symlinks" )
or diag explain { got => \@files, expected => \@nofollow };
}
{
my @tree = qw(
aaaa.txt
bbbb.txt
cccc/dddd.txt
);
my $td = make_tree(@tree);
symlink path( $td, 'zzzz' ), path( $td, 'pppp' ); # dangling symlink
symlink path( $td, 'cccc', 'dddd.txt' ), path( $td, 'qqqq.txt' ); # regular symlink
my @dangling = qw(
pppp
);
my @not_dangling = qw(
.
aaaa.txt
bbbb.txt
cccc
qqqq.txt
cccc/dddd.txt
);
my @valid_symlinks = qw(
qqqq.txt
);
my ( $rule, @files );
$rule = Path::Iterator::Rule->new->dangling;
@files = map { unixify( $_, $td ) } $rule->all($td);
cmp_deeply( \@files, \@dangling, "Dangling symlinks" )
or diag explain { got => \@files, expected => \@dangling };
$rule = Path::Iterator::Rule->new->not_dangling;
@files = map { unixify( $_, $td ) } $rule->all($td);
cmp_deeply( \@files, \@not_dangling, "No dangling symlinks" )
or diag explain { got => \@files, expected => \@not_dangling };
$rule = Path::Iterator::Rule->new->symlink->not_dangling;
@files = map { unixify( $_, $td ) } $rule->all($td);
cmp_deeply( \@files, \@valid_symlinks, "Only non-dangling symlinks" )
or diag explain { got => \@files, expected => \@valid_symlinks };
}
{
my @tree = qw(
aaaa.txt
bbbb.txt
cccc/dddd.txt
);
my $td = make_tree(@tree);
symlink path( $td, 'cccc' ), path( $td, 'cccc', 'eeee' ); # symlink loop
my @expected = qw(
.
aaaa.txt
bbbb.txt
cccc
cccc/dddd.txt
cccc/eeee
);
my ( $rule, @files );
$rule = Path::Iterator::Rule->new;
@files = map { unixify( $_, $td ) } $rule->all($td);
cmp_deeply( \@files, \@expected, "Symlink loop" )
or diag explain { got => \@files, expected => \@expected };
}
done_testing;
#
# This file is part of Path-Iterator-Rule
#
# This software is Copyright (c) 2013 by David Golden.
#
# This is free software, licensed under:
#
# The Apache License, Version 2.0, January 2004
#
|