summaryrefslogtreecommitdiff
path: root/t/examples.t
blob: 376de3975f4796ead5b6e8a8eddc1ac565b275fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/perl
#
# This file is part of GNU Stow.
#
# GNU Stow is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GNU Stow is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see https://www.gnu.org/licenses/.

#
# Testing examples from the documentation
#

use strict;
use warnings;

use testutil;

use Test::More tests => 10;
use English qw(-no_match_vars);

init_test_dirs();
cd("$TEST_DIR/target");

my $stow;

## set up some fake packages to stow

# perl
make_path('stow/perl/bin');
make_file('stow/perl/bin/perl');
make_file('stow/perl/bin/a2p');
make_path('stow/perl/info');
make_file('stow/perl/info/perl');
make_path('stow/perl/lib/perl');
make_path('stow/perl/man/man1');
make_file('stow/perl/man/man1/perl.1');

# emacs
make_path('stow/emacs/bin');
make_file('stow/emacs/bin/emacs');
make_file('stow/emacs/bin/etags');
make_path('stow/emacs/info');
make_file('stow/emacs/info/emacs');
make_path('stow/emacs/libexec/emacs');
make_path('stow/emacs/man/man1');
make_file('stow/emacs/man/man1/emacs.1');

#
# stow perl into an empty target
# 

$stow = new_Stow(dir => 'stow');
$stow->plan_stow('perl');
$stow->process_tasks();
ok(
    $stow->get_conflict_count == 0 &&
    -l 'bin' && -l 'info' && -l 'lib' && -l 'man' &&
    readlink('bin')  eq 'stow/perl/bin' &&
    readlink('info') eq 'stow/perl/info' &&
    readlink('lib')  eq 'stow/perl/lib' &&
    readlink('man')  eq 'stow/perl/man'
    => 'stow perl into an empty target' 
);

#
# stow perl into a non-empty target
#

# clean up previous stow
remove_link('bin');
remove_link('info');
remove_link('lib');
remove_link('man');

make_path('bin');
make_path('lib');
make_path('man/man1');

$stow = new_Stow(dir => 'stow');
$stow->plan_stow('perl');
$stow->process_tasks();
ok(
    $stow->get_conflict_count == 0 &&
    -d 'bin' && -d 'lib' && -d 'man' && -d 'man/man1' &&
    -l 'info' && -l 'bin/perl' && -l 'bin/a2p' && 
    -l 'lib/perl' && -l 'man/man1/perl.1' &&
    readlink('info')     eq 'stow/perl/info' &&
    readlink('bin/perl') eq '../stow/perl/bin/perl' &&
    readlink('bin/a2p')  eq '../stow/perl/bin/a2p' &&
    readlink('lib/perl') eq '../stow/perl/lib/perl' &&
    readlink('man/man1/perl.1')  eq '../../stow/perl/man/man1/perl.1'
    => 'stow perl into a non-empty target' 
); 


#
# Install perl into an empty target and then install emacs
#

# clean up previous stow
remove_link('info');
remove_dir('bin');
remove_dir('lib');
remove_dir('man');

$stow = new_Stow(dir => 'stow');
$stow->plan_stow('perl', 'emacs');
$stow->process_tasks();
is($stow->get_conflict_count, 0, 'no conflicts');
ok(
    -d 'bin'        && 
    -l 'bin/perl'   && 
    -l 'bin/emacs'  && 
    -l 'bin/a2p'    && 
    -l 'bin/etags'  && 
    readlink('bin/perl')    eq '../stow/perl/bin/perl'      &&
    readlink('bin/a2p')     eq '../stow/perl/bin/a2p'       &&
    readlink('bin/emacs')   eq '../stow/emacs/bin/emacs'    &&
    readlink('bin/etags')   eq '../stow/emacs/bin/etags'    &&
    
    -d 'info'       && 
    -l 'info/perl'  && 
    -l 'info/emacs' && 
    readlink('info/perl')   eq '../stow/perl/info/perl'     &&
    readlink('info/emacs')  eq '../stow/emacs/info/emacs'   &&

    -d 'man'                && 
    -d 'man/man1'           &&
    -l 'man/man1/perl.1'    &&
    -l 'man/man1/emacs.1'   &&
    readlink('man/man1/perl.1')  eq '../../stow/perl/man/man1/perl.1'   &&
    readlink('man/man1/emacs.1') eq '../../stow/emacs/man/man1/emacs.1' &&

    -l 'lib'        && 
    -l 'libexec'    &&
    readlink('lib')     eq 'stow/perl/lib'      &&
    readlink('libexec') eq 'stow/emacs/libexec' &&
    1
    => 'stow perl into an empty target, then stow emacs' 
); 

#
# BUG 1: 
# 1. stowing a package with an empty directory
# 2. stow another package with the same directory but non empty
# 3. unstow the second package
# Q. the original empty directory should remain 
# behaviour is the same as if the empty directory had nothing to do with stow
#

make_path('stow/pkg1a/bin1');
make_path('stow/pkg1b/bin1');
make_file('stow/pkg1b/bin1/file1b');

$stow = new_Stow(dir => 'stow');
$stow->plan_stow('pkg1a', 'pkg1b');
$stow->plan_unstow('pkg1b');
$stow->process_tasks();
is($stow->get_conflict_count, 0, 'no conflicts stowing empty dirs');
ok(-d 'bin1' => 'bug 1: stowing empty dirs');

#
# BUG 2: split open tree-folding symlinks pointing inside different stow
# directories
#
make_path('stow2a/pkg2a/bin2');
make_file('stow2a/pkg2a/bin2/file2a');
make_file('stow2a/.stow');
make_path('stow2b/pkg2b/bin2');
make_file('stow2b/pkg2b/bin2/file2b');
make_file('stow2b/.stow');

$stow = new_Stow(dir => 'stow2a');
$stow->plan_stow('pkg2a');
$stow->set_stow_dir('stow2b');
$stow->plan_stow('pkg2b');
$stow->process_tasks();

is($stow->get_conflict_count, 0, 'no conflicts splitting tree-folding symlinks');
ok(-d 'bin2' => 'tree got split by packages from multiple stow directories');
ok(-f 'bin2/file2a' => 'file from 1st stow dir');
ok(-f 'bin2/file2b' => 'file from 2nd stow dir');

## Finish this test