2 # Test some of cp's options and how cp handles situations in
3 # which a naive implementation might overwrite the source file.
5 if test "$VERBOSE" = yes; then
10 . $srcdir/../lang-default
12 VERSION_CONTROL=numbered; export VERSION_CONTROL
16 trap 'status=$?; cd $pwd; exec 1>&2; rm -rf $tmp && exit $status' 0
17 trap 'exit $?' 1 2 13 15
20 mkdir $tmp || framework_failure=1
21 cd $tmp || framework_failure=1
23 if test $framework_failure = 1; then
24 echo 'failure in testing framework'
33 # FIXME: This should be bigger: like more than 8k
36 for args in 'foo symlink' 'symlink foo' 'foo foo' 'sl1 sl2' 'foo hardlink'; do
37 for options in '' -d -f -df --rem -b -bd -bf -bdf \
38 -l -dl -fl -dfl -bl -bdl -bfl -bdfl; do
40 # These tests are not portable.
41 # They all involve making a hard link to a symbolic link.
59 case "$args" in *symlink*) ln -s foo symlink ;; esac
60 case "$args" in *hardlink*) ln foo hardlink ;; esac
61 case "$args" in *sl1*) ln -s foo sl1;; esac
62 case "$args" in *sl2*) ln -s foo sl2;; esac
65 # echo 1>&2 cp $options $args
66 cp $options $args 2>.err
69 # Normalize the program name in the error output,
70 # and put brackets around the output.
71 test -s .err && echo "[`sed 's/^[^:][^:]*:/cp:/' .err`]"
72 # Strip off all but the file names.
73 ls="`ls -lG --ignore=.err . \
76 -e 's/^...............................................//'`"
78 # Make sure the original is unchanged and that
79 # the destination is a copy.
98 cat <<\EOF > $expected
99 1 [cp: `foo' and `symlink' are the same file] (foo symlink -> foo)
100 1 -d [cp: `foo' and `symlink' are the same file] (foo symlink -> foo)
101 1 -f [cp: `foo' and `symlink' are the same file] (foo symlink -> foo)
102 1 -df [cp: `foo' and `symlink' are the same file] (foo symlink -> foo)
103 0 --rem (foo symlink)
104 0 -b (foo symlink symlink.~1~ -> foo)
105 0 -bd (foo symlink symlink.~1~ -> foo)
106 0 -bf (foo symlink symlink.~1~ -> foo)
107 0 -bdf (foo symlink symlink.~1~ -> foo)
108 0 -l (foo symlink -> foo)
109 0 -dl (foo symlink -> foo)
110 0 -fl (foo symlink -> foo)
112 0 -bl (foo symlink -> foo)
113 0 -bdl (foo symlink symlink.~1~ -> foo)
114 0 -bfl (foo symlink -> foo)
115 0 -bdfl (foo symlink symlink.~1~ -> foo)
117 1 [cp: `symlink' and `foo' are the same file] (foo symlink -> foo)
118 1 -d [cp: `symlink' and `foo' are the same file] (foo symlink -> foo)
119 1 -f [cp: `symlink' and `foo' are the same file] (foo symlink -> foo)
120 1 -df [cp: `symlink' and `foo' are the same file] (foo symlink -> foo)
121 1 --rem [cp: `symlink' and `foo' are the same file] (foo symlink -> foo)
122 1 -b [cp: `symlink' and `foo' are the same file] (foo symlink -> foo)
123 0 -bd (foo -> foo foo.~1~ symlink -> foo) symlink-loop symlink-loop
124 1 -bf [cp: `symlink' and `foo' are the same file] (foo symlink -> foo)
125 0 -bdf (foo -> foo foo.~1~ symlink -> foo) symlink-loop symlink-loop
126 0 -l (foo symlink -> foo)
127 0 -dl (foo symlink -> foo)
128 0 -fl (foo symlink -> foo)
129 0 -bl (foo symlink -> foo)
130 0 -bfl (foo symlink -> foo)
132 1 [cp: `foo' and `foo' are the same file] (foo)
133 1 -d [cp: `foo' and `foo' are the same file] (foo)
134 1 -f [cp: `foo' and `foo' are the same file] (foo)
135 1 -df [cp: `foo' and `foo' are the same file] (foo)
136 1 --rem [cp: `foo' and `foo' are the same file] (foo)
137 1 -b [cp: `foo' and `foo' are the same file] (foo)
138 1 -bd [cp: `foo' and `foo' are the same file] (foo)
148 0 -bdfl (foo foo.~1~)
150 1 [cp: `sl1' and `sl2' are the same file] (foo sl1 -> foo sl2 -> foo)
151 0 -d (foo sl1 -> foo sl2 -> foo)
152 1 -f [cp: `sl1' and `sl2' are the same file] (foo sl1 -> foo sl2 -> foo)
153 0 -df (foo sl1 -> foo sl2 -> foo)
154 0 --rem (foo sl1 -> foo sl2)
155 0 -b (foo sl1 -> foo sl2 sl2.~1~ -> foo)
156 0 -bd (foo sl1 -> foo sl2 -> foo sl2.~1~ -> foo)
157 0 -bf (foo sl1 -> foo sl2 sl2.~1~ -> foo)
158 0 -bdf (foo sl1 -> foo sl2 -> foo sl2.~1~ -> foo)
159 0 -l (foo sl1 -> foo sl2 -> foo)
160 0 -fl (foo sl1 -> foo sl2 -> foo)
161 0 -bl (foo sl1 -> foo sl2 -> foo)
162 0 -bfl (foo sl1 -> foo sl2 -> foo)
164 1 [cp: `foo' and `hardlink' are the same file] (foo hardlink)
165 1 -d [cp: `foo' and `hardlink' are the same file] (foo hardlink)
166 1 -f [cp: `foo' and `hardlink' are the same file] (foo hardlink)
167 1 -df [cp: `foo' and `hardlink' are the same file] (foo hardlink)
168 0 --rem (foo hardlink)
169 0 -b (foo hardlink hardlink.~1~)
170 0 -bd (foo hardlink hardlink.~1~)
171 0 -bf (foo hardlink hardlink.~1~)
172 0 -bdf (foo hardlink hardlink.~1~)
176 0 -dfl (foo hardlink)
178 0 -bdl (foo hardlink)
179 0 -bfl (foo hardlink)
180 0 -bdfl (foo hardlink)
186 # Some folks don't have diff.
187 cmp $expected $actual \
188 || { diff -c $expected $actual 1>&2; fail=1; }