t/unstow.t: convert to use subtests
[gnu-stow.git] / t / dotfiles.t
blob83874ca212a1fdf1afea44d1171cf6586d910959
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 => 10;
26 use English qw(-no_match_vars);
28 use Stow::Util qw(adjust_dotfile);
29 use testutil;
31 init_test_dirs();
32 cd("$TEST_DIR/target");
34 subtest('adjust_dotfile()', sub {
35 plan tests => 9;
36 my @TESTS = (
37 ['file'],
38 ['dot-file', '.file'],
39 ['dir1/file'],
40 ['dir1/dir2/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;
49 $expected ||= $input;
50 is(adjust_dotfile($input), $expected);
52 });
54 my $stow;
56 subtest("stow a dotfile marked with 'dot' prefix", sub {
57 plan tests => 1;
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();
64 is(
65 readlink('.foo'),
66 '../stow/dotfiles/dot-foo',
67 => 'processed dotfile'
69 });
71 subtest("ensure that turning off dotfile processing links files as usual", sub {
72 plan tests => 1;
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();
79 is(
80 readlink('dot-foo'),
81 '../stow/dotfiles/dot-foo',
82 => 'unprocessed dotfile'
85 });
87 subtest("stow folder marked with 'dot' prefix", sub {
88 plan tests => 1;
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();
96 is(
97 readlink('.emacs'),
98 '../stow/dotfiles/dot-emacs',
99 => 'processed dotfile folder'
103 subtest("process folder marked with 'dot' prefix when directory exists is target", sub {
104 plan tests => 1;
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 {
121 plan tests => 1;
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 {
138 plan tests => 1;
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 {
156 plan tests => 2;
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();
168 readlink('dot-'),
169 '../stow/dotfiles/dot-',
170 => 'processed dotfile'
173 readlink('dot-.'),
174 '../stow/dotfiles/dot-.',
175 => 'unprocessed dotfile'
179 subtest("simple unstow scenario", sub {
180 plan tests => 3;
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 {
195 plan tests => 4;
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');