2 # Test some of cp's options and how cp handles situations in
3 # which a naive implementation might overwrite the source file.
5 # Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2006 Free Software
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 if test "$VERBOSE" = yes; then
28 . $srcdir/../lang-default
29 . $srcdir/../envvar-check
31 # Unset CDPATH. Otherwise, output from the `cd dir' command
32 # can make this test fail.
33 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
35 VERSION_CONTROL=numbered; export VERSION_CONTROL
38 t0=`echo "$0"|sed 's,.*/,,'`.tmp;tmp=$t0/$$
39 trap 'status=$?; cd "$pwd" && exec 1>&2; rm -rf $t0 && exit $status' 0
40 trap 'exit $?' 1 2 13 15
43 mkdir -p $tmp || framework_failure=1
44 cd $tmp || framework_failure=1
46 if test $framework_failure = 1; then
47 echo 'failure in testing framework'
56 # FIXME: This should be bigger: like more than 8k
59 for args in 'foo symlink' 'symlink foo' 'foo foo' 'sl1 sl2' 'foo hardlink'; do
60 for options in '' -d -f -df --rem -b -bd -bf -bdf \
61 -l -dl -fl -dfl -bl -bdl -bfl -bdfl; do
63 # These tests are not portable.
64 # They all involve making a hard link to a symbolic link.
82 case "$args" in *symlink*) ln -s foo symlink ;; esac
83 case "$args" in *hardlink*) ln foo hardlink ;; esac
84 case "$args" in *sl1*) ln -s foo sl1;; esac
85 case "$args" in *sl2*) ln -s foo sl2;; esac
88 # echo 1>&2 cp $options $args
89 cp $options $args 2>_err
92 # Normalize the program name in the error output,
93 # and put brackets around the output.
94 test -s _err && echo "[`sed 's/^[^:][^:]*:/cp:/' _err`]"
95 # Strip off all but the file names.
96 ls="`ls -gG --ignore=_err . \
99 -e 's/^[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *//'`"
101 # Make sure the original is unchanged and that
102 # the destination is a copy.
121 cat <<\EOF > $expected
122 1 [cp: `foo' and `symlink' are the same file] (foo symlink -> foo)
123 1 -d [cp: `foo' and `symlink' are the same file] (foo symlink -> foo)
124 1 -f [cp: `foo' and `symlink' are the same file] (foo symlink -> foo)
125 1 -df [cp: `foo' and `symlink' are the same file] (foo symlink -> foo)
126 0 --rem (foo symlink)
127 0 -b (foo symlink symlink.~1~ -> foo)
128 0 -bd (foo symlink symlink.~1~ -> foo)
129 0 -bf (foo symlink symlink.~1~ -> foo)
130 0 -bdf (foo symlink symlink.~1~ -> foo)
131 0 -l (foo symlink -> foo)
132 0 -dl (foo symlink -> foo)
133 0 -fl (foo symlink -> foo)
135 0 -bl (foo symlink -> foo)
136 0 -bdl (foo symlink symlink.~1~ -> foo)
137 0 -bfl (foo symlink -> foo)
138 0 -bdfl (foo symlink symlink.~1~ -> foo)
140 1 [cp: `symlink' and `foo' are the same file] (foo symlink -> foo)
141 1 -d [cp: `symlink' and `foo' are the same file] (foo symlink -> foo)
142 1 -f [cp: `symlink' and `foo' are the same file] (foo symlink -> foo)
143 1 -df [cp: `symlink' and `foo' are the same file] (foo symlink -> foo)
144 1 --rem [cp: `symlink' and `foo' are the same file] (foo symlink -> foo)
145 1 -b [cp: `symlink' and `foo' are the same file] (foo symlink -> foo)
146 0 -bd (foo -> foo foo.~1~ symlink -> foo) symlink-loop symlink-loop
147 1 -bf [cp: `symlink' and `foo' are the same file] (foo symlink -> foo)
148 0 -bdf (foo -> foo foo.~1~ symlink -> foo) symlink-loop symlink-loop
149 0 -l (foo symlink -> foo)
150 0 -dl (foo symlink -> foo)
151 0 -fl (foo symlink -> foo)
152 0 -bl (foo symlink -> foo)
153 0 -bfl (foo symlink -> foo)
155 1 [cp: `foo' and `foo' are the same file] (foo)
156 1 -d [cp: `foo' and `foo' are the same file] (foo)
157 1 -f [cp: `foo' and `foo' are the same file] (foo)
158 1 -df [cp: `foo' and `foo' are the same file] (foo)
159 1 --rem [cp: `foo' and `foo' are the same file] (foo)
160 1 -b [cp: `foo' and `foo' are the same file] (foo)
161 1 -bd [cp: `foo' and `foo' are the same file] (foo)
171 0 -bdfl (foo foo.~1~)
173 1 [cp: `sl1' and `sl2' are the same file] (foo sl1 -> foo sl2 -> foo)
174 0 -d (foo sl1 -> foo sl2 -> foo)
175 1 -f [cp: `sl1' and `sl2' are the same file] (foo sl1 -> foo sl2 -> foo)
176 0 -df (foo sl1 -> foo sl2 -> foo)
177 0 --rem (foo sl1 -> foo sl2)
178 0 -b (foo sl1 -> foo sl2 sl2.~1~ -> foo)
179 0 -bd (foo sl1 -> foo sl2 -> foo sl2.~1~ -> foo)
180 0 -bf (foo sl1 -> foo sl2 sl2.~1~ -> foo)
181 0 -bdf (foo sl1 -> foo sl2 -> foo sl2.~1~ -> foo)
182 0 -l (foo sl1 -> foo sl2 -> foo)
183 0 -fl (foo sl1 -> foo sl2 -> foo)
184 0 -bl (foo sl1 -> foo sl2 -> foo)
185 0 -bfl (foo sl1 -> foo sl2 -> foo)
187 1 [cp: `foo' and `hardlink' are the same file] (foo hardlink)
188 1 -d [cp: `foo' and `hardlink' are the same file] (foo hardlink)
189 1 -f [cp: `foo' and `hardlink' are the same file] (foo hardlink)
190 1 -df [cp: `foo' and `hardlink' are the same file] (foo hardlink)
191 0 --rem (foo hardlink)
192 0 -b (foo hardlink hardlink.~1~)
193 0 -bd (foo hardlink hardlink.~1~)
194 0 -bf (foo hardlink hardlink.~1~)
195 0 -bdf (foo hardlink hardlink.~1~)
199 0 -dfl (foo hardlink)
201 0 -bdl (foo hardlink)
202 0 -bfl (foo hardlink)
203 0 -bdfl (foo hardlink)
209 # Some folks don't have diff.
210 cmp $expected $actual \
211 || { diff -c $expected $actual 1>&2; fail=1; }
213 (exit $fail); exit $fail