3 # This file is part of GNU Stow.
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.
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.
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/.
19 # Testing cleanup_invalid_links()
25 use Test
::More tests
=> 4;
26 use English
qw(-no_match_vars);
32 cd
("$TEST_DIR/target");
36 # Note that each of the following tests use a distinct set of files
38 subtest
('nothing to clean in a simple tree' => sub {
41 make_path
('../stow/pkg1/bin1');
42 make_file
('../stow/pkg1/bin1/file1');
43 make_link
('bin1', '../stow/pkg1/bin1');
46 $stow->cleanup_invalid_links('./');
48 scalar($stow->get_tasks), 0
53 subtest
('cleanup an orphaned owned link in a simple tree' => sub {
57 make_path
('../stow/pkg2/bin2');
58 make_file
('../stow/pkg2/bin2/file2a');
59 make_link
('bin2/file2a', '../../stow/pkg2/bin2/file2a');
60 make_invalid_link
('bin2/file2b', '../../stow/pkg2/bin2/file2b');
63 $stow->cleanup_invalid_links('bin2');
64 is
($stow->get_conflict_count, 0, 'no conflicts cleaning up bad link');
65 is
(scalar($stow->get_tasks), 1, 'one task cleaning up bad link');
66 is
($stow->link_task_action('bin2/file2b'), 'remove', 'removal task for bad link');
69 subtest
("don't cleanup a bad link not owned by stow" => sub {
73 make_path
('../stow/pkg3/bin3');
74 make_file
('../stow/pkg3/bin3/file3a');
75 make_link
('bin3/file3a', '../../stow/pkg3/bin3/file3a');
76 make_invalid_link
('bin3/file3b', '../../empty');
79 $stow->cleanup_invalid_links('bin3');
80 is
($stow->get_conflict_count, 0, 'no conflicts cleaning up bad link not owned by stow');
81 is
(scalar($stow->get_tasks), 0, 'no tasks cleaning up bad link not owned by stow');
84 subtest
("don't cleanup a valid link in the target not owned by stow" => sub {
88 make_path
('../stow/pkg4/bin4');
89 make_file
('../stow/pkg4/bin4/file3a');
90 make_link
('bin4/file3a', '../../stow/pkg4/bin4/file3a');
92 make_link
('bin4/file3b', '../unowned');
95 $stow->cleanup_invalid_links('bin4');
96 is
($stow->get_conflict_count, 0, 'no conflicts cleaning up bad link not owned by stow');
97 is
(scalar($stow->get_tasks), 0, 'no tasks cleaning up bad link not owned by stow');