Bump version to 2.4.0
[gnu-stow.git] / t / dotfiles.t
blob643b87358e3a24486a5bc57c1415677897ea11fc
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 => 12;
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("unstow .bar from dot-bar", sub {
189 plan tests => 3;
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 {
204 plan tests => 4;
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 {
221 plan tests => 4;
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');