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 # Test case for dotfiles special processing
25 use Test
::More tests
=> 14;
26 use English
qw(-no_match_vars);
28 use Stow
::Util
qw(adjust_dotfile unadjust_dotfile);
32 cd
("$TEST_DIR/target");
34 subtest
('adjust_dotfile()', sub {
40 ['dot-file', '.file'],
42 for my $test (@TESTS) {
43 my ($input, $expected) = @
$test;
45 is
(adjust_dotfile
($input), $expected);
49 subtest
('unadjust_dotfile()', sub {
55 ['.file', 'dot-file'],
57 for my $test (@TESTS) {
58 my ($input, $expected) = @
$test;
60 is
(unadjust_dotfile
($input), $expected);
66 subtest
("stow dot-foo as .foo", sub {
68 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
69 make_path
('../stow/dotfiles');
70 make_file
('../stow/dotfiles/dot-foo');
72 $stow->plan_stow('dotfiles');
73 $stow->process_tasks();
76 '../stow/dotfiles/dot-foo',
77 => 'processed dotfile'
81 subtest
("stow dot-foo as dot-foo without --dotfile enabled", sub {
83 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 0);
84 make_path
('../stow/dotfiles');
85 make_file
('../stow/dotfiles/dot-foo');
87 $stow->plan_stow('dotfiles');
88 $stow->process_tasks();
91 '../stow/dotfiles/dot-foo',
92 => 'unprocessed dotfile'
96 subtest
("stow dot-emacs dir as .emacs", sub {
98 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
100 make_path
('../stow/dotfiles/dot-emacs');
101 make_file
('../stow/dotfiles/dot-emacs/init.el');
103 $stow->plan_stow('dotfiles');
104 $stow->process_tasks();
107 '../stow/dotfiles/dot-emacs',
108 => 'processed dotfile dir'
112 subtest
("stow dir marked with 'dot' prefix when directory exists in target", sub {
114 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
116 make_path
('../stow/dotfiles/dot-emacs.d');
117 make_file
('../stow/dotfiles/dot-emacs.d/init.el');
118 make_path
('.emacs.d');
120 $stow->plan_stow('dotfiles');
121 $stow->process_tasks();
123 readlink('.emacs.d/init.el'),
124 '../../stow/dotfiles/dot-emacs.d/init.el',
125 => 'processed dotfile dir when dir exists (1 level)'
129 subtest
("stow dir marked with 'dot' prefix when directory exists in target (2 levels)", sub {
131 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
133 make_path
('../stow/dotfiles/dot-emacs.d/dot-emacs.d');
134 make_file
('../stow/dotfiles/dot-emacs.d/dot-emacs.d/init.el');
135 make_path
('.emacs.d');
137 $stow->plan_stow('dotfiles');
138 $stow->process_tasks();
140 readlink('.emacs.d/.emacs.d'),
141 '../../stow/dotfiles/dot-emacs.d/dot-emacs.d',
142 => 'processed dotfile dir exists (2 levels)'
146 subtest
("stow dir marked with 'dot' prefix when directory exists in target", sub {
148 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
150 make_path
('../stow/dotfiles/dot-one/dot-two');
151 make_file
('../stow/dotfiles/dot-one/dot-two/three');
152 make_path
('.one/.two');
154 $stow->plan_stow('dotfiles');
155 $stow->process_tasks();
157 readlink('./.one/.two/three'),
158 '../../../stow/dotfiles/dot-one/dot-two/three',
159 => 'processed dotfile 2 dir exists (2 levels)'
164 subtest
("dot-. should not have that part expanded.", sub {
166 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
168 make_path
('../stow/dotfiles');
169 make_file
('../stow/dotfiles/dot-');
171 make_path
('../stow/dotfiles/dot-.');
172 make_file
('../stow/dotfiles/dot-./foo');
174 $stow->plan_stow('dotfiles');
175 $stow->process_tasks();
178 '../stow/dotfiles/dot-',
179 => 'processed dotfile'
183 '../stow/dotfiles/dot-.',
184 => 'unprocessed dotfile'
188 subtest
("when stowing, dot-gitignore is not ignored by default", sub {
190 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
192 make_file
('../stow/dotfiles/dot-gitignore');
194 $stow->plan_stow('dotfiles');
195 $stow->process_tasks();
197 readlink('.gitignore'),
198 '../stow/dotfiles/dot-gitignore',
199 => "dot-gitignore shouldn't have been ignored"
203 subtest
("unstow .bar from dot-bar", sub {
205 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
207 make_path
('../stow/dotfiles');
208 make_file
('../stow/dotfiles/dot-bar');
209 make_link
('.bar', '../stow/dotfiles/dot-bar');
211 $stow->plan_unstow('dotfiles');
212 $stow->process_tasks();
213 is
($stow->get_conflict_count, 0);
214 ok
(-f
'../stow/dotfiles/dot-bar', 'package file untouched');
215 ok
(! -e
'.bar' => '.bar was unstowed');
218 subtest
("unstow dot-emacs.d/init.el when .emacs.d/init.el in target", sub {
220 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
222 make_path
('../stow/dotfiles/dot-emacs.d');
223 make_file
('../stow/dotfiles/dot-emacs.d/init.el');
224 make_path
('.emacs.d');
225 make_link
('.emacs.d/init.el', '../../stow/dotfiles/dot-emacs.d/init.el');
227 $stow->plan_unstow('dotfiles');
228 $stow->process_tasks();
229 is
($stow->get_conflict_count, 0);
230 ok
(-f
'../stow/dotfiles/dot-emacs.d/init.el');
231 ok
(! -e
'.emacs.d/init.el', '.emacs.d/init.el unstowed');
232 ok
(-d
'.emacs.d/' => '.emacs.d left behind');
235 subtest
("unstow dot-emacs.d/init.el in --compat mode", sub {
237 $stow = new_compat_Stow
(dir
=> '../stow', dotfiles
=> 1);
239 make_path
('../stow/dotfiles/dot-emacs.d');
240 make_file
('../stow/dotfiles/dot-emacs.d/init.el');
241 make_path
('.emacs.d');
242 make_link
('.emacs.d/init.el', '../../stow/dotfiles/dot-emacs.d/init.el');
244 $stow->plan_unstow('dotfiles');
245 $stow->process_tasks();
246 is
($stow->get_conflict_count, 0);
247 ok
(-f
'../stow/dotfiles/dot-emacs.d/init.el');
248 ok
(! -e
'.emacs.d/init.el', '.emacs.d/init.el unstowed');
249 ok
(-d
'.emacs.d/' => '.emacs.d left behind');
252 subtest
("when unstowing, dot-gitignore is not ignored by default", sub {
254 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
257 make_file
('../stow/dotfiles/dot-gitignore');
258 -e
'.gitignore' or make_link
('.gitignore', '../stow/dotfiles/dot-gitignore');
260 $stow->plan_unstow('dotfiles');
261 $stow->process_tasks();
264 => "dot-gitignore shouldn't have been ignored"