Bump version to 2.4.2 for development of next release
[gnu-stow.git] / t / link_dest_within_stow_dir.t
blob01ec2f4f49e947525e30d024a90ae8b26362a0ca
1 #!/usr/bin/perl
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 Stow::link_dest_within_stow_dir()
22 use strict;
23 use warnings;
25 use Test::More tests => 6;
27 use testutil;
28 use Stow::Util;
30 init_test_dirs();
32 # This is a relative path, unlike $ABS_TEST_DIR below.
33 my $stow = new_Stow(dir => "$TEST_DIR/stow",
34 target => "$TEST_DIR/target");
36 subtest("relative stow dir, link to top-level package file" => sub {
37 plan tests => 2;
38 my ($package, $path) =
39 $stow->link_dest_within_stow_dir("../stow/pkg/dir/file");
40 is($package, "pkg", "package");
41 is($path, "dir/file", "path");
42 });
44 subtest("relative stow dir, link to second-level package file" => sub {
45 plan tests => 2;
46 my ($package, $path) =
47 $stow->link_dest_within_stow_dir("../stow/pkg/dir/subdir/file");
48 is($package, "pkg", "package");
49 is($path, "dir/subdir/file", "path");
50 });
52 # This is an absolute path, unlike $TEST_DIR above.
53 $stow = new_Stow(dir => "$ABS_TEST_DIR/stow",
54 target => "$ABS_TEST_DIR/target");
56 subtest("relative stow dir, link to second-level package file" => sub {
57 plan tests => 2;
58 my ($package, $path) =
59 $stow->link_dest_within_stow_dir("../stow/pkg/dir/file");
60 is($package, "pkg", "package");
61 is($path, "dir/file", "path");
62 });
64 subtest("absolute stow dir, link to top-level package file" => sub {
65 plan tests => 2;
66 my ($package, $path) =
67 $stow->link_dest_within_stow_dir("../stow/pkg/dir/subdir/file");
68 is($package, "pkg", "package");
69 is($path, "dir/subdir/file", "path");
70 });
72 # Links with destination in the target are not pointing within
73 # the stow dir, so they're not owned by stow.
74 subtest("link to path in target" => sub {
75 plan tests => 2;
76 my ($package, $path) =
77 $stow->link_dest_within_stow_dir("./alien");
78 is($path, "", "alien is in target, so path is empty");
79 is($package, "", "alien is in target, so package is empty");
80 });
82 subtest("link to path outside target and stow dir" => sub {
83 plan tests => 2;
84 my ($package, $path) =
85 $stow->link_dest_within_stow_dir("../alien");
86 is($path, "", "alien is outside, so path is empty");
87 is($package, "", "alien is outside, so package is empty");
88 });