3 [ -f testing.sh ] && . testing.sh
6 dd if=/dev/urandom of=random bs=64 count=1 2> /dev/null
8 #testing "name" "command" "result" "infile" "stdin"
10 testing "not enough arguments [fail]" "cp one 2>/dev/null || echo yes" \
12 testing "-missing source [fail]" "cp missing two 2>/dev/null || echo yes" \
14 testing "file->file" "cp random two && cmp random two && echo yes" \
19 testing "file->dir" "cp random two && cmp random two/random && echo yes" \
22 testing "file->dir/file" \
23 "cp random two/random && cmp random two/random && echo yes" \
25 testing "-r dir->missing" \
26 "cp -r two three && cmp random three/random && echo yes" \
29 testing "-r dir->file [fail]" \
30 "cp -r two walrus 2>/dev/null || echo yes" "yes\n" "" ""
32 testing "-r dir hits file." \
33 "cp -r three two 2>/dev/null || echo yes" "yes\n" "" ""
34 rm -rf two three walrus
38 testing "file->inaccessable [fail]" \
39 "cp random two 2>/dev/null || echo yes" "yes\n" "" ""
44 testing "-f file->inaccessable" \
45 "cp -f random two && cmp random two && echo yes" "yes\n" "" ""
48 testing "file->inaccessable_dir [fail]" \
49 "cp random sub 2>/dev/null || echo yes" "yes\n" "" ""
53 # This test fails because our -rf deletes existing target files without
54 # regard to what we'd be copying over it. Posix says to only do that if
55 # we'd be copying a file over the file, but does not say _why_.
59 #testing "-rf dir file [fail]" "cp -rf dir file 2>/dev/null || echo yes" \
64 testing "file1 file2 missing [fail]" \
65 "cp one two missing 2>/dev/null || echo yes" "yes\n" "" ""
67 testing "dir file missing [fail]" \
68 "cp dir two missing 2>/dev/null || echo yes" "yes\n" "" ""
69 testing "-rf dir file missing [fail]" \
70 "cp dir two missing 2>/dev/null || echo yes" "yes\n" "" ""
71 testing "file1 file2 file [fail]" \
72 "cp random one two 2>/dev/null || echo yes" "yes\n" "" ""
73 testing "file1 file2 dir" \
74 "cp random one dir && cmp random dir/random && cmp one dir/one && echo yes" \
79 mkdir -p one/two/three/four
80 touch one/two/three/five
81 touch one/{six,seven,eight}
82 testing "-r /abspath dest" \
83 "cp -r \"$(readlink -f one)\" dir && diff -r one dir && echo yes" \
85 testing "-r dir again" "cp -r one/. dir && diff -r one dir && echo yes" \
88 testing "-r dir1/* dir2" \
89 "cp -r one/* dir2 && diff -r one dir2 && echo yes" "yes\n" "" ""
92 # cp -r ../source destdir
93 # cp -r one/two/three missing
94 # cp -r one/two/three two
95 # mkdir one; touch one/two; ln -s two one/three
97 # cp file1 missing file2 -> dir
99 # Make sure it's truncating existing file
100 # copy with -d at top level, with -d in directory, without -d at top level,
101 # without -d in directory