2011-11-16 09:04:03 -05:00
|
|
|
#!/usr/local/bin/perl
|
|
|
|
|
|
|
|
#
|
|
|
|
# Testing find_stowed_path()
|
|
|
|
#
|
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
use testutil;
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
use Test::More tests => 6;
|
|
|
|
|
2011-11-23 18:45:48 -05:00
|
|
|
init_test_dirs();
|
2011-11-24 11:28:09 -05:00
|
|
|
|
|
|
|
my $stow = new_Stow(dir => 't/stow');
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2011-11-23 18:45:48 -05:00
|
|
|
is_deeply(
|
|
|
|
[ $stow->find_stowed_path('t/target/a/b/c', '../../../stow/a/b/c') ],
|
|
|
|
[ 't/stow/a/b/c', 't/stow', 'a' ]
|
2011-11-16 09:04:03 -05:00
|
|
|
=> 'from root'
|
|
|
|
);
|
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
cd('t/target');
|
|
|
|
$stow->set_stow_dir('../stow');
|
2011-11-23 18:45:48 -05:00
|
|
|
is_deeply(
|
|
|
|
[ $stow->find_stowed_path('a/b/c','../../../stow/a/b/c') ],
|
|
|
|
[ '../stow/a/b/c', '../stow', 'a' ]
|
2011-11-16 09:04:03 -05:00
|
|
|
=> 'from target directory'
|
|
|
|
);
|
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
make_dir('stow');
|
|
|
|
cd('../..');
|
|
|
|
$stow->set_stow_dir('t/target/stow');
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2011-11-23 18:45:48 -05:00
|
|
|
is_deeply(
|
|
|
|
[ $stow->find_stowed_path('t/target/a/b/c', '../../stow/a/b/c') ],
|
|
|
|
[ 't/target/stow/a/b/c', 't/target/stow', 'a' ]
|
2011-11-16 09:04:03 -05:00
|
|
|
=> 'stow is subdir of target directory'
|
|
|
|
);
|
|
|
|
|
2011-11-23 18:45:48 -05:00
|
|
|
is_deeply(
|
|
|
|
[ $stow->find_stowed_path('t/target/a/b/c','../../empty') ],
|
|
|
|
[ '', '', '' ]
|
2011-11-16 09:04:03 -05:00
|
|
|
=> 'target is not stowed'
|
|
|
|
);
|
|
|
|
|
|
|
|
make_dir('t/target/stow2');
|
|
|
|
make_file('t/target/stow2/.stow');
|
|
|
|
|
2011-11-23 18:45:48 -05:00
|
|
|
is_deeply(
|
|
|
|
[ $stow->find_stowed_path('t/target/a/b/c','../../stow2/a/b/c') ],
|
|
|
|
[ 't/target/stow2/a/b/c', 't/target/stow2', 'a' ]
|
2011-11-16 09:04:03 -05:00
|
|
|
=> q(detect alternate stow directory)
|
|
|
|
);
|
2011-11-24 11:28:09 -05:00
|
|
|
|
|
|
|
# Possible corner case with rogue symlink pointing to ancestor of
|
|
|
|
# stow dir.
|
2011-11-23 18:45:48 -05:00
|
|
|
is_deeply(
|
|
|
|
[ $stow->find_stowed_path('t/target/a/b/c','../../..') ],
|
|
|
|
[ '', '', '' ]
|
2011-11-24 11:28:09 -05:00
|
|
|
=> q(corner case - link points to ancestor of stow dir)
|
|
|
|
);
|