Bump version to 2.1.1
[gnu-stow.git] / t / find_stowed_path.t
blob2d5425d2adde8ccc7c285ceef666c4ac5c595732
1 #!/usr/local/bin/perl
4 # Testing find_stowed_path()
7 use strict;
8 use warnings;
10 use testutil;
12 use Test::More tests => 6;
14 init_test_dirs();
16 my $stow = new_Stow(dir => "$OUT_DIR/stow");
18 is_deeply(
19 [ $stow->find_stowed_path("$OUT_DIR/target/a/b/c", '../../../stow/a/b/c') ],
20 [ "$OUT_DIR/stow/a/b/c", "$OUT_DIR/stow", 'a' ]
21 => 'from root'
24 cd("$OUT_DIR/target");
25 $stow->set_stow_dir('../stow');
26 is_deeply(
27 [ $stow->find_stowed_path('a/b/c','../../../stow/a/b/c') ],
28 [ '../stow/a/b/c', '../stow', 'a' ]
29 => 'from target directory'
32 make_dir('stow');
33 cd('../..');
34 $stow->set_stow_dir("$OUT_DIR/target/stow");
36 is_deeply(
37 [ $stow->find_stowed_path("$OUT_DIR/target/a/b/c", '../../stow/a/b/c') ],
38 [ "$OUT_DIR/target/stow/a/b/c", "$OUT_DIR/target/stow", 'a' ]
39 => 'stow is subdir of target directory'
42 is_deeply(
43 [ $stow->find_stowed_path("$OUT_DIR/target/a/b/c",'../../empty') ],
44 [ '', '', '' ]
45 => 'target is not stowed'
48 make_dir("$OUT_DIR/target/stow2");
49 make_file("$OUT_DIR/target/stow2/.stow");
51 is_deeply(
52 [ $stow->find_stowed_path("$OUT_DIR/target/a/b/c",'../../stow2/a/b/c') ],
53 [ "$OUT_DIR/target/stow2/a/b/c", "$OUT_DIR/target/stow2", 'a' ]
54 => q(detect alternate stow directory)
57 # Possible corner case with rogue symlink pointing to ancestor of
58 # stow dir.
59 is_deeply(
60 [ $stow->find_stowed_path("$OUT_DIR/target/a/b/c",'../../..') ],
61 [ '', '', '' ]
62 => q(corner case - link points to ancestor of stow dir)