2 # Copyright (c) 2016 Jilles Tjoelker
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 copy_to_nonexistent_with_opts() {
30 printf 'test\n123\r456\r\n789\0z' >testf
31 atf_check install "$@" testf copyf
32 cmp testf copyf || atf_fail "bad copy"
33 [ ! testf -nt copyf ] || atf_fail "bad timestamp"
34 [ ! -e copyf.bak ] || atf_fail "no backup expected"
37 atf_test_case copy_to_nonexistent
38 copy_to_nonexistent_body() {
39 copy_to_nonexistent_with_opts
42 atf_test_case copy_to_nonexistent_safe
43 copy_to_nonexistent_safe_body() {
44 copy_to_nonexistent_with_opts -S
47 atf_test_case copy_to_nonexistent_comparing
48 copy_to_nonexistent_comparing_body() {
49 copy_to_nonexistent_with_opts -C
52 atf_test_case copy_to_nonexistent_safe_comparing
53 copy_to_nonexistent_safe_comparing_body() {
54 copy_to_nonexistent_with_opts -S -C
57 atf_test_case copy_to_nonexistent_backup
58 copy_to_nonexistent_backup_body() {
59 copy_to_nonexistent_with_opts -b -B.bak
62 atf_test_case copy_to_nonexistent_backup_safe
63 copy_to_nonexistent_backup_safe_body() {
64 copy_to_nonexistent_with_opts -b -B.bak -S
67 atf_test_case copy_to_nonexistent_preserving
68 copy_to_nonexistent_preserving_body() {
69 copy_to_nonexistent_with_opts -p
70 [ ! testf -ot copyf ] || atf_fail "bad timestamp 2"
73 copy_self_with_opts() {
74 printf 'test\n123\r456\r\n789\0z' >testf
75 printf 'test\n123\r456\r\n789\0z' >testf2
76 atf_check -s not-exit:0 -o empty -e match:. install "$@" testf testf
77 cmp testf testf2 || atf_fail "file changed after self-copy attempt"
80 atf_test_case copy_self
85 atf_test_case copy_self_safe
86 copy_self_safe_body() {
87 copy_self_with_opts -S
90 atf_test_case copy_self_comparing
91 copy_self_comparing_body() {
92 copy_self_with_opts -C
95 atf_test_case copy_self_safe_comparing
96 copy_self_safe_comparing_body() {
97 copy_self_with_opts -S -C
100 overwrite_with_opts() {
101 printf 'test\n123\r456\r\n789\0z' >testf
102 printf 'test\n123\r456\r\n789\0w' >otherf
103 atf_check install "$@" testf otherf
104 cmp testf otherf || atf_fail "bad overwrite"
105 [ ! testf -nt otherf ] || atf_fail "bad timestamp"
108 atf_test_case overwrite
113 atf_test_case overwrite_safe
114 overwrite_safe_body() {
115 overwrite_with_opts -S
118 atf_test_case overwrite_comparing
119 overwrite_comparing_body() {
120 overwrite_with_opts -C
123 atf_test_case overwrite_safe_comparing
124 overwrite_safe_comparing_body() {
125 overwrite_with_opts -S -C
128 overwrite_eq_with_opts() {
129 printf 'test\n123\r456\r\n789\0z' >testf
130 printf 'test\n123\r456\r\n789\0z' >otherf
131 atf_check install "$@" testf otherf
132 cmp testf otherf || atf_fail "bad overwrite"
133 [ ! testf -nt otherf ] || atf_fail "bad timestamp"
136 atf_test_case overwrite_eq
137 overwrite_eq_body() {
138 overwrite_eq_with_opts
141 atf_test_case overwrite_eq_safe
142 overwrite_eq_safe_body() {
143 overwrite_eq_with_opts -S
146 atf_test_case overwrite_eq_comparing
147 overwrite_eq_comparing_body() {
148 overwrite_eq_with_opts -C
151 atf_test_case overwrite_eq_safe_comparing
152 overwrite_eq_safe_comparing_body() {
153 overwrite_eq_with_opts -S -C
156 overwrite_backup_with_opts() {
157 printf 'test\n123\r456\r\n789\0z' >testf
158 printf 'test\n123\r456\r\n789\0w' >otherf
159 printf 'test\n123\r456\r\n789\0w' >otherf2
160 atf_check install -b -B.bak "$@" testf otherf
161 cmp testf otherf || atf_fail "bad overwrite"
162 [ ! testf -nt otherf ] || atf_fail "bad timestamp"
163 cmp otherf.bak otherf2 || atf_fail "bad backup"
166 atf_test_case overwrite_backup
167 overwrite_backup_body() {
168 overwrite_backup_with_opts
171 atf_test_case overwrite_backup_safe
172 overwrite_backup_safe_body() {
173 overwrite_backup_with_opts -S
176 atf_test_case overwrite_backup_comparing
177 overwrite_backup_comparing_body() {
178 overwrite_backup_with_opts -C
181 atf_test_case overwrite_backup_safe_comparing
182 overwrite_backup_safe_comparing_body() {
183 overwrite_backup_with_opts -S -C
187 cat <<\STRIPBIN >stripbin
189 tr z @ <"$1" >"$1.new" && mv -- "$1.new" "$1"
192 export STRIPBIN="$PWD/stripbin"
195 strip_changing_with_opts() {
197 printf 'test\n123\r456\r\n789\0z' >testf
198 atf_check install -s "$@" testf copyf
199 [ ! testf -nt copyf ] || atf_fail "bad timestamp"
200 printf 'test\n123\r456\r\n789\0@' >otherf
201 cmp otherf copyf || atf_fail "bad stripped copy"
204 atf_test_case strip_changing
205 strip_changing_body() {
206 strip_changing_with_opts
209 atf_test_case strip_changing_comparing
210 strip_changing_comparing_body() {
211 strip_changing_with_opts -C
214 strip_changing_overwrite_with_opts() {
216 printf 'test\n123\r456\r\n789\0z' >testf
217 printf 'test\n123\r456\r\n789\0w' >copyf
218 atf_check install -s "$@" testf copyf
219 [ ! testf -nt copyf ] || atf_fail "bad timestamp"
220 printf 'test\n123\r456\r\n789\0@' >otherf
221 cmp otherf copyf || atf_fail "bad stripped copy"
224 atf_test_case strip_changing_overwrite
225 strip_changing_overwrite_body() {
226 strip_changing_overwrite_with_opts
229 atf_test_case strip_changing_overwrite_comparing
230 strip_changing_overwrite_comparing_body() {
231 strip_changing_overwrite_with_opts -C
234 strip_changing_overwrite_eq_with_opts() {
236 printf 'test\n123\r456\r\n789\0z' >testf
237 printf 'test\n123\r456\r\n789\0@' >copyf
238 atf_check install -s "$@" testf copyf
239 [ ! testf -nt copyf ] || atf_fail "bad timestamp"
240 printf 'test\n123\r456\r\n789\0@' >otherf
241 cmp otherf copyf || atf_fail "bad stripped copy"
244 atf_test_case strip_changing_overwrite_eq
245 strip_changing_overwrite_eq_body() {
246 strip_changing_overwrite_eq_with_opts
249 atf_test_case strip_changing_overwrite_eq_comparing
250 strip_changing_overwrite_eq_comparing_body() {
251 strip_changing_overwrite_eq_with_opts -C
254 atf_test_case strip_noop
257 printf 'test\n123\r456\r\n789\0z' >testf
258 atf_check install -s testf copyf
259 [ ! testf -nt copyf ] || atf_fail "bad timestamp"
260 printf 'test\n123\r456\r\n789\0z' >otherf
261 cmp otherf copyf || atf_fail "bad stripped copy"
264 atf_test_case hard_link
266 printf 'test\n123\r456\r\n789\0z' >testf
267 atf_check install -l h testf copyf
268 [ testf -ef copyf ] || atf_fail "not same file"
269 [ ! -L copyf ] || atf_fail "copy is symlink"
272 atf_test_case symbolic_link
273 symbolic_link_body() {
274 printf 'test\n123\r456\r\n789\0z' >testf
275 atf_check install -l s testf copyf
276 [ testf -ef copyf ] || atf_fail "not same file"
277 [ -L copyf ] || atf_fail "copy is not symlink"
280 atf_test_case symbolic_link_absolute
281 symbolic_link_absolute_body() {
282 printf 'test\n123\r456\r\n789\0z' >testf
283 atf_check install -l sa testf copyf
284 [ testf -ef copyf ] || atf_fail "not same file"
285 [ -L copyf ] || atf_fail "copy is not symlink"
286 copyf_path=$(readlink copyf)
287 testf_path="$(pwd -P)/testf"
288 if [ "$copyf_path" != "$testf_path" ]; then
289 atf_fail "unexpected symlink contents ('$copyf_path' != '$testf_path')"
293 atf_test_case symbolic_link_relative
294 symbolic_link_relative_body() {
295 printf 'test\n123\r456\r\n789\0z' >testf
296 atf_check install -l sr testf copyf
297 [ testf -ef copyf ] || atf_fail "not same file"
298 [ -L copyf ] || atf_fail "copy is not symlink"
299 copyf_path=$(readlink copyf)
301 if [ "$copyf_path" != "$testf_path" ]; then
302 atf_fail "unexpected symlink contents ('$copyf_path' != '$testf_path')"
306 atf_test_case symbolic_link_relative_absolute_source_and_dest1
307 symbolic_link_relative_absolute_source_and_dest1_head() {
308 atf_set "descr" "Verify -l rs with absolute paths (.../copyf -> .../a/b/c/testf)"
310 symbolic_link_relative_absolute_source_and_dest1_body() {
312 src_path_prefixed=$PWD/$src_path
315 atf_check mkdir -p a/b/c
316 atf_check touch $src_path
317 atf_check install -l sr $src_path_prefixed $dest_path
318 [ $src_path_prefixed -ef $dest_path ] || atf_fail "not same file"
319 [ -L $dest_path ] || atf_fail "copy is not symlink"
320 dest_path_relative=$(readlink $dest_path)
321 src_path_relative="$src_path"
322 if [ "$src_path_relative" != "$dest_path_relative" ]; then
323 atf_fail "unexpected symlink contents ('$src_path_relative' != '$dest_path_relative')"
327 atf_test_case symbolic_link_relative_absolute_source_and_dest1_double_slash
328 symbolic_link_relative_absolute_source_and_dest1_double_slash_head() {
329 atf_set "descr" "Verify -l rs with absolute paths (.../copyf -> .../a/b/c/testf), using double-slashes"
331 symbolic_link_relative_absolute_source_and_dest1_double_slash_body() {
332 src_path=a//b//c//testf
333 src_path_prefixed=$PWD/$src_path
336 atf_check mkdir -p a/b/c
337 atf_check touch $src_path
338 atf_check install -l sr $src_path_prefixed $dest_path
339 [ $src_path_prefixed -ef $dest_path ] || atf_fail "not same file"
340 [ -L $dest_path ] || atf_fail "copy is not symlink"
341 dest_path_relative=$(readlink $dest_path)
342 src_path_relative="$(echo $src_path | sed -e 's,//,/,g')"
343 if [ "$src_path_relative" != "$dest_path_relative" ]; then
344 atf_fail "unexpected symlink contents ('$src_path_relative' != '$dest_path_relative')"
348 atf_test_case symbolic_link_relative_absolute_source_and_dest2
349 symbolic_link_relative_absolute_source_and_dest2_head() {
350 atf_set "descr" "Verify -l rs with absolute paths (.../a/b/c/copyf -> .../testf)"
352 symbolic_link_relative_absolute_source_and_dest2_body() {
354 src_path_prefixed=$PWD/$src_path
355 dest_path=$PWD/a/b/c/copyf
357 atf_check mkdir -p a/b/c
358 atf_check touch $src_path
359 atf_check install -l sr $src_path_prefixed $dest_path
360 [ $src_path_prefixed -ef $dest_path ] || atf_fail "not same file"
361 [ -L $dest_path ] || atf_fail "copy is not symlink"
362 dest_path_relative=$(readlink $dest_path)
363 src_path_relative="../../../$src_path"
364 if [ "$src_path_relative" != "$dest_path_relative" ]; then
365 atf_fail "unexpected symlink contents ('$src_path_relative' != '$dest_path_relative')"
369 atf_test_case mkdir_simple
370 mkdir_simple_body() {
371 atf_check install -d dir1/dir2
372 [ -d dir1 ] || atf_fail "dir1 missing"
373 [ -d dir1/dir2 ] || atf_fail "dir2 missing"
374 atf_check install -d dir1/dir2/dir3
375 [ -d dir1/dir2/dir3 ] || atf_fail "dir3 missing"
376 atf_check install -d dir1
377 atf_check install -d dir1/dir2/dir3
380 atf_init_test_cases() {
381 atf_add_test_case copy_to_nonexistent
382 atf_add_test_case copy_to_nonexistent_safe
383 atf_add_test_case copy_to_nonexistent_comparing
384 atf_add_test_case copy_to_nonexistent_safe_comparing
385 atf_add_test_case copy_to_nonexistent_backup
386 atf_add_test_case copy_to_nonexistent_backup_safe
387 atf_add_test_case copy_to_nonexistent_preserving
388 atf_add_test_case copy_self
389 atf_add_test_case copy_self_safe
390 atf_add_test_case copy_self_comparing
391 atf_add_test_case copy_self_safe_comparing
392 atf_add_test_case overwrite
393 atf_add_test_case overwrite_safe
394 atf_add_test_case overwrite_comparing
395 atf_add_test_case overwrite_safe_comparing
396 atf_add_test_case overwrite_eq
397 atf_add_test_case overwrite_eq_safe
398 atf_add_test_case overwrite_eq_comparing
399 atf_add_test_case overwrite_eq_safe_comparing
400 atf_add_test_case overwrite_backup
401 atf_add_test_case overwrite_backup_safe
402 atf_add_test_case overwrite_backup_comparing
403 atf_add_test_case overwrite_backup_safe_comparing
404 atf_add_test_case strip_changing
405 atf_add_test_case strip_changing_comparing
406 atf_add_test_case strip_changing_overwrite
407 atf_add_test_case strip_changing_overwrite_comparing
408 atf_add_test_case strip_changing_overwrite_eq
409 atf_add_test_case strip_changing_overwrite_eq_comparing
410 atf_add_test_case strip_noop
411 atf_add_test_case hard_link
412 atf_add_test_case symbolic_link
413 atf_add_test_case symbolic_link_absolute
414 atf_add_test_case symbolic_link_relative
415 atf_add_test_case symbolic_link_relative_absolute_source_and_dest1
416 atf_add_test_case symbolic_link_relative_absolute_source_and_dest1_double_slash
417 atf_add_test_case symbolic_link_relative_absolute_source_and_dest2
418 atf_add_test_case mkdir_simple