Denys Vlasenko | a40f062 | 2010-01-15 22:05:07 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright 2010 by Denys Vlasenko |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 3 | # Licensed under GPLv2, see file LICENSE in this source tree. |
Denys Vlasenko | a40f062 | 2010-01-15 22:05:07 +0100 | [diff] [blame] | 4 | |
| 5 | . ./testing.sh |
| 6 | |
| 7 | # Opening quote in "omitting directory 'dir'" message: |
| 8 | sq='`' # GNU cp: ` |
| 9 | sq="'" # bbox cp: ' |
| 10 | |
| 11 | rm -rf cp.testdir >/dev/null |
| 12 | |
| 13 | mkdir cp.testdir |
| 14 | mkdir cp.testdir/dir |
| 15 | > cp.testdir/dir/file |
| 16 | ln -s file cp.testdir/dir/file_symlink |
| 17 | |
| 18 | > cp.testdir/file |
| 19 | ln -s file cp.testdir/file_symlink |
| 20 | ln -s dir cp.testdir/dir_symlink |
| 21 | |
| 22 | |
| 23 | # testing "test name" "command" "expected result" "file input" "stdin" |
| 24 | |
| 25 | rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1 |
| 26 | testing "cp" '\ |
Denys Vlasenko | 1e9bc26 | 2010-01-16 02:27:31 +0100 | [diff] [blame] | 27 | cd cp.testdir || exit 1; cp * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1 |
| 28 | test ! -L file && test -f file || echo BAD: file |
| 29 | test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink |
| 30 | test ! -L dir && test ! -e dir || echo BAD: dir |
| 31 | test ! -L dir_symlink && test ! -e dir_symlink || echo BAD: dir_symlink |
Denys Vlasenko | a40f062 | 2010-01-15 22:05:07 +0100 | [diff] [blame] | 32 | ' "\ |
| 33 | cp: omitting directory ${sq}dir' |
| 34 | cp: omitting directory ${sq}dir_symlink' |
| 35 | 1 |
| 36 | " "" "" |
| 37 | |
| 38 | rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1 |
| 39 | testing "cp -d" '\ |
Denys Vlasenko | 1e9bc26 | 2010-01-16 02:27:31 +0100 | [diff] [blame] | 40 | cd cp.testdir || exit 1; cp -d * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1 |
| 41 | test ! -L file && test -f file || echo BAD: file |
| 42 | test -L file_symlink && test -f file_symlink || echo BAD: file_symlink |
| 43 | test ! -L dir && test ! -e dir || echo BAD: dir |
| 44 | test -L dir_symlink && test ! -e dir_symlink || echo BAD: dir_symlink |
Denys Vlasenko | a40f062 | 2010-01-15 22:05:07 +0100 | [diff] [blame] | 45 | ' "\ |
| 46 | cp: omitting directory ${sq}dir' |
| 47 | 1 |
| 48 | " "" "" |
| 49 | |
| 50 | rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1 |
| 51 | testing "cp -P" '\ |
Denys Vlasenko | 1e9bc26 | 2010-01-16 02:27:31 +0100 | [diff] [blame] | 52 | cd cp.testdir || exit 1; cp -P * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1 |
| 53 | test ! -L file && test -f file || echo BAD: file |
| 54 | test -L file_symlink && test -f file_symlink || echo BAD: file_symlink |
| 55 | test ! -L dir && test ! -e dir || echo BAD: dir |
| 56 | test -L dir_symlink && test ! -e dir_symlink || echo BAD: dir_symlink |
Denys Vlasenko | a40f062 | 2010-01-15 22:05:07 +0100 | [diff] [blame] | 57 | ' "\ |
| 58 | cp: omitting directory ${sq}dir' |
| 59 | 1 |
| 60 | " "" "" |
| 61 | |
| 62 | rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1 |
| 63 | testing "cp -L" '\ |
Denys Vlasenko | 1e9bc26 | 2010-01-16 02:27:31 +0100 | [diff] [blame] | 64 | cd cp.testdir || exit 1; cp -L * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1 |
| 65 | test ! -L file && test -f file || echo BAD: file |
| 66 | test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink |
| 67 | test ! -L dir && test ! -e dir || echo BAD: dir |
| 68 | test ! -L dir_symlink && test ! -e dir_symlink || echo BAD: dir_symlink |
Denys Vlasenko | a40f062 | 2010-01-15 22:05:07 +0100 | [diff] [blame] | 69 | ' "\ |
| 70 | cp: omitting directory ${sq}dir' |
| 71 | cp: omitting directory ${sq}dir_symlink' |
| 72 | 1 |
| 73 | " "" "" |
| 74 | |
| 75 | rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1 |
| 76 | testing "cp -H" '\ |
Denys Vlasenko | 1e9bc26 | 2010-01-16 02:27:31 +0100 | [diff] [blame] | 77 | cd cp.testdir || exit 1; cp -H * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1 |
| 78 | test ! -L file && test -f file || echo BAD: file |
| 79 | test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink |
| 80 | test ! -L dir && test ! -e dir || echo BAD: dir |
| 81 | test ! -L dir_symlink && test ! -e dir_symlink || echo BAD: dir_symlink |
Denys Vlasenko | a40f062 | 2010-01-15 22:05:07 +0100 | [diff] [blame] | 82 | ' "\ |
| 83 | cp: omitting directory ${sq}dir' |
| 84 | cp: omitting directory ${sq}dir_symlink' |
| 85 | 1 |
| 86 | " "" "" |
| 87 | |
| 88 | rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1 |
| 89 | testing "cp -R" '\ |
Denys Vlasenko | 1e9bc26 | 2010-01-16 02:27:31 +0100 | [diff] [blame] | 90 | cd cp.testdir || exit 1; cp -R * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1 |
| 91 | test ! -L file && test -f file || echo BAD: file |
| 92 | test -L file_symlink && test -f file_symlink || echo BAD: file_symlink |
| 93 | test ! -L dir && test -d dir || echo BAD: dir |
| 94 | test -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink |
| 95 | test ! -L dir/file && test -f dir/file || echo BAD: dir/file |
| 96 | test -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink |
Denys Vlasenko | a40f062 | 2010-01-15 22:05:07 +0100 | [diff] [blame] | 97 | ' "\ |
| 98 | 0 |
| 99 | " "" "" |
| 100 | |
| 101 | rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1 |
| 102 | testing "cp -Rd" '\ |
Denys Vlasenko | 1e9bc26 | 2010-01-16 02:27:31 +0100 | [diff] [blame] | 103 | cd cp.testdir || exit 1; cp -Rd * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1 |
| 104 | test ! -L file && test -f file || echo BAD: file |
| 105 | test -L file_symlink && test -f file_symlink || echo BAD: file_symlink |
| 106 | test ! -L dir && test -d dir || echo BAD: dir |
| 107 | test -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink |
| 108 | test ! -L dir/file && test -f dir/file || echo BAD: dir/file |
| 109 | test -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink |
Denys Vlasenko | a40f062 | 2010-01-15 22:05:07 +0100 | [diff] [blame] | 110 | ' "\ |
| 111 | 0 |
| 112 | " "" "" |
| 113 | |
| 114 | rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1 |
| 115 | testing "cp -RP" '\ |
Denys Vlasenko | 1e9bc26 | 2010-01-16 02:27:31 +0100 | [diff] [blame] | 116 | cd cp.testdir || exit 1; cp -RP * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1 |
| 117 | test ! -L file && test -f file || echo BAD: file |
| 118 | test -L file_symlink && test -f file_symlink || echo BAD: file_symlink |
| 119 | test ! -L dir && test -d dir || echo BAD: dir |
| 120 | test -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink |
| 121 | test ! -L dir/file && test -f dir/file || echo BAD: dir/file |
| 122 | test -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink |
Denys Vlasenko | a40f062 | 2010-01-15 22:05:07 +0100 | [diff] [blame] | 123 | ' "\ |
| 124 | 0 |
| 125 | " "" "" |
| 126 | |
| 127 | rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1 |
| 128 | testing "cp -RL" '\ |
Denys Vlasenko | 1e9bc26 | 2010-01-16 02:27:31 +0100 | [diff] [blame] | 129 | cd cp.testdir || exit 1; cp -RL * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1 |
| 130 | test ! -L file && test -f file || echo BAD: file |
| 131 | test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink |
| 132 | test ! -L dir && test -d dir || echo BAD: dir |
| 133 | test ! -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink |
| 134 | test ! -L dir/file && test -f dir/file || echo BAD: dir/file |
| 135 | test ! -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink |
Denys Vlasenko | a40f062 | 2010-01-15 22:05:07 +0100 | [diff] [blame] | 136 | ' "\ |
| 137 | 0 |
| 138 | " "" "" |
| 139 | |
| 140 | rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1 |
| 141 | # GNU coreutils 7.2 says: |
| 142 | # cp: will not create hard link `../cp.testdir2/dir_symlink' to directory `../cp.testdir2/dir' |
| 143 | test x"$SKIP_KNOWN_BUGS" = x"" && \ |
| 144 | testing "cp -RH" '\ |
Denys Vlasenko | 1e9bc26 | 2010-01-16 02:27:31 +0100 | [diff] [blame] | 145 | cd cp.testdir || exit 1; cp -RH * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1 |
| 146 | test ! -L file && test -f file || echo BAD: file |
| 147 | test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink |
| 148 | test ! -L dir && test -d dir || echo BAD: dir |
| 149 | test ! -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink |
| 150 | test ! -L dir/file && test -f dir/file || echo BAD: dir/file |
| 151 | test -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink |
Denys Vlasenko | a40f062 | 2010-01-15 22:05:07 +0100 | [diff] [blame] | 152 | ' "\ |
| 153 | 0 |
| 154 | " "" "" |
| 155 | |
| 156 | rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1 |
| 157 | # GNU coreutils 7.2 says: |
| 158 | # cp: will not create hard link `../cp.testdir2/dir_symlink' to directory `../cp.testdir2/dir' |
| 159 | test x"$SKIP_KNOWN_BUGS" = x"" && \ |
| 160 | testing "cp -RHP" '\ |
Denys Vlasenko | 1e9bc26 | 2010-01-16 02:27:31 +0100 | [diff] [blame] | 161 | cd cp.testdir || exit 1; cp -RHP * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1 |
| 162 | test ! -L file && test -f file || echo BAD: file |
| 163 | test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink |
| 164 | test ! -L dir && test -d dir || echo BAD: dir |
| 165 | test ! -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink |
| 166 | test ! -L dir/file && test -f dir/file || echo BAD: dir/file |
| 167 | test -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink |
Denys Vlasenko | a40f062 | 2010-01-15 22:05:07 +0100 | [diff] [blame] | 168 | ' "\ |
| 169 | 0 |
| 170 | " "" "" |
| 171 | |
| 172 | rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1 |
| 173 | testing "cp -RHL" '\ |
Denys Vlasenko | 1e9bc26 | 2010-01-16 02:27:31 +0100 | [diff] [blame] | 174 | cd cp.testdir || exit 1; cp -RHL * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1 |
| 175 | test ! -L file && test -f file || echo BAD: file |
| 176 | test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink |
| 177 | test ! -L dir && test -d dir || echo BAD: dir |
| 178 | test ! -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink |
| 179 | test ! -L dir/file && test -f dir/file || echo BAD: dir/file |
| 180 | test ! -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink |
Denys Vlasenko | a40f062 | 2010-01-15 22:05:07 +0100 | [diff] [blame] | 181 | ' "\ |
| 182 | 0 |
| 183 | " "" "" |
| 184 | |
| 185 | rm -rf cp.testdir2 >/dev/null && mkdir cp.testdir2 || exit 1 |
| 186 | # Wow! "cp -RLH" is not the same as "cp -RHL" (prev test)! |
| 187 | # GNU coreutils 7.2 says: |
| 188 | # cp: will not create hard link `../cp.testdir2/dir_symlink' to directory `../cp.testdir2/dir' |
| 189 | test x"$SKIP_KNOWN_BUGS" = x"" && \ |
| 190 | testing "cp -RLH" '\ |
Denys Vlasenko | 1e9bc26 | 2010-01-16 02:27:31 +0100 | [diff] [blame] | 191 | cd cp.testdir || exit 1; cp -RLH * ../cp.testdir2 2>&1; echo $?; cd ../cp.testdir2 || exit 1 |
| 192 | test ! -L file && test -f file || echo BAD: file |
| 193 | test ! -L file_symlink && test -f file_symlink || echo BAD: file_symlink |
| 194 | test ! -L dir && test -d dir || echo BAD: dir |
| 195 | test ! -L dir_symlink && test -d dir_symlink || echo BAD: dir_symlink |
| 196 | test ! -L dir/file && test -f dir/file || echo BAD: dir/file |
| 197 | test ! -L dir/file_symlink && test -f dir/file_symlink || echo BAD: dir/file_symlink |
Denys Vlasenko | a40f062 | 2010-01-15 22:05:07 +0100 | [diff] [blame] | 198 | ' "\ |
| 199 | 0 |
| 200 | " "" "" |
| 201 | |
| 202 | |
| 203 | # Clean up |
| 204 | rm -rf cp.testdir cp.testdir2 2>/dev/null |
| 205 | |
| 206 | exit $FAILCOUNT |