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
=> 12;
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
("unstow .bar from dot-bar", sub {
190 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
192 make_path
('../stow/dotfiles');
193 make_file
('../stow/dotfiles/dot-bar');
194 make_link
('.bar', '../stow/dotfiles/dot-bar');
196 $stow->plan_unstow('dotfiles');
197 $stow->process_tasks();
198 is
($stow->get_conflict_count, 0);
199 ok
(-f
'../stow/dotfiles/dot-bar', 'package file untouched');
200 ok
(! -e
'.bar' => '.bar was unstowed');
203 subtest
("unstow dot-emacs.d/init.el when .emacs.d/init.el in target", sub {
205 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
207 make_path
('../stow/dotfiles/dot-emacs.d');
208 make_file
('../stow/dotfiles/dot-emacs.d/init.el');
209 make_path
('.emacs.d');
210 make_link
('.emacs.d/init.el', '../../stow/dotfiles/dot-emacs.d/init.el');
212 $stow->plan_unstow('dotfiles');
213 $stow->process_tasks();
214 is
($stow->get_conflict_count, 0);
215 ok
(-f
'../stow/dotfiles/dot-emacs.d/init.el');
216 ok
(! -e
'.emacs.d/init.el', '.emacs.d/init.el unstowed');
217 ok
(-d
'.emacs.d/' => '.emacs.d left behind');
220 subtest
("unstow dot-emacs.d/init.el in --compat mode", sub {
222 $stow = new_compat_Stow
(dir
=> '../stow', dotfiles
=> 1);
224 make_path
('../stow/dotfiles/dot-emacs.d');
225 make_file
('../stow/dotfiles/dot-emacs.d/init.el');
226 make_path
('.emacs.d');
227 make_link
('.emacs.d/init.el', '../../stow/dotfiles/dot-emacs.d/init.el');
229 $stow->plan_unstow('dotfiles');
230 $stow->process_tasks();
231 is
($stow->get_conflict_count, 0);
232 ok
(-f
'../stow/dotfiles/dot-emacs.d/init.el');
233 ok
(! -e
'.emacs.d/init.el', '.emacs.d/init.el unstowed');
234 ok
(-d
'.emacs.d/' => '.emacs.d left behind');