4 # Testing unstow_contents_orig()
10 use Test
::More tests
=> 23;
12 use English
qw(-no_match_vars);
15 use Stow
::Util
qw(canon_path);
17 make_fresh_stow_and_target_dirs
();
20 # Note that each of the following tests use a distinct set of files
26 # unstow a simple tree minimally
29 $stow = new_compat_Stow
();
31 make_dir
('../stow/pkg1/bin1');
32 make_file
('../stow/pkg1/bin1/file1');
33 make_link
('bin1', '../stow/pkg1/bin1');
35 $stow->plan_unstow('pkg1');
36 $stow->process_tasks();
38 scalar($stow->get_conflicts) == 0 &&
39 -f
'../stow/pkg1/bin1/file1' && ! -e
'bin1'
40 => 'unstow a simple tree'
44 # unstow a simple tree from an existing directory
46 $stow = new_compat_Stow
();
49 make_dir
('../stow/pkg2/lib2');
50 make_file
('../stow/pkg2/lib2/file2');
51 make_link
('lib2/file2', '../../stow/pkg2/lib2/file2');
52 $stow->plan_unstow('pkg2');
53 $stow->process_tasks();
55 scalar($stow->get_conflicts) == 0 &&
56 -f
'../stow/pkg2/lib2/file2' && -d
'lib2'
57 => 'unstow simple tree from a pre-existing directory'
61 # fold tree after unstowing
63 $stow = new_compat_Stow
();
67 make_dir
('../stow/pkg3a/bin3');
68 make_file
('../stow/pkg3a/bin3/file3a');
69 make_link
('bin3/file3a' => '../../stow/pkg3a/bin3/file3a'); # emulate stow
71 make_dir
('../stow/pkg3b/bin3');
72 make_file
('../stow/pkg3b/bin3/file3b');
73 make_link
('bin3/file3b' => '../../stow/pkg3b/bin3/file3b'); # emulate stow
74 $stow->plan_unstow('pkg3b');
75 $stow->process_tasks();
77 scalar($stow->get_conflicts) == 0 &&
79 readlink('bin3') eq '../stow/pkg3a/bin3'
80 => 'fold tree after unstowing'
84 # existing link is owned by stow but is invalid so it gets removed anyway
86 $stow = new_compat_Stow
();
89 make_dir
('../stow/pkg4/bin4');
90 make_file
('../stow/pkg4/bin4/file4');
91 make_link
('bin4/file4', '../../stow/pkg4/bin4/does-not-exist');
93 $stow->plan_unstow('pkg4');
94 $stow->process_tasks();
96 scalar($stow->get_conflicts) == 0 &&
98 => q
(remove invalid
link owned by stow
)
102 # Existing link is not owned by stow
104 $stow = new_compat_Stow
();
106 make_dir
('../stow/pkg5/bin5');
107 make_link
('bin5', '../not-stow');
109 $stow->plan_unstow('pkg5');
110 # Unlike the corresponding stow_contents.t test, this doesn't
111 # cause any conflicts.
114 # $Conflicts[-1], qr(CONFLICT:.*can't unlink.*not owned by stow)
115 # => q(existing link not owned by stow)
118 -l
'bin5' && readlink('bin5') eq '../not-stow'
119 => q
(existing
link not owned by stow
)
123 # Target already exists, is owned by stow, but points to a different package
125 $stow = new_compat_Stow
();
128 make_dir
('../stow/pkg6a/bin6');
129 make_file
('../stow/pkg6a/bin6/file6');
130 make_link
('bin6/file6', '../../stow/pkg6a/bin6/file6');
132 make_dir
('../stow/pkg6b/bin6');
133 make_file
('../stow/pkg6b/bin6/file6');
135 $stow->plan_unstow('pkg6b');
137 scalar($stow->get_conflicts) == 0 &&
139 readlink('bin6/file6') eq '../../stow/pkg6a/bin6/file6'
140 => q
(ignore existing
link that points to a different
package)
144 # Don't unlink anything under the stow directory
146 make_dir
('stow'); # make out stow dir a subdir of target
147 $stow = new_compat_Stow
(dir
=> 'stow');
149 # emulate stowing into ourself (bizarre corner case or accident)
150 make_dir
('stow/pkg7a/stow/pkg7b');
151 make_file
('stow/pkg7a/stow/pkg7b/file7b');
152 make_link
('stow/pkg7b', '../stow/pkg7a/stow/pkg7b');
154 $stow->plan_unstow('pkg7b');
156 sub { $stow->process_tasks(); },
157 qr/There are no outstanding operations to perform/,
158 'no tasks to process when unstowing pkg7b'
161 scalar($stow->get_conflicts) == 0 &&
163 readlink('stow/pkg7b') eq '../stow/pkg7a/stow/pkg7b'
164 => q
(don
't unlink any nodes under the stow directory)
168 # Don't
unlink any nodes under another stow directory
170 $stow = new_compat_Stow
(dir
=> 'stow');
172 make_dir
('stow2'); # make our alternate stow dir a subdir of target
173 make_file
('stow2/.stow');
175 # emulate stowing into ourself (bizarre corner case or accident)
176 make_dir
('stow/pkg8a/stow2/pkg8b');
177 make_file
('stow/pkg8a/stow2/pkg8b/file8b');
178 make_link
('stow2/pkg8b', '../stow/pkg8a/stow2/pkg8b');
180 $stow->plan_unstow('pkg8a');
182 sub { $stow->process_tasks(); },
183 qr/There are no outstanding operations to perform/,
184 'no tasks to process when unstowing pkg8a'
187 scalar($stow->get_conflicts) == 0 &&
189 readlink('stow2/pkg8b') eq '../stow/pkg8a/stow2/pkg8b'
190 => q
(don
't unlink any nodes under another stow directory)
194 # overriding already stowed documentation
196 $stow = new_compat_Stow(override => ['man9
', 'info9
']);
197 make_file('stow
/.stow
');
199 make_dir('../stow/pkg
9a
/man9/man
1');
200 make_file('../stow/pkg
9a
/man9/man
1/file9
.1
');
201 make_dir('man9
/man1
');
202 make_link('man9
/man1/file9
.1
' => '../../../stow/pkg
9a
/man9/man
1/file9
.1
'); # emulate stow
204 make_dir('../stow/pkg
9b
/man9/man
1');
205 make_file('../stow/pkg
9b
/man9/man
1/file9
.1
');
206 $stow->plan_unstow('pkg9b
');
207 $stow->process_tasks();
209 scalar($stow->get_conflicts) == 0 &&
210 !-l 'man9
/man1/file9
.1
'
211 => 'overriding existing documentation files
'
215 # deferring to already stowed documentation
217 $stow = new_compat_Stow(defer => ['man10
', 'info10
']);
219 make_dir('../stow/pkg
10a
/man10/man
1');
220 make_file('../stow/pkg
10a
/man10/man
1/file10a
.1');
221 make_dir('man10
/man1
');
222 make_link('man10
/man1/file10a
.1' => '../../../stow/pkg
10a
/man10/man
1/file10a
.1');
224 # need this to block folding
225 make_dir('../stow/pkg
10b
/man10/man
1');
226 make_file('../stow/pkg
10b
/man10/man
1/file10b
.1');
227 make_link('man10
/man1/file10b
.1' => '../../../stow/pkg
10b
/man10/man
1/file10b
.1');
230 make_dir('../stow/pkg
10c
/man10/man
1');
231 make_file('../stow/pkg
10c
/man10/man
1/file10a
.1');
232 $stow->plan_unstow('pkg10c
');
234 sub { $stow->process_tasks(); },
235 qr/There are no outstanding operations to perform/,
236 'no tasks to process
when unstowing pkg10c
'
239 scalar($stow->get_conflicts) == 0 &&
240 readlink('man10
/man1/file10a
.1') eq '../../../stow/pkg
10a
/man10/man
1/file10a
.1'
241 => 'defer to existing documentation files
'
247 $stow = new_compat_Stow(ignore => ['~', '\
.#.*']);
249 make_dir
('../stow/pkg12/man12/man1');
250 make_file
('../stow/pkg12/man12/man1/file12.1');
251 make_file
('../stow/pkg12/man12/man1/file12.1~');
252 make_file
('../stow/pkg12/man12/man1/.#file12.1');
253 make_dir
('man12/man1');
254 make_link
('man12/man1/file12.1' => '../../../stow/pkg12/man12/man1/file12.1');
256 $stow->plan_unstow('pkg12');
257 $stow->process_tasks();
259 scalar($stow->get_conflicts) == 0 &&
260 !-e
'man12/man1/file12.1'
261 => 'ignore temp files'
265 # Unstow an already unstowed package
267 $stow = new_compat_Stow
();
268 $stow->plan_unstow('pkg12');
270 sub { $stow->process_tasks(); },
271 qr/There are no outstanding operations to perform/,
272 'no tasks to process when unstowing pkg12'
275 scalar($stow->get_conflicts) == 0
276 => 'unstow already unstowed package pkg12'
280 # Unstow a never stowed package
283 eval { remove_dir
('t/target'); };
286 $stow = new_compat_Stow
();
287 $stow->plan_unstow('pkg12');
289 sub { $stow->process_tasks(); },
290 qr/There are no outstanding operations to perform/,
291 'no tasks to process when unstowing pkg12 which was never stowed'
294 scalar($stow->get_conflicts) == 0
295 => 'unstow never stowed package pkg12'
299 # Unstowing when target contains a real file shouldn't be an issue.
301 make_file
('man12/man1/file12.1');
303 $stow = new_compat_Stow
();
304 $stow->plan_unstow('pkg12');
306 sub { $stow->process_tasks(); },
307 qr/There are no outstanding operations to perform/,
308 'no tasks to process when unstowing pkg12 for third time'
310 @conflicts = $stow->get_conflicts;
313 $conflicts[0] =~ m!existing target is neither a link nor a directory: man12/man1/file12\.1!
314 => 'unstow pkg12 for third time'
318 # unstow a simple tree minimally when cwd isn't target
321 $stow = new_Stow
(dir
=> 't/stow', target
=> 't/target');
323 make_dir
('t/stow/pkg13/bin13');
324 make_file
('t/stow/pkg13/bin13/file13');
325 make_link
('t/target/bin13', '../stow/pkg13/bin13');
327 $stow->plan_unstow('pkg13');
328 $stow->process_tasks();
330 scalar($stow->get_conflicts) == 0 &&
331 -f
't/stow/pkg13/bin13/file13' && ! -e
't/target/bin13'
332 => 'unstow a simple tree'
336 # unstow a simple tree minimally with absolute stow dir when cwd isn't
339 $stow = new_Stow
(dir
=> canon_path
('t/stow'),
340 target
=> 't/target');
342 make_dir
('t/stow/pkg14/bin14');
343 make_file
('t/stow/pkg14/bin14/file14');
344 make_link
('t/target/bin14', '../stow/pkg14/bin14');
346 $stow->plan_unstow('pkg14');
347 $stow->process_tasks();
349 scalar($stow->get_conflicts) == 0 &&
350 -f
't/stow/pkg14/bin14/file14' && ! -e
't/target/bin14'
351 => 'unstow a simple tree with absolute stow dir'
355 # unstow a simple tree minimally with absolute stow AND target dirs
356 # when cwd isn't target
358 $stow = new_Stow
(dir
=> canon_path
('t/stow'),
359 target
=> canon_path
('t/target'));
361 make_dir
('t/stow/pkg15/bin15');
362 make_file
('t/stow/pkg15/bin15/file15');
363 make_link
('t/target/bin15', '../stow/pkg15/bin15');
365 $stow->plan_unstow('pkg15');
366 $stow->process_tasks();
368 scalar($stow->get_conflicts) == 0 &&
369 -f
't/stow/pkg15/bin15/file15' && ! -e
't/target/bin15'
370 => 'unstow a simple tree with absolute stow and target dirs'
376 # Test cleaning up subdirs with --paranoid option