Bump version to 2.4.2 for development of next release
[gnu-stow.git] / t / dotfiles.t
blob4db742c3262b7be90896da95e1b98a390e5e41ec
1 #!/usr/bin/perl
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
22 use strict;
23 use warnings;
25 use Test::More tests => 14;
26 use English qw(-no_match_vars);
28 use Stow::Util qw(adjust_dotfile unadjust_dotfile);
29 use testutil;
31 init_test_dirs();
32 cd("$TEST_DIR/target");
34 subtest('adjust_dotfile()', sub {
35 plan tests => 4;
36 my @TESTS = (
37 ['file'],
38 ['dot-'],
39 ['dot-.'],
40 ['dot-file', '.file'],
42 for my $test (@TESTS) {
43 my ($input, $expected) = @$test;
44 $expected ||= $input;
45 is(adjust_dotfile($input), $expected);
47 });
49 subtest('unadjust_dotfile()', sub {
50 plan tests => 4;
51 my @TESTS = (
52 ['file'],
53 ['.'],
54 ['..'],
55 ['.file', 'dot-file'],
57 for my $test (@TESTS) {
58 my ($input, $expected) = @$test;
59 $expected ||= $input;
60 is(unadjust_dotfile($input), $expected);
62 });
64 my $stow;
66 subtest("stow dot-foo as .foo", sub {
67 plan tests => 1;
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();
74 is(
75 readlink('.foo'),
76 '../stow/dotfiles/dot-foo',
77 => 'processed dotfile'
79 });
81 subtest("stow dot-foo as dot-foo without --dotfile enabled", sub {
82 plan tests => 1;
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();
89 is(
90 readlink('dot-foo'),
91 '../stow/dotfiles/dot-foo',
92 => 'unprocessed dotfile'
94 });
96 subtest("stow dot-emacs dir as .emacs", sub {
97 plan tests => 1;
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();
106 readlink('.emacs'),
107 '../stow/dotfiles/dot-emacs',
108 => 'processed dotfile dir'
112 subtest("stow dir marked with 'dot' prefix when directory exists in target", sub {
113 plan tests => 1;
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 {
130 plan tests => 1;
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 {
147 plan tests => 1;
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 {
165 plan tests => 2;
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();
177 readlink('dot-'),
178 '../stow/dotfiles/dot-',
179 => 'processed dotfile'
182 readlink('dot-.'),
183 '../stow/dotfiles/dot-.',
184 => 'unprocessed dotfile'
188 subtest("when stowing, dot-gitignore is not ignored by default", sub {
189 plan tests => 1;
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 {
204 plan tests => 3;
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 {
219 plan tests => 4;
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 {
236 plan tests => 4;
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 {
253 plan tests => 1;
254 $stow = new_Stow(dir => '../stow', dotfiles => 1);
256 system('pwd');
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();
263 ! -e ('.gitignore')
264 => "dot-gitignore shouldn't have been ignored"