File: foldable.t

package info (click to toggle)
stow 2.4.1-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,304 kB
  • sloc: perl: 4,355; sh: 710; makefile: 184
file content (82 lines) | stat: -rwxr-xr-x 2,134 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl
#
# This file is part of GNU Stow.
#
# GNU Stow is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GNU Stow is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see https://www.gnu.org/licenses/.

#
# Testing foldable()
#

use strict;
use warnings;

use testutil;

use Test::More tests => 4;
use English qw(-no_match_vars);

init_test_dirs();
cd("$TEST_DIR/target");

my $stow = new_Stow(dir => '../stow');

# Note that each of the following tests use a distinct set of files

#
# can fold a simple tree
#

make_path('../stow/pkg1/bin1');
make_file('../stow/pkg1/bin1/file1');
make_path('bin1');
make_link('bin1/file1','../../stow/pkg1/bin1/file1');

is( $stow->foldable('bin1'), '../stow/pkg1/bin1' => q(can fold a simple tree) );

#
# can't fold an empty directory 
# 

make_path('../stow/pkg2/bin2');
make_file('../stow/pkg2/bin2/file2');
make_path('bin2');

is( $stow->foldable('bin2'), '' => q(can't fold an empty directory) );

#
# can't fold if dir contains a non-link
#

make_path('../stow/pkg3/bin3');
make_file('../stow/pkg3/bin3/file3');
make_path('bin3');
make_link('bin3/file3','../../stow/pkg3/bin3/file3');
make_file('bin3/non-link');

is( $stow->foldable('bin3'), '' => q(can't fold a dir containing non-links) );

#
# can't fold if links point to different directories
#

make_path('bin4');
make_path('../stow/pkg4a/bin4');
make_file('../stow/pkg4a/bin4/file4a');
make_link('bin4/file4a','../../stow/pkg4a/bin4/file4a');
make_path('../stow/pkg4b/bin4');
make_file('../stow/pkg4b/bin4/file4b');
make_link('bin4/file4b','../../stow/pkg4b/bin4/file4b');

is( $stow->foldable('bin4'), '' => q(can't fold if links point to different dirs) );