Bump version to 2.1.1
[gnu-stow.git] / t / cleanup_invalid_links.t
blobe6edd9d36f5d59cf679e363185e14736ac079cbc
1 #!/usr/local/bin/perl
4 # Testing cleanup_invalid_links()
7 use strict;
8 use warnings;
10 use Test::More tests => 6;
11 use English qw(-no_match_vars);
13 use testutil;
15 init_test_dirs();
16 cd("$OUT_DIR/target");
18 my $stow;
20 # Note that each of the following tests use a distinct set of files
23 # nothing to clean in a simple tree
27 make_dir('../stow/pkg1/bin1');
28 make_file('../stow/pkg1/bin1/file1');
29 make_link('bin1', '../stow/pkg1/bin1');
31 $stow = new_Stow();
32 $stow->cleanup_invalid_links('./');
33 is(
34 scalar($stow->get_tasks), 0
35 => 'nothing to clean'
39 # cleanup a bad link in a simple tree
41 make_dir('bin2');
42 make_dir('../stow/pkg2/bin2');
43 make_file('../stow/pkg2/bin2/file2a');
44 make_link('bin2/file2a', '../../stow/pkg2/bin2/file2a');
45 make_link('bin2/file2b', '../../stow/pkg2/bin2/file2b');
47 $stow = new_Stow();
48 $stow->cleanup_invalid_links('bin2');
49 is(scalar($stow->get_conflicts), 0, 'no conflicts cleaning up bad link');
50 is(scalar($stow->get_tasks), 1, 'one task cleaning up bad link');
51 is($stow->link_task_action('bin2/file2b'), 'remove', 'removal task for bad link');
54 # dont cleanup a bad link not owned by stow
57 make_dir('bin3');
58 make_dir('../stow/pkg3/bin3');
59 make_file('../stow/pkg3/bin3/file3a');
60 make_link('bin3/file3a', '../../stow/pkg3/bin3/file3a');
61 make_link('bin3/file3b', '../../empty');
63 $stow = new_Stow();
64 $stow->cleanup_invalid_links('bin3');
65 is(scalar($stow->get_conflicts), 0, 'no conflicts cleaning up bad link not owned by stow');
66 is(scalar($stow->get_tasks), 0, 'no tasks cleaning up bad link not owned by stow');