2019-06-27 15:37:50 -04:00
|
|
|
#!/usr/bin/perl
|
2019-06-27 09:02:19 -04:00
|
|
|
#
|
|
|
|
# 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/.
|
2011-11-16 09:04:03 -05:00
|
|
|
|
|
|
|
#
|
|
|
|
# Testing find_stowed_path()
|
|
|
|
#
|
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2019-06-28 10:23:52 -04:00
|
|
|
use Test::More tests => 18;
|
2011-11-24 11:28:09 -05:00
|
|
|
|
2019-06-28 05:32:18 -04:00
|
|
|
use testutil;
|
|
|
|
use Stow::Util qw(set_debug_level);
|
|
|
|
|
2011-11-23 18:45:48 -05:00
|
|
|
init_test_dirs();
|
2011-11-24 11:28:09 -05:00
|
|
|
|
2019-06-27 19:53:12 -04:00
|
|
|
my $stow = new_Stow(dir => "$TEST_DIR/stow");
|
2019-06-28 05:32:18 -04:00
|
|
|
#set_debug_level(4);
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2019-06-28 10:23:52 -04:00
|
|
|
my ($path, $stow_path, $package) =
|
|
|
|
$stow->find_stowed_path("$TEST_DIR/target/a/b/c", "../../../stow/a/b/c");
|
|
|
|
is($path, "$TEST_DIR/stow/a/b/c", "path");
|
|
|
|
is($stow_path, "$TEST_DIR/stow", "stow path");
|
|
|
|
is($package, "a", "package");
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2019-06-27 19:53:12 -04:00
|
|
|
cd("$TEST_DIR/target");
|
2019-06-28 10:23:52 -04:00
|
|
|
$stow->set_stow_dir("../stow");
|
|
|
|
($path, $stow_path, $package) =
|
|
|
|
$stow->find_stowed_path("a/b/c", "../../../stow/a/b/c");
|
|
|
|
is($path, "../stow/a/b/c", "path from target directory");
|
|
|
|
is($stow_path, "../stow", "stow path from target directory");
|
|
|
|
is($package, "a", "from target directory");
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2019-06-28 10:23:52 -04:00
|
|
|
make_path("stow");
|
|
|
|
cd("../..");
|
2019-06-27 19:53:12 -04:00
|
|
|
$stow->set_stow_dir("$TEST_DIR/target/stow");
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2019-06-28 10:23:52 -04:00
|
|
|
($path, $stow_path, $package) =
|
|
|
|
$stow->find_stowed_path("$TEST_DIR/target/a/b/c", "../../stow/a/b/c");
|
|
|
|
is($path, "$TEST_DIR/target/stow/a/b/c", "path");
|
|
|
|
is($stow_path, "$TEST_DIR/target/stow", "stow path");
|
|
|
|
is($package, "a", "stow is subdir of target directory");
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2019-06-28 10:23:52 -04:00
|
|
|
($path, $stow_path, $package) =
|
|
|
|
$stow->find_stowed_path("$TEST_DIR/target/a/b/c", "../../empty");
|
|
|
|
is($path, "", "empty path");
|
|
|
|
is($stow_path, "", "empty stow path");
|
|
|
|
is($package, "", "target is not stowed");
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2024-03-09 13:11:00 -05:00
|
|
|
# Make a second stow directory within the target directory, so that we
|
|
|
|
# can check that links to package files within that second stow
|
|
|
|
# directory are detected correctly.
|
2019-06-27 20:02:48 -04:00
|
|
|
make_path("$TEST_DIR/target/stow2");
|
2019-06-27 19:53:12 -04:00
|
|
|
make_file("$TEST_DIR/target/stow2/.stow");
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2019-06-28 10:23:52 -04:00
|
|
|
($path, $stow_path, $package) =
|
2024-03-09 13:11:29 -05:00
|
|
|
$stow->find_stowed_path("$TEST_DIR/target/a/b/c", "../../stow2/a/b/c");
|
2019-06-28 10:23:52 -04:00
|
|
|
is($path, "$TEST_DIR/target/stow2/a/b/c", "path");
|
|
|
|
is($stow_path, "$TEST_DIR/target/stow2", "stow path");
|
|
|
|
is($package, "a", "detect alternate stow directory");
|
2011-11-24 11:28:09 -05:00
|
|
|
|
|
|
|
# Possible corner case with rogue symlink pointing to ancestor of
|
|
|
|
# stow dir.
|
2019-06-28 10:23:52 -04:00
|
|
|
($path, $stow_path, $package) =
|
2024-03-09 13:11:29 -05:00
|
|
|
$stow->find_stowed_path("$TEST_DIR/target/a/b/c", "../../..");
|
2019-06-28 10:23:52 -04:00
|
|
|
is($path, "", "path");
|
|
|
|
is($stow_path, "", "stow path");
|
|
|
|
is($package, "", "corner case - link points to ancestor of stow dir");
|