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
=> 10;
26 use English
qw(-no_match_vars);
28 use Stow
::Util
qw(adjust_dotfile);
32 cd
("$TEST_DIR/target");
34 subtest
('adjust_dotfile()', sub {
38 ['dot-file', '.file'],
41 ['dir1/dir2/dot-file', 'dir1/dir2/.file'],
42 ['dir1/dot-dir2/file', 'dir1/.dir2/file'],
43 ['dir1/dot-dir2/dot-file', 'dir1/.dir2/.file'],
44 ['dot-dir1/dot-dir2/dot-file', '.dir1/.dir2/.file'],
45 ['dot-dir1/dot-dir2/file', '.dir1/.dir2/file'],
47 for my $test (@TESTS) {
48 my ($input, $expected) = @
$test;
50 is
(adjust_dotfile
($input), $expected);
56 subtest
("stow a dotfile marked with 'dot' prefix", sub {
58 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
59 make_path
('../stow/dotfiles');
60 make_file
('../stow/dotfiles/dot-foo');
62 $stow->plan_stow('dotfiles');
63 $stow->process_tasks();
66 '../stow/dotfiles/dot-foo',
67 => 'processed dotfile'
71 subtest
("ensure that turning off dotfile processing links files as usual", sub {
73 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 0);
74 make_path
('../stow/dotfiles');
75 make_file
('../stow/dotfiles/dot-foo');
77 $stow->plan_stow('dotfiles');
78 $stow->process_tasks();
81 '../stow/dotfiles/dot-foo',
82 => 'unprocessed dotfile'
87 subtest
("stow folder marked with 'dot' prefix", sub {
89 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
91 make_path
('../stow/dotfiles/dot-emacs');
92 make_file
('../stow/dotfiles/dot-emacs/init.el');
94 $stow->plan_stow('dotfiles');
95 $stow->process_tasks();
98 '../stow/dotfiles/dot-emacs',
99 => 'processed dotfile folder'
103 subtest
("process folder marked with 'dot' prefix when directory exists is target", sub {
105 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
107 make_path
('../stow/dotfiles/dot-emacs.d');
108 make_file
('../stow/dotfiles/dot-emacs.d/init.el');
109 make_path
('.emacs.d');
111 $stow->plan_stow('dotfiles');
112 $stow->process_tasks();
114 readlink('.emacs.d/init.el'),
115 '../../stow/dotfiles/dot-emacs.d/init.el',
116 => 'processed dotfile folder when folder exists (1 level)'
120 subtest
("process folder marked with 'dot' prefix when directory exists is target (2 levels)", sub {
122 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
124 make_path
('../stow/dotfiles/dot-emacs.d/dot-emacs.d');
125 make_file
('../stow/dotfiles/dot-emacs.d/dot-emacs.d/init.el');
126 make_path
('.emacs.d');
128 $stow->plan_stow('dotfiles');
129 $stow->process_tasks();
131 readlink('.emacs.d/.emacs.d'),
132 '../../stow/dotfiles/dot-emacs.d/dot-emacs.d',
133 => 'processed dotfile folder exists (2 levels)'
137 subtest
("process folder marked with 'dot' prefix when directory exists is target", sub {
139 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
141 make_path
('../stow/dotfiles/dot-one/dot-two');
142 make_file
('../stow/dotfiles/dot-one/dot-two/three');
143 make_path
('.one/.two');
145 $stow->plan_stow('dotfiles');
146 $stow->process_tasks();
148 readlink('./.one/.two/three'),
149 '../../../stow/dotfiles/dot-one/dot-two/three',
150 => 'processed dotfile 2 folder exists (2 levels)'
155 subtest
("dot-. should not have that part expanded.", sub {
157 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
159 make_path
('../stow/dotfiles');
160 make_file
('../stow/dotfiles/dot-');
162 make_path
('../stow/dotfiles/dot-.');
163 make_file
('../stow/dotfiles/dot-./foo');
165 $stow->plan_stow('dotfiles');
166 $stow->process_tasks();
169 '../stow/dotfiles/dot-',
170 => 'processed dotfile'
174 '../stow/dotfiles/dot-.',
175 => 'unprocessed dotfile'
179 subtest
("simple unstow scenario", sub {
181 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
183 make_path
('../stow/dotfiles');
184 make_file
('../stow/dotfiles/dot-bar');
185 make_link
('.bar', '../stow/dotfiles/dot-bar');
187 $stow->plan_unstow('dotfiles');
188 $stow->process_tasks();
189 is
($stow->get_conflict_count, 0);
190 ok
(-f
'../stow/dotfiles/dot-bar');
191 ok
(! -e
'.bar' => 'unstow a simple dotfile');
194 subtest
("unstow process folder marked with 'dot' prefix when directory exists is target", sub {
196 $stow = new_Stow
(dir
=> '../stow', dotfiles
=> 1);
198 make_path
('../stow/dotfiles/dot-emacs.d');
199 make_file
('../stow/dotfiles/dot-emacs.d/init.el');
200 make_path
('.emacs.d');
201 make_link
('.emacs.d/init.el', '../../stow/dotfiles/dot-emacs.d/init.el');
203 $stow->plan_unstow('dotfiles');
204 $stow->process_tasks();
205 is
($stow->get_conflict_count, 0);
206 ok
(-f
'../stow/dotfiles/dot-emacs.d/init.el');
207 ok
(! -e
'.emacs.d/init.el');
208 ok
(-d
'.emacs.d/' => 'unstow dotfile folder when folder already exists');