4 # Testing unstow_contents()
8 BEGIN { use lib
qw(.); require "t/util.pm"; require "stow"; }
10 use Test
::More tests
=> 14;
12 use English
qw(-no_match_vars);
25 eval { remove_dir
('t/target'); };
26 eval { remove_dir
('t/stow'); };
31 $Stow_Path= '../stow';
33 # Note that each of the following tests use a distinct set of files
36 # unstow a simple tree minimally
40 $Option{'verbose'} = 0;
42 make_dir
('../stow/pkg1/bin1');
43 make_file
('../stow/pkg1/bin1/file1');
44 make_link
('bin1','../stow/pkg1/bin1');
46 unstow_contents
('../stow/pkg1','./');
49 scalar(@Conflicts) == 0 &&
50 -f
'../stow/pkg1/bin1/file1' && ! -e
'bin1'
51 => 'unstow a simple tree'
55 # unstow a simple tree from an existing directory
58 $Option{'verbose'} = 0;
61 make_dir
('../stow/pkg2/lib2');
62 make_file
('../stow/pkg2/lib2/file2');
63 make_link
('lib2/file2', '../../stow/pkg2/lib2/file2');
64 unstow_contents
('../stow/pkg2','./');
67 scalar(@Conflicts) == 0 &&
68 -f
'../stow/pkg2/lib2/file2' && -d
'lib2'
69 => 'unstow simple tree from a pre-existing directory'
73 # fold tree after unstowing
76 $Option{'verbose'} = 0;
80 make_dir
('../stow/pkg3a/bin3');
81 make_file
('../stow/pkg3a/bin3/file3a');
82 make_link
('bin3/file3a' => '../../stow/pkg3a/bin3/file3a'); # emulate stow
84 make_dir
('../stow/pkg3b/bin3');
85 make_file
('../stow/pkg3b/bin3/file3b');
86 make_link
('bin3/file3b' => '../../stow/pkg3b/bin3/file3b'); # emulate stow
87 unstow_contents
('../stow/pkg3b', './');
90 scalar(@Conflicts) == 0 &&
92 readlink('bin3') eq '../stow/pkg3a/bin3'
93 => 'fold tree after unstowing'
97 # existing link is owned by stow but is invalid so it gets removed anyway
100 $Option{'verbose'} = 0;
103 make_dir
('../stow/pkg4/bin4');
104 make_file
('../stow/pkg4/bin4/file4');
105 make_link
('bin4/file4', '../../stow/pkg4/bin4/does-not-exist');
107 unstow_contents
('../stow/pkg4', './');
110 scalar(@Conflicts) == 0 &&
112 => q
(remove invalid
link owned by stow
)
116 # Existing link is not owned by stow
119 $Option{'verbose'} = 0;
121 make_dir
('../stow/pkg5/bin5');
122 make_link
('bin5', '../not-stow');
124 unstow_contents
('../stow/pkg5', './');
126 $Conflicts[-1], qr
(CONFLICT
:.*existing target is
not owned by stow
)
127 => q
(existing
link not owned by stow
)
130 # Target already exists, is owned by stow, but points to a different package
133 $Option{'verbose'} = 0;
136 make_dir
('../stow/pkg6a/bin6');
137 make_file
('../stow/pkg6a/bin6/file6');
138 make_link
('bin6/file6', '../../stow/pkg6a/bin6/file6');
140 make_dir
('../stow/pkg6b/bin6');
141 make_file
('../stow/pkg6b/bin6/file6');
143 unstow_contents
('../stow/pkg6b', './');
145 scalar(@Conflicts) == 0 &&
147 readlink('bin6/file6') eq '../../stow/pkg6a/bin6/file6'
148 => q
(ignore existing
link that points to a different
package)
152 # Don't unlink anything under the stow directory
155 $Option{'verbose'} = 0;
157 make_dir
('stow'); # make out stow dir a subdir of target
160 # emulate stowing into ourself (bizarre corner case or accident)
161 make_dir
('stow/pkg7a/stow/pkg7b');
162 make_file
('stow/pkg7a/stow/pkg7b/file7b');
163 make_link
('stow/pkg7b', '../stow/pkg7a/stow/pkg7b');
165 unstow_contents
('stow/pkg7b', './');
167 sub { process_tasks
(); },
168 qr/There are no outstanding operations to perform/,
169 'no tasks to process when unstowing pkg7b'
172 scalar(@Conflicts) == 0 &&
174 readlink('stow/pkg7b') eq '../stow/pkg7a/stow/pkg7b'
175 => q
(don
't unlink any nodes under the stow directory)
179 # Don't
unlink any nodes under another stow directory
182 $Option{'verbose'} = 0;
184 make_dir
('stow'); # make out stow dir a subdir of target
187 make_dir
('stow2'); # make our alternate stow dir a subdir of target
188 make_file
('stow2/.stow');
190 # emulate stowing into ourself (bizarre corner case or accident)
191 make_dir
('stow/pkg8a/stow2/pkg8b');
192 make_file
('stow/pkg8a/stow2/pkg8b/file8b');
193 make_link
('stow2/pkg8b', '../stow/pkg8a/stow2/pkg8b');
195 unstow_contents
('stow/pkg8a', './');
197 sub { process_tasks
(); },
198 qr/There are no outstanding operations to perform/,
199 'no tasks to process when unstowing pkg8a'
202 scalar(@Conflicts) == 0 &&
204 readlink('stow2/pkg8b') eq '../stow/pkg8a/stow2/pkg8b'
205 => q
(don
't unlink any nodes under another stow directory)
209 # overriding already stowed documentation
212 $Stow_Path = '../stow
';
213 $Option{'verbose
'} = 0;
214 $Option{'override
'} = ['man9
', 'info9
'];
216 make_dir('../stow/pkg
9a
/man9/man
1');
217 make_file('../stow/pkg
9a
/man9/man
1/file9
.1
');
218 make_dir('man9
/man1
');
219 make_link('man9
/man1/file9
.1
' => '../../../stow/pkg
9a
/man9/man
1/file9
.1
'); # emulate stow
221 make_dir('../stow/pkg
9b
/man9/man
1');
222 make_file('../stow/pkg
9b
/man9/man
1/file9
.1
');
223 unstow_contents('../stow/pkg
9b
', './');
226 scalar(@Conflicts) == 0 &&
227 !-l 'man9
/man1/file9
.1
'
228 => 'overriding existing documentation files
'
232 # deferring to already stowed documentation
235 $Option{'verbose
'} = 0;
236 $Option{'defer
'} = ['man10
', 'info10
'];
238 make_dir('../stow/pkg
10a
/man10/man
1');
239 make_file('../stow/pkg
10a
/man10/man
1/file10a
.1');
240 make_dir('man10
/man1
');
241 make_link('man10
/man1/file10a
.1' => '../../../stow/pkg
10a
/man10/man
1/file10a
.1');
243 # need this to block folding
244 make_dir('../stow/pkg
10b
/man10/man
1');
245 make_file('../stow/pkg
10b
/man10/man
1/file10b
.1');
246 make_link('man10
/man1/file10b
.1' => '../../../stow/pkg
10b
/man10/man
1/file10b
.1');
249 make_dir('../stow/pkg
10c
/man10/man
1');
250 make_file('../stow/pkg
10c
/man10/man
1/file10a
.1');
251 unstow_contents('../stow/pkg
10c
', './');
253 sub { process_tasks(); },
254 qr/There are no outstanding operations to perform/,
255 'no tasks to process
when unstowing pkg10c
'
258 scalar(@Conflicts) == 0 &&
259 readlink('man10
/man1/file10a
.1') eq '../../../stow/pkg
10a
/man10/man
1/file10a
.1'
260 => 'defer to existing documentation files
'
267 $Option{'verbose
'} = 0;
268 $Option{'ignore
'} = ['~', '\
.#.*'];
270 make_dir
('../stow/pkg12/man12/man1');
271 make_file
('../stow/pkg12/man12/man1/file12.1');
272 make_file
('../stow/pkg12/man12/man1/file12.1~');
273 make_file
('../stow/pkg12/man12/man1/.#file12.1');
274 make_dir
('man12/man1');
275 make_link
('man12/man1/file12.1' => '../../../stow/pkg12/man12/man1/file12.1');
277 unstow_contents
('../stow/pkg12', './');
280 scalar(@Conflicts) == 0 &&
281 !-e
'man12/man1/file12.1'
282 => 'ignore temp files'
288 # Test cleaning up subdirs with --paranoid option