4 # Copyright 2017-2025 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 .
"${srcdir=.}/init.sh"; path_prepend_ ..
/src
23 cat <<'EOF' > exp || fail=1
27 a b differ: char 1, line 1
30 cmp: EOF on
'c' which is empty
33 cmp: d
: No such
file or directory
36 b a differ
: char
1, line
1
41 cmp: EOF on
'c' which is empty
44 cmp: d
: No such
file or directory
47 cmp: EOF on
'c' which is empty
50 cmp: EOF on
'c' which is empty
55 cmp: d
: No such
file or directory
58 cmp: d
: No such
file or directory
61 cmp: d
: No such
file or directory
64 cmp: d
: No such
file or directory
67 cmp: d
: No such
file or directory
75 cmp: EOF on
'c' which is empty
78 cmp: d
: No such
file or directory
86 cmp: EOF on
'c' which is empty
89 cmp: d
: No such
file or directory
92 cmp: EOF on
'c' which is empty
95 cmp: EOF on
'c' which is empty
100 cmp: d
: No such
file or directory
103 cmp: d
: No such
file or directory
106 cmp: d
: No such
file or directory
109 cmp: d
: No such
file or directory
112 cmp: d
: No such
file or directory
153 for option
in '' -l -s; do
156 echo cmp $option $i $j
157 cmp $option $i $j >stdout
2>stderr
165 compare exp out || fail
=1
167 cat <<'EOF' > exp1 || fail=1
169 cmp: EOF on
'a0' which is empty
172 cmp: EOF on
'a1' after byte
2, line
1
175 cmp: EOF on
'a2' after byte
5, in line
2
178 cmp: EOF on
'a0' which is empty
181 cmp: EOF on
'a1' after byte
2
184 cmp: EOF on
'a2' after byte
5
197 printf '1\nfoolery\n' >a3
199 for option
in '' -l -s; do
200 for files
in 'a0 a1' 'a1 a2' 'a2 a3'; do
201 echo cmp $option $files
202 cmp $option $files >stdout
2>stderr
209 compare exp1 out1 || fail
=1
213 echo LC_ALL
=C
cmp -b bad bug
214 LC_ALL
=C
cmp -b bad bug
215 test $?
-eq 1 || fail
=1
216 case `LC_ALL=C cmp -b bad bug` in
217 'bad bug differ: byte 2, line 1 is '*' a '*' u') ;;
218 *) echo 'expected cmp -b to report a and u'; fail
=1;;
221 printf 'Jackdaws love my big sphinx of quartz!' > j1
222 printf 'jackdaws love my big sphinx of quartz.' > j2
223 cat <<'EOF' > exp2 || fail=1
228 test $?
-eq 1 || fail
=1
229 compare exp2 out2 || fail
=1
231 if (LC_ALL
=en_US.iso8859-1 locale charmap
) >/dev
/null
2>&1; then
232 printf '\200\300\377\n' >j3
233 printf '\0@\177\n' >j4
234 cat <<'EOF' >exp3 || fail=1
239 LC_ALL
=en_US.iso8859-1
cmp -bl j3 j4
>out3
240 test $?
-eq 1 || fail
=1
241 compare exp3 out3 || fail
=1
244 big
=99999999999999999999999999999999999999999999999999999999999
245 cmp -i $big j1 j2 || fail
=1
246 cmp -i 1000 -n $big j1 j2 || fail
=1
249 if timeout
0.1 true
&& truncate
-s 14T a
&& truncate
-s 15T b
; then
250 returns_
1 timeout
0.1 cmp a b
>/dev
/null || fail
=1