foldable: add debug for different cases when not foldable
[gnu-stow.git] / t / examples.t
blob376de3975f4796ead5b6e8a8eddc1ac565b275fa
1 #!/usr/bin/perl
3 # This file is part of GNU Stow.
5 # GNU Stow is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # GNU Stow is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see https://www.gnu.org/licenses/.
19 # Testing examples from the documentation
22 use strict;
23 use warnings;
25 use testutil;
27 use Test::More tests => 10;
28 use English qw(-no_match_vars);
30 init_test_dirs();
31 cd("$TEST_DIR/target");
33 my $stow;
35 ## set up some fake packages to stow
37 # perl
38 make_path('stow/perl/bin');
39 make_file('stow/perl/bin/perl');
40 make_file('stow/perl/bin/a2p');
41 make_path('stow/perl/info');
42 make_file('stow/perl/info/perl');
43 make_path('stow/perl/lib/perl');
44 make_path('stow/perl/man/man1');
45 make_file('stow/perl/man/man1/perl.1');
47 # emacs
48 make_path('stow/emacs/bin');
49 make_file('stow/emacs/bin/emacs');
50 make_file('stow/emacs/bin/etags');
51 make_path('stow/emacs/info');
52 make_file('stow/emacs/info/emacs');
53 make_path('stow/emacs/libexec/emacs');
54 make_path('stow/emacs/man/man1');
55 make_file('stow/emacs/man/man1/emacs.1');
58 # stow perl into an empty target
61 $stow = new_Stow(dir => 'stow');
62 $stow->plan_stow('perl');
63 $stow->process_tasks();
64 ok(
65 $stow->get_conflict_count == 0 &&
66 -l 'bin' && -l 'info' && -l 'lib' && -l 'man' &&
67 readlink('bin') eq 'stow/perl/bin' &&
68 readlink('info') eq 'stow/perl/info' &&
69 readlink('lib') eq 'stow/perl/lib' &&
70 readlink('man') eq 'stow/perl/man'
71 => 'stow perl into an empty target'
75 # stow perl into a non-empty target
78 # clean up previous stow
79 remove_link('bin');
80 remove_link('info');
81 remove_link('lib');
82 remove_link('man');
84 make_path('bin');
85 make_path('lib');
86 make_path('man/man1');
88 $stow = new_Stow(dir => 'stow');
89 $stow->plan_stow('perl');
90 $stow->process_tasks();
91 ok(
92 $stow->get_conflict_count == 0 &&
93 -d 'bin' && -d 'lib' && -d 'man' && -d 'man/man1' &&
94 -l 'info' && -l 'bin/perl' && -l 'bin/a2p' &&
95 -l 'lib/perl' && -l 'man/man1/perl.1' &&
96 readlink('info') eq 'stow/perl/info' &&
97 readlink('bin/perl') eq '../stow/perl/bin/perl' &&
98 readlink('bin/a2p') eq '../stow/perl/bin/a2p' &&
99 readlink('lib/perl') eq '../stow/perl/lib/perl' &&
100 readlink('man/man1/perl.1') eq '../../stow/perl/man/man1/perl.1'
101 => 'stow perl into a non-empty target'
106 # Install perl into an empty target and then install emacs
109 # clean up previous stow
110 remove_link('info');
111 remove_dir('bin');
112 remove_dir('lib');
113 remove_dir('man');
115 $stow = new_Stow(dir => 'stow');
116 $stow->plan_stow('perl', 'emacs');
117 $stow->process_tasks();
118 is($stow->get_conflict_count, 0, 'no conflicts');
120 -d 'bin' &&
121 -l 'bin/perl' &&
122 -l 'bin/emacs' &&
123 -l 'bin/a2p' &&
124 -l 'bin/etags' &&
125 readlink('bin/perl') eq '../stow/perl/bin/perl' &&
126 readlink('bin/a2p') eq '../stow/perl/bin/a2p' &&
127 readlink('bin/emacs') eq '../stow/emacs/bin/emacs' &&
128 readlink('bin/etags') eq '../stow/emacs/bin/etags' &&
130 -d 'info' &&
131 -l 'info/perl' &&
132 -l 'info/emacs' &&
133 readlink('info/perl') eq '../stow/perl/info/perl' &&
134 readlink('info/emacs') eq '../stow/emacs/info/emacs' &&
136 -d 'man' &&
137 -d 'man/man1' &&
138 -l 'man/man1/perl.1' &&
139 -l 'man/man1/emacs.1' &&
140 readlink('man/man1/perl.1') eq '../../stow/perl/man/man1/perl.1' &&
141 readlink('man/man1/emacs.1') eq '../../stow/emacs/man/man1/emacs.1' &&
143 -l 'lib' &&
144 -l 'libexec' &&
145 readlink('lib') eq 'stow/perl/lib' &&
146 readlink('libexec') eq 'stow/emacs/libexec' &&
148 => 'stow perl into an empty target, then stow emacs'
152 # BUG 1:
153 # 1. stowing a package with an empty directory
154 # 2. stow another package with the same directory but non empty
155 # 3. unstow the second package
156 # Q. the original empty directory should remain
157 # behaviour is the same as if the empty directory had nothing to do with stow
160 make_path('stow/pkg1a/bin1');
161 make_path('stow/pkg1b/bin1');
162 make_file('stow/pkg1b/bin1/file1b');
164 $stow = new_Stow(dir => 'stow');
165 $stow->plan_stow('pkg1a', 'pkg1b');
166 $stow->plan_unstow('pkg1b');
167 $stow->process_tasks();
168 is($stow->get_conflict_count, 0, 'no conflicts stowing empty dirs');
169 ok(-d 'bin1' => 'bug 1: stowing empty dirs');
172 # BUG 2: split open tree-folding symlinks pointing inside different stow
173 # directories
175 make_path('stow2a/pkg2a/bin2');
176 make_file('stow2a/pkg2a/bin2/file2a');
177 make_file('stow2a/.stow');
178 make_path('stow2b/pkg2b/bin2');
179 make_file('stow2b/pkg2b/bin2/file2b');
180 make_file('stow2b/.stow');
182 $stow = new_Stow(dir => 'stow2a');
183 $stow->plan_stow('pkg2a');
184 $stow->set_stow_dir('stow2b');
185 $stow->plan_stow('pkg2b');
186 $stow->process_tasks();
188 is($stow->get_conflict_count, 0, 'no conflicts splitting tree-folding symlinks');
189 ok(-d 'bin2' => 'tree got split by packages from multiple stow directories');
190 ok(-f 'bin2/file2a' => 'file from 1st stow dir');
191 ok(-f 'bin2/file2b' => 'file from 2nd stow dir');
193 ## Finish this test