1#!/usr/bin/perl
2#
3# This file is part of GNU Stow.
4#
5# GNU Stow is free software: you can redistribute it and/or modify it
6# under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# GNU Stow is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see https://www.gnu.org/licenses/.
17
18#
19# Testing foldable()
20#
21
22use strict;
23use warnings;
24
25use testutil;
26
27use Test::More tests => 4;
28use English qw(-no_match_vars);
29
30init_test_dirs();
31cd("$TEST_DIR/target");
32
33my $stow = new_Stow(dir => '../stow');
34
35# Note that each of the following tests use a distinct set of files
36
37#
38# can fold a simple tree
39#
40
41make_path('../stow/pkg1/bin1');
42make_file('../stow/pkg1/bin1/file1');
43make_path('bin1');
44make_link('bin1/file1','../../stow/pkg1/bin1/file1');
45
46is( $stow->foldable('bin1'), '../stow/pkg1/bin1' => q(can fold a simple tree) );
47
48#
49# can't fold an empty directory
50#
51
52make_path('../stow/pkg2/bin2');
53make_file('../stow/pkg2/bin2/file2');
54make_path('bin2');
55
56is( $stow->foldable('bin2'), '' => q(can't fold an empty directory) );
57
58#
59# can't fold if dir contains a non-link
60#
61
62make_path('../stow/pkg3/bin3');
63make_file('../stow/pkg3/bin3/file3');
64make_path('bin3');
65make_link('bin3/file3','../../stow/pkg3/bin3/file3');
66make_file('bin3/non-link');
67
68is( $stow->foldable('bin3'), '' => q(can't fold a dir containing non-links) );
69
70#
71# can't fold if links point to different directories
72#
73
74make_path('bin4');
75make_path('../stow/pkg4a/bin4');
76make_file('../stow/pkg4a/bin4/file4a');
77make_link('bin4/file4a','../../stow/pkg4a/bin4/file4a');
78make_path('../stow/pkg4b/bin4');
79make_file('../stow/pkg4b/bin4/file4b');
80make_link('bin4/file4b','../../stow/pkg4b/bin4/file4b');
81
82is( $stow->foldable('bin4'), '' => q(can't fold if links point to different dirs) );
83