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
|
|
|
|
2011-11-24 11:32:01 -05:00
|
|
|
my $stow = new_Stow(dir => "$OUT_DIR/stow");
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2011-11-23 18:45:48 -05:00
|
|
|
is_deeply(
|
2011-11-24 11:32:01 -05:00
|
|
|
[ $stow->find_stowed_path("$OUT_DIR/target/a/b/c", '../../../stow/a/b/c') ],
|
|
|
|
[ "$OUT_DIR/stow/a/b/c", "$OUT_DIR/stow", 'a' ]
|
2011-11-16 09:04:03 -05:00
|
|
|
=> 'from root'
|
|
|
|
);
|
|
|
|
|
2011-11-24 11:32:01 -05:00
|
|
|
cd("$OUT_DIR/target");
|
2011-11-24 11:28:09 -05:00
|
|
|
$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('../..');
|
2011-11-24 11:32:01 -05:00
|
|
|
$stow->set_stow_dir("$OUT_DIR/target/stow");
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2011-11-23 18:45:48 -05:00
|
|
|
is_deeply(
|
2011-11-24 11:32:01 -05:00
|
|
|
[ $stow->find_stowed_path("$OUT_DIR/target/a/b/c", '../../stow/a/b/c') ],
|
|
|
|
[ "$OUT_DIR/target/stow/a/b/c", "$OUT_DIR/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(
|
2011-11-24 11:32:01 -05:00
|
|
|
[ $stow->find_stowed_path("$OUT_DIR/target/a/b/c",'../../empty') ],
|
2011-11-23 18:45:48 -05:00
|
|
|
[ '', '', '' ]
|
2011-11-16 09:04:03 -05:00
|
|
|
=> 'target is not stowed'
|
|
|
|
);
|
|
|
|
|
2011-11-24 11:32:01 -05:00
|
|
|
make_dir("$OUT_DIR/target/stow2");
|
|
|
|
make_file("$OUT_DIR/target/stow2/.stow");
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2011-11-23 18:45:48 -05:00
|
|
|
is_deeply(
|
2011-11-24 11:32:01 -05:00
|
|
|
[ $stow->find_stowed_path("$OUT_DIR/target/a/b/c",'../../stow2/a/b/c') ],
|
|
|
|
[ "$OUT_DIR/target/stow2/a/b/c", "$OUT_DIR/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(
|
2011-11-24 11:32:01 -05:00
|
|
|
[ $stow->find_stowed_path("$OUT_DIR/target/a/b/c",'../../..') ],
|
2011-11-23 18:45:48 -05:00
|
|
|
[ '', '', '' ]
|
2011-11-24 11:28:09 -05:00
|
|
|
=> q(corner case - link points to ancestor of stow dir)
|
|
|
|
);
|