Use File::Spec->abs2rel() instead of home-grown relative_path
[gnu-stow.git] / t / examples.t
blobec90cef5bb27771f379ccfd52a6737dcffb954fb
1 #!/usr/local/bin/perl
4 # Testing examples from the documentation
7 # load as a library
8 BEGIN { use lib qw(.); require "t/util.pm"; require "stow"; }
10 use Test::More tests => 4;
11 use English qw(-no_match_vars);
13 # local utility
14 sub reset_state {
15 @Tasks = ();
16 @Conflicts = ();
17 %Link_Task_For = ();
18 %Dir_Task_For = ();
19 %Option = ();
20 return;
23 ### setup
24 eval { remove_dir('t/target'); };
25 make_dir('t/target/stow');
27 chdir 't/target';
28 $Stow_Path= 'stow';
30 ## set up some fake packages to stow
32 # perl
33 make_dir('stow/perl/bin');
34 make_file('stow/perl/bin/perl');
35 make_file('stow/perl/bin/a2p');
36 make_dir('stow/perl/info');
37 make_file('stow/perl/info/perl');
38 make_dir('stow/perl/lib/perl');
39 make_dir('stow/perl/man/man1');
40 make_file('stow/perl/man/man1/perl.1');
42 # emacs
43 make_dir('stow/emacs/bin');
44 make_file('stow/emacs/bin/emacs');
45 make_file('stow/emacs/bin/etags');
46 make_dir('stow/emacs/info');
47 make_file('stow/emacs/info/emacs');
48 make_dir('stow/emacs/libexec/emacs');
49 make_dir('stow/emacs/man/man1');
50 make_file('stow/emacs/man/man1/emacs.1');
53 # stow perl into an empty target
55 reset_state();
56 $Option{'verbose'} = 0;
58 make_dir('stow/perl/bin');
59 make_file('stow/perl/bin/perl');
60 make_file('stow/perl/bin/a2p');
61 make_dir('stow/perl/info');
62 make_dir('stow/perl/lib/perl');
63 make_dir('stow/perl/man/man1');
64 make_file('stow/perl/man/man1/perl.1');
66 stow_contents('stow/perl','./','stow/perl');
67 process_tasks();
68 ok(
69 scalar(@Conflicts) == 0 &&
70 -l 'bin' && -l 'info' && -l 'lib' && -l 'man' &&
71 readlink('bin') eq 'stow/perl/bin' &&
72 readlink('info') eq 'stow/perl/info' &&
73 readlink('lib') eq 'stow/perl/lib' &&
74 readlink('man') eq 'stow/perl/man'
75 => 'stow perl into an empty target'
80 # stow perl into a non-empty target
82 reset_state();
83 $Option{'verbose'} = 0;
85 # clean up previous stow
86 remove_link('bin');
87 remove_link('info');
88 remove_link('lib');
89 remove_link('man');
91 make_dir('bin');
92 make_dir('lib');
93 make_dir('man/man1');
95 stow_contents('stow/perl','./','stow/perl');
96 process_tasks();
97 ok(
98 scalar(@Conflicts) == 0 &&
99 -d 'bin' && -d 'lib' && -d 'man' && -d 'man/man1' &&
100 -l 'info' && -l 'bin/perl' && -l 'bin/a2p' &&
101 -l 'lib/perl' && -l 'man/man1/perl.1' &&
102 readlink('info') eq 'stow/perl/info' &&
103 readlink('bin/perl') eq '../stow/perl/bin/perl' &&
104 readlink('bin/a2p') eq '../stow/perl/bin/a2p' &&
105 readlink('lib/perl') eq '../stow/perl/lib/perl' &&
106 readlink('man/man1/perl.1') eq '../../stow/perl/man/man1/perl.1'
107 => 'stow perl into a non-empty target'
112 # Install perl into an empty target and then install emacs
114 reset_state();
115 $Option{'verbose'} = 0;
117 # clean up previous stow
118 remove_link('info');
119 remove_dir('bin');
120 remove_dir('lib');
121 remove_dir('man');
123 stow_contents('stow/perl', './','stow/perl');
124 stow_contents('stow/emacs','./','stow/emacs');
125 process_tasks();
127 scalar(@Conflicts) == 0 &&
128 -d 'bin' &&
129 -l 'bin/perl' &&
130 -l 'bin/emacs' &&
131 -l 'bin/a2p' &&
132 -l 'bin/etags' &&
133 readlink('bin/perl') eq '../stow/perl/bin/perl' &&
134 readlink('bin/a2p') eq '../stow/perl/bin/a2p' &&
135 readlink('bin/emacs') eq '../stow/emacs/bin/emacs' &&
136 readlink('bin/etags') eq '../stow/emacs/bin/etags' &&
138 -d 'info' &&
139 -l 'info/perl' &&
140 -l 'info/emacs' &&
141 readlink('info/perl') eq '../stow/perl/info/perl' &&
142 readlink('info/emacs') eq '../stow/emacs/info/emacs' &&
144 -d 'man' &&
145 -d 'man/man1' &&
146 -l 'man/man1/perl.1' &&
147 -l 'man/man1/emacs.1' &&
148 readlink('man/man1/perl.1') eq '../../stow/perl/man/man1/perl.1' &&
149 readlink('man/man1/emacs.1') eq '../../stow/emacs/man/man1/emacs.1' &&
151 -l 'lib' &&
152 -l 'libexec' &&
153 readlink('lib') eq 'stow/perl/lib' &&
154 readlink('libexec') eq 'stow/emacs/libexec' &&
156 => 'stow perl into an empty target, then stow emacs'
160 # BUG 1:
161 # 1. stowing a package with an empty directory
162 # 2. stow another package with the same directory but non empty
163 # 3. unstow the second package
164 # Q. the original empty directory should remain
165 # behaviour is the same as if the empty directory had nothing to do with stow
167 reset_state();
168 $Option{'verbose'} = 0;
170 make_dir('stow/pkg1a/bin1');
171 make_dir('stow/pkg1b/bin1');
172 make_file('stow/pkg1b/bin1/file1b');
174 stow_contents('stow/pkg1a', './', 'stow/pkg1a');
175 stow_contents('stow/pkg1b', './', 'stow/pkg1b');
176 unstow_contents('stow/pkg1b', './', 'stow/pkg1b');
177 process_tasks();
180 scalar(@Conflicts) == 0 &&
181 -d 'bin1'
182 => 'bug 1: stowing empty dirs'
187 # BUG 2: split open tree-folding symlinks pointing inside different stow
188 # directories
190 reset_state();
191 $Option{'verbose'} = 0;
193 make_dir('stow2a/pkg2a/bin2');
194 make_file('stow2a/pkg2a/bin2/file2a');
195 make_file('stow2a/.stow');
196 make_dir('stow2b/pkg2b/bin2');
197 make_file('stow2b/pkg2b/bin2/file2b');
198 make_file('stow2b/.stow');
200 stow_contents('stow2a/pkg2a','./', 'stow2a/pkg2a');
201 stow_contents('stow2b/pkg2b','./', 'stow2b/pkg2b');
202 process_tasks();
204 ## Finish this test