/
01.simple.t
230 lines (170 loc) · 7.26 KB
/
01.simple.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!perl
use Test::More;
use strict;
use FindBin qw($Bin);
use English qw( -no_match_vars );
require "$Bin/helper.pl";
my $file_slurp_available = load_mod('File::Slurp qw(read_file)');
check_minimum_test_more_version();
my $profile_filename = ( lc($OSNAME) eq 'darwin' ) ? '.profile' : '.bashrc';
subtest 'simplest' => sub {
focus('simplest');
my ( $home, $repo, $origin );
( $home, $repo, $origin ) = minimum_home('simple');
( $home, $repo ) = minimum_home( 'simple2', { origin => $origin } );
`touch $repo/.bashrc.load`; # make sure there's a loader
my $output = `HOME=$home perl $repo/bin/dfm --verbose`;
ok( -d "$home/.backup", 'main backup dir exists' );
ok( -l "$home/bin", 'bin is a symlink' );
ok( !-e "$home/.git", ".git does not exist in \$home" );
ok( !-e "$home/.gitignore", '.gitignore does not exist' );
ok( !-e "$home/.dfminstall", '.dfminstall does not exist' );
is( readlink("$home/bin"), '.dotfiles/bin', 'bin points into repo' );
SKIP: {
skip 'File::Slurp not found', 1 unless $file_slurp_available;
ok( read_file("$home/$profile_filename") =~ /bashrc.load/,
"loader present in $profile_filename" );
}
ok( !-e "$home/README.md", 'no README.md in homedir' );
ok( !-e "$home/t", 'no t dir in homedir' );
};
subtest 'dangling symlinks' => sub {
focus('dangling');
my ( $home, $repo ) = minimum_home_with_ssh('dangling');
symlink( ".dotfiles/.other", "$home/.other" );
symlink( "../.dotfiles/.ssh/.other", "$home/.ssh/.other" );
my $output = `HOME=$home perl $repo/bin/dfm --verbose`;
ok( !-l "$home/.other", 'dangling symlink is gone' );
ok( !-l "$home/.ssh/.other", 'dangling symlink is gone' );
};
subtest 'with . ssh recurse( no . ssh dir )' => sub {
focus('recurse_no');
my ( $home, $repo ) = minimum_home_with_ssh( 'ssh_no', 1 );
`touch $repo/.bashrc.load`; # make sure there's a loader
my $output = `HOME=$home perl $repo/bin/dfm --verbose`;
check_ssh_recurse($home);
};
subtest 'with .ssh recurse (with .ssh dir)' => sub {
focus('recurse_with');
my ( $home, $repo ) = minimum_home_with_ssh('ssh_with');
`touch $repo/.bashrc.load`; # make sure there's a loader
my $output = `HOME=$home perl $repo/bin/dfm --verbose`;
check_ssh_recurse($home);
};
subtest 'with bin recurse' => sub {
focus('bin_recurse');
my ( $home, $repo, $origin );
( $home, $repo, $origin )
= minimum_home( 'bin_recurse', { dfminstall_contents => 'bin' } );
`mkdir -p $home/bin`;
`echo "another bin" > $home/bin/another`;
my $output = `HOME=$home perl $repo/bin/dfm --verbose`;
ok( -d "$home/.backup", 'main backup dir exists' );
ok( -d "$home/bin", 'bin is a directory' );
ok( -l "$home/bin/dfm", 'dfm is a symlink' );
ok( -e "$home/bin/another" && !-l "$home/bin/another",
'existing binary still intact' );
};
subtest 'check deprecated recursion' => sub {
focus('deprec');
my ( $home, $repo );
( $home, $repo )
= minimum_home( 'deprecated_recurse',
{ dfminstall_contents => 'bin' } );
my $output = `HOME=$home perl $repo/bin/dfm --verbose`;
like(
$output,
qr(using implied recursion in .dfminstall is deprecated),
'warning present'
);
like( $output, qr($repo/.dfminstall), '.dfminstall path present' );
like(
$output,
qr('bin recurse'),
'proper .dfminstall contents mentioned'
);
( $home, $repo )
= minimum_home( 'deprecated_recurse',
{ dfminstall_contents => 'bin recurse' } );
my $output = `HOME=$home perl $repo/bin/dfm --verbose`;
unlike(
$output,
qr(using implied recursion in .dfminstall is deprecated),
'warning present when keyword used'
);
};
subtest 'switch to recursion' => sub {
focus('rec_switch');
my ( $home, $repo, $origin );
( $home, $repo, $origin ) = minimum_home('switch_recurse');
my $output;
$output = `HOME=$home perl $repo/bin/dfm --verbose`;
ok( -d "$home/.backup", 'main backup dir exists' );
ok( -l "$home/bin", 'bin is a symlink' );
`echo "bin recurse" >> $repo/.dfminstall`;
$output = `HOME=$home perl $repo/bin/dfm --verbose`;
ok( -d "$home/.backup", 'main backup dir exists' );
ok( -d "$home/bin", 'bin is a directory' );
ok( -l "$home/bin/dfm", 'dfm is a symlink' );
};
subtest 'parallel recursions work' => sub {
focus('parallel_rec');
my ( $home, $repo, $origin );
( $home, $repo, $origin )
= minimum_home( 'parallel_recursions',
{ dfminstall_contents => "test1 recurse\ntest2 recurse" } );
`mkdir -p $repo/test1`;
`touch $repo/test1/file1`;
`mkdir -p $repo/test2`;
`touch $repo/test2/file2`;
my $output = `HOME=$home perl $repo/bin/dfm --verbose`;
ok( -d "$home/test1", 'first directory present' );
ok( -l "$home/test1/file1", 'first file is symlink' );
ok( -d "$home/test2", 'second directory present' );
ok( -l "$home/test2/file2", 'second file is symlink' );
};
subtest 'exec option' => sub {
focus('exec_option');
my ( $home, $repo, $origin );
( $home, $repo, $origin ) = minimum_home(
'exec_option',
{ dfminstall_contents =>
"script1.sh exec\nscript1.sh skip\ntest2 recurse"
}
);
# set up non-recurse script that needs to be set executable
`echo "#!/bin/sh\n\necho 'message1';\ntouch testfile" > $repo/script1.sh`;
# set up recurse script that is already executable
`mkdir -p $repo/test2`;
`echo "script2.sh exec" > $repo/test2/.dfminstall`;
`echo "#!/bin/sh\n\necho 'message2';\ntouch testfile2" > $repo/test2/script2.sh`;
`chmod +x $repo/test2/script2.sh`;
my $output = `HOME=$home perl $repo/bin/dfm --verbose`;
like( $output, qr/message1/, 'output contains output from script1' );
ok( -e "$home/testfile", 'file created by script1 exists' );
ok( !-e "$home/script1.sh", 'script1 is not symlinked into home' );
ok( -x "$repo/script1.sh", 'script1 file is executable' );
like( $output, qr/message2/, 'output contains output from script2' );
ok( -e "$home/test2/testfile2", 'file created by script2 exists' );
ok( -x "$repo/test2/script2.sh", 'script2 file is executable' );
};
done_testing;
sub check_ssh_recurse {
my ($home) = @_;
ok( -d "$home/.backup", 'main backup dir exists' );
ok( -l "$home/bin", 'bin is a symlink' );
ok( !-e "$home/.git", '.git does not exist in $home' );
ok( !-e "$home/.gitignore", '.gitignore does not exist' );
ok( !-e "$home/.dfminstall", '.dfminstall does not exist' );
ok( !-l "$home/.ssh", '.ssh is not a symlink' );
ok( !-e "$home/.ssh/.gitignore", '.ssh/.gitignore does not exist' );
is( readlink("$home/bin"), '.dotfiles/bin', 'bin points into repo' );
ok( -d "$home/.ssh/.backup", 'ssh backup dir exists' );
SKIP: {
skip 'File::Slurp not found', 1 unless $file_slurp_available;
ok( read_file("$home/$profile_filename") =~ /bashrc.load/,
"loader present in $profile_filename" );
}
ok( !-e "$home/README.md", 'no README.md in homedir' );
ok( !-e "$home/t", 'no t dir in homedir' );
}