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 find_stowed_path()
25 use Test
::More tests
=> 18;
28 use Stow
::Util
qw(set_debug_level);
32 my $stow = new_Stow
(dir
=> "$TEST_DIR/stow");
35 my ($path, $stow_path, $package) =
36 $stow->find_stowed_path("$TEST_DIR/target/a/b/c", "../../../stow/a/b/c");
37 is
($path, "$TEST_DIR/stow/a/b/c", "path");
38 is
($stow_path, "$TEST_DIR/stow", "stow path");
39 is
($package, "a", "package");
41 cd
("$TEST_DIR/target");
42 $stow->set_stow_dir("../stow");
43 ($path, $stow_path, $package) =
44 $stow->find_stowed_path("a/b/c", "../../../stow/a/b/c");
45 is
($path, "../stow/a/b/c", "path from target directory");
46 is
($stow_path, "../stow", "stow path from target directory");
47 is
($package, "a", "from target directory");
51 $stow->set_stow_dir("$TEST_DIR/target/stow");
53 ($path, $stow_path, $package) =
54 $stow->find_stowed_path("$TEST_DIR/target/a/b/c", "../../stow/a/b/c");
55 is
($path, "$TEST_DIR/target/stow/a/b/c", "path");
56 is
($stow_path, "$TEST_DIR/target/stow", "stow path");
57 is
($package, "a", "stow is subdir of target directory");
59 ($path, $stow_path, $package) =
60 $stow->find_stowed_path("$TEST_DIR/target/a/b/c", "../../empty");
61 is
($path, "", "empty path");
62 is
($stow_path, "", "empty stow path");
63 is
($package, "", "target is not stowed");
65 # Make a second stow directory within the target directory, so that we
66 # can check that links to package files within that second stow
67 # directory are detected correctly.
68 make_path
("$TEST_DIR/target/stow2");
69 make_file
("$TEST_DIR/target/stow2/.stow");
71 ($path, $stow_path, $package) =
72 $stow->find_stowed_path("$TEST_DIR/target/a/b/c", "../../stow2/a/b/c");
73 is
($path, "$TEST_DIR/target/stow2/a/b/c", "path");
74 is
($stow_path, "$TEST_DIR/target/stow2", "stow path");
75 is
($package, "a", "detect alternate stow directory");
77 # Possible corner case with rogue symlink pointing to ancestor of
79 ($path, $stow_path, $package) =
80 $stow->find_stowed_path("$TEST_DIR/target/a/b/c", "../../..");
81 is
($path, "", "path");
82 is
($stow_path, "", "stow path");
83 is
($package, "", "corner case - link points to ancestor of stow dir");