From ed12c787df985896c8ba1c188af45b9fb637b017 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Sat, 18 Feb 2012 20:13:32 +0000 Subject: Add --no-folding option. --- t/stow.t | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- t/testutil.pm | 37 ++++++++++++++++++++ t/unstow.t | 85 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 223 insertions(+), 7 deletions(-) (limited to 't') diff --git a/t/stow.t b/t/stow.t index 0786d18..ccad54d 100755 --- a/t/stow.t +++ b/t/stow.t @@ -7,7 +7,7 @@ use strict; use warnings; -use Test::More tests => 35; +use Test::More tests => 111; use Test::Output; use English qw(-no_match_vars); @@ -32,7 +32,7 @@ make_file('../stow/pkg1/bin1/file1'); $stow->plan_stow('pkg1'); $stow->process_tasks(); -is($stow->get_conflicts(), 0, 'no conflicts with minimal stow'); +is_deeply([ $stow->get_conflicts ], [], 'no conflicts with minimal stow'); is( readlink('bin1'), '../stow/pkg1/bin1', @@ -387,7 +387,7 @@ make_file("$OUT_DIR/stow/pkg16/bin16/file16"); $stow->plan_stow('pkg16'); $stow->process_tasks(); -is($stow->get_conflicts(), 0, 'no conflicts with minimal stow'); +is_deeply([ $stow->get_conflicts ], [], 'no conflicts with minimal stow'); is( readlink("$OUT_DIR/target/bin16"), '../stow/pkg16/bin16', @@ -406,7 +406,7 @@ make_file("$OUT_DIR/stow/pkg17/bin17/file17"); $stow->plan_stow('pkg17'); $stow->process_tasks(); -is($stow->get_conflicts(), 0, 'no conflicts with minimal stow'); +is_deeply([ $stow->get_conflicts ], [], 'no conflicts with minimal stow'); is( readlink("$OUT_DIR/target/bin17"), '../stow/pkg17/bin17', @@ -425,10 +425,108 @@ make_file("$OUT_DIR/stow/pkg18/bin18/file18"); $stow->plan_stow('pkg18'); $stow->process_tasks(); -is($stow->get_conflicts(), 0, 'no conflicts with minimal stow'); +is_deeply([ $stow->get_conflicts ], [], 'no conflicts with minimal stow'); is( readlink("$OUT_DIR/target/bin18"), '../stow/pkg18/bin18', => "minimal stow of a simple tree with absolute stow and target dirs" ); +# +# stow a tree with no-folding enabled - +# no new folded directories should be created, and existing +# folded directories should be split open (unfolded) where +# (and only where) necessary +# +cd("$OUT_DIR/target"); + +sub create_pkg { + my ($id, $pkg) = @_; + + my $stow_pkg = "../stow/$id-$pkg"; + make_dir ($stow_pkg); + make_file("$stow_pkg/$id-file-$pkg"); + + # create a shallow hierarchy specific to this package which isn't + # yet stowed + make_dir ("$stow_pkg/$id-$pkg-only-new"); + make_file("$stow_pkg/$id-$pkg-only-new/$id-file-$pkg"); + + # create a deeper hierarchy specific to this package which isn't + # yet stowed + make_dir ("$stow_pkg/$id-$pkg-only-new2/subdir"); + make_file("$stow_pkg/$id-$pkg-only-new2/subdir/$id-file-$pkg"); + + # create a hierarchy specific to this package which is already + # stowed via a folded tree + make_dir ("$stow_pkg/$id-$pkg-only-old"); + make_link("$id-$pkg-only-old", "$stow_pkg/$id-$pkg-only-old"); + make_file("$stow_pkg/$id-$pkg-only-old/$id-file-$pkg"); + + # create a shared hierarchy which this package uses + make_dir ("$stow_pkg/$id-shared"); + make_file("$stow_pkg/$id-shared/$id-file-$pkg"); + + # create a partially shared hierarchy which this package uses + make_dir ("$stow_pkg/$id-shared2/subdir-$pkg"); + make_file("$stow_pkg/$id-shared2/$id-file-$pkg"); + make_file("$stow_pkg/$id-shared2/subdir-$pkg/$id-file-$pkg"); +} + +foreach my $pkg (qw{a b}) { + create_pkg('no-folding', $pkg); +} + +$stow = new_Stow('no-folding' => 1); +$stow->plan_stow('no-folding-a'); +is_deeply([ $stow->get_conflicts ], [] => 'no conflicts with --no-folding'); +my @tasks = $stow->get_tasks; +use Data::Dumper; +is(scalar(@tasks), 12 => "6 dirs, 6 links") || warn Dumper(\@tasks); +$stow->process_tasks(); + +sub check_no_folding { + my ($pkg) = @_; + my $stow_pkg = "../stow/no-folding-$pkg"; + is_link("no-folding-file-$pkg", "$stow_pkg/no-folding-file-$pkg"); + + # check existing folded tree is untouched + is_link("no-folding-$pkg-only-old", "$stow_pkg/no-folding-$pkg-only-old"); + + # check newly stowed shallow tree is not folded + is_dir_not_symlink("no-folding-$pkg-only-new"); + is_link("no-folding-$pkg-only-new/no-folding-file-$pkg", + "../$stow_pkg/no-folding-$pkg-only-new/no-folding-file-$pkg"); + + # check newly stowed deeper tree is not folded + is_dir_not_symlink("no-folding-$pkg-only-new2"); + is_dir_not_symlink("no-folding-$pkg-only-new2/subdir"); + is_link("no-folding-$pkg-only-new2/subdir/no-folding-file-$pkg", + "../../$stow_pkg/no-folding-$pkg-only-new2/subdir/no-folding-file-$pkg"); + + # check shared tree is not folded. first time round this will be + # newly stowed. + is_dir_not_symlink('no-folding-shared'); + is_link("no-folding-shared/no-folding-file-$pkg", + "../$stow_pkg/no-folding-shared/no-folding-file-$pkg"); + + # check partially shared tree is not folded. first time round this + # will be newly stowed. + is_dir_not_symlink('no-folding-shared2'); + is_link("no-folding-shared2/no-folding-file-$pkg", + "../$stow_pkg/no-folding-shared2/no-folding-file-$pkg"); + is_link("no-folding-shared2/no-folding-file-$pkg", + "../$stow_pkg/no-folding-shared2/no-folding-file-$pkg"); +} + +check_no_folding('a'); + +$stow = new_Stow('no-folding' => 1); +$stow->plan_stow('no-folding-b'); +is_deeply([ $stow->get_conflicts ], [] => 'no conflicts with --no-folding'); +@tasks = $stow->get_tasks; +is(scalar(@tasks), 10 => '4 dirs, 6 links') || warn Dumper(\@tasks); +$stow->process_tasks(); + +check_no_folding('a'); +check_no_folding('b'); diff --git a/t/testutil.pm b/t/testutil.pm index 9e4573b..b9359be 100755 --- a/t/testutil.pm +++ b/t/testutil.pm @@ -13,6 +13,7 @@ use Carp qw(croak); use File::Basename; use File::Path qw(remove_tree); use File::Spec; +use Test::More; use Stow; use Stow::Util qw(parent canon_path); @@ -26,6 +27,7 @@ our @EXPORT = qw( make_dir make_link make_invalid_link make_file remove_dir remove_link cat_file + is_link is_dir_not_symlink is_nonexistent_path ); our $OUT_DIR = 'tmp-testing-trees'; @@ -254,6 +256,41 @@ sub cat_file { return $contents; } +#===== SUBROUTINE =========================================================== +# Name : is_link() +# Purpose : assert path is a symlink +# Parameters: $path => path to check +# : $dest => target symlink should point to +#============================================================================ +sub is_link { + my ($path, $dest) = @_; + ok(-l $path => "$path should be symlink"); + is(readlink $path, $dest => "$path symlinks to $dest"); +} + +#===== SUBROUTINE =========================================================== +# Name : is_dir_not_symlink() +# Purpose : assert path is a directory not a symlink +# Parameters: $path => path to check +#============================================================================ +sub is_dir_not_symlink { + my ($path) = @_; + ok(! -l $path => "$path should not be symlink"); + ok(-d _ => "$path should be a directory"); +} + +#===== SUBROUTINE =========================================================== +# Name : is_nonexistent_path() +# Purpose : assert path does not exist +# Parameters: $path => path to check +#============================================================================ +sub is_nonexistent_path { + my ($path) = @_; + ok(! -l $path => "$path should not be symlink"); + ok(! -e _ => "$path should not exist"); +} + + 1; # Local variables: diff --git a/t/unstow.t b/t/unstow.t index bf46bfa..d166107 100755 --- a/t/unstow.t +++ b/t/unstow.t @@ -7,7 +7,7 @@ use strict; use warnings; -use Test::More tests => 23; +use Test::More tests => 38; use Test::Output; use English qw(-no_match_vars); @@ -341,8 +341,89 @@ ok( => 'unstow a simple tree with absolute stow and target dirs' ); +# +# unstow a tree with no-folding enabled - +# no refolding should take place +# +cd("$OUT_DIR/target"); + +sub create_and_stow_pkg { + my ($id, $pkg) = @_; + + my $stow_pkg = "../stow/$id-$pkg"; + make_dir ($stow_pkg); + make_file("$stow_pkg/$id-file-$pkg"); + + # create a shallow hierarchy specific to this package and stow + # via folding + make_dir ("$stow_pkg/$id-$pkg-only-folded"); + make_file("$stow_pkg/$id-$pkg-only-folded/file-$pkg"); + make_link("$id-$pkg-only-folded", "$stow_pkg/$id-$pkg-only-folded"); + + # create a deeper hierarchy specific to this package and stow + # via folding + make_dir ("$stow_pkg/$id-$pkg-only-folded2/subdir"); + make_file("$stow_pkg/$id-$pkg-only-folded2/subdir/file-$pkg"); + make_link("$id-$pkg-only-folded2", + "$stow_pkg/$id-$pkg-only-folded2"); + + # create a shallow hierarchy specific to this package and stow + # without folding + make_dir ("$stow_pkg/$id-$pkg-only-unfolded"); + make_file("$stow_pkg/$id-$pkg-only-unfolded/file-$pkg"); + make_dir ("$id-$pkg-only-unfolded"); + make_link("$id-$pkg-only-unfolded/file-$pkg", + "../$stow_pkg/$id-$pkg-only-unfolded/file-$pkg"); + + # create a deeper hierarchy specific to this package and stow + # without folding + make_dir ("$stow_pkg/$id-$pkg-only-unfolded2/subdir"); + make_file("$stow_pkg/$id-$pkg-only-unfolded2/subdir/file-$pkg"); + make_dir ("$id-$pkg-only-unfolded2/subdir"); + make_link("$id-$pkg-only-unfolded2/subdir/file-$pkg", + "../../$stow_pkg/$id-$pkg-only-unfolded2/subdir/file-$pkg"); + + # create a shallow shared hierarchy which this package uses, and stow + # its contents without folding + make_dir ("$stow_pkg/$id-shared"); + make_file("$stow_pkg/$id-shared/file-$pkg"); + make_dir ("$id-shared"); + make_link("$id-shared/file-$pkg", + "../$stow_pkg/$id-shared/file-$pkg"); + + # create a deeper shared hierarchy which this package uses, and stow + # its contents without folding + make_dir ("$stow_pkg/$id-shared2/subdir"); + make_file("$stow_pkg/$id-shared2/file-$pkg"); + make_file("$stow_pkg/$id-shared2/subdir/file-$pkg"); + make_dir ("$id-shared2/subdir"); + make_link("$id-shared2/file-$pkg", + "../$stow_pkg/$id-shared2/file-$pkg"); + make_link("$id-shared2/subdir/file-$pkg", + "../../$stow_pkg/$id-shared2/subdir/file-$pkg"); +} + +foreach my $pkg (qw{a b}) { + create_and_stow_pkg('no-folding', $pkg); +} + +$stow = new_Stow('no-folding' => 1); +$stow->plan_unstow('no-folding-b'); +is_deeply([ $stow->get_conflicts ], [] => 'no conflicts with --no-folding'); +use Data::Dumper; +#warn Dumper($stow->get_tasks); + +$stow->process_tasks(); + +is_nonexistent_path('no-folding-b-only-folded'); +is_nonexistent_path('no-folding-b-only-folded2'); +is_nonexistent_path('no-folding-b-only-unfolded/file-b'); +is_nonexistent_path('no-folding-b-only-unfolded2/subdir/file-b'); +is_dir_not_symlink('no-folding-shared'); +is_dir_not_symlink('no-folding-shared2'); +is_dir_not_symlink('no-folding-shared2/subdir'); + # Todo # # Test cleaning up subdirs with --paranoid option - -- cgit v1.2.1