mirror of
https://https.git.savannah.gnu.org/git/diffutils.git
synced 2026-01-31 03:44:57 +00:00
* lib/diagnose.c, lib/diagnose.h: New files. * lib/Makefile.am (noinst_HEADERS, libdiffutils_a_SOURCES): Add them. * po/POTFILES.in: Add lib/diagnose.c. * src/analyze.c, src/cmp.c, src/diff3.c, src/dir.c: * src/sdiff.c, src/util.c: Include diagnose.h. * src/analyze.c (briefly_report, diff_2_files): * src/cmp.c (usage, main, cmp): * src/diff.c (add_regexp, summarize_regexp_list, main, compare_files): * src/diff3.c (usage, process_diff, scan_diff_line): * src/dir.c (diff_dirs): * src/sdiff.c (usage, ck_fopen, main, edit): * src/util.c (perror_with_name, begin_output): Quote file names or regexps with squote. * src/cmp.c, src/diff.c, src/diff3.c, src/dir.c, src/sdiff.c: Include quote.h. * src/cmp.c, src/diff.c, src/diff3.c, src/sdiff.c (try_help): Remove; now in diagnose.c. * src/cmp.c (specify_ignore_initial, main, cmp): * src/diff.c (main, specify_value, specify_colors_style): * src/diff3.c (main, read_diff): * src/dir.c (compare_collated): * src/sdiff.c (check_child_status, main): * src/util.c (finish_output): Quote strings with ‘quote’ or ‘quote_n’. * src/system.h (EXIT_TROUBLE): Remove; now in diagnose.h and now an enum. * src/util.c (c_escape_char, c_escape): Remove, as we now use squote. * tests/cmp, tests/filename-quoting, tests/invalid-re: Adjust to match new behavior.
255 lines
4.2 KiB
Bash
Executable File
255 lines
4.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# Test 'cmp'.
|
|
|
|
# Copyright 2017-2023 Free Software Foundation, Inc.
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
. "${srcdir=.}/init.sh"; path_prepend_ ../src
|
|
|
|
fail=0
|
|
|
|
cat <<'EOF' > exp || fail=1
|
|
cmp a a
|
|
0
|
|
cmp a b
|
|
a b differ: char 1, line 1
|
|
1
|
|
cmp a c
|
|
cmp: EOF on 'c' which is empty
|
|
1
|
|
cmp a d
|
|
cmp: d: No such file or directory
|
|
2
|
|
cmp b a
|
|
b a differ: char 1, line 1
|
|
1
|
|
cmp b b
|
|
0
|
|
cmp b c
|
|
cmp: EOF on 'c' which is empty
|
|
1
|
|
cmp b d
|
|
cmp: d: No such file or directory
|
|
2
|
|
cmp c a
|
|
cmp: EOF on 'c' which is empty
|
|
1
|
|
cmp c b
|
|
cmp: EOF on 'c' which is empty
|
|
1
|
|
cmp c c
|
|
0
|
|
cmp c d
|
|
cmp: d: No such file or directory
|
|
2
|
|
cmp d a
|
|
cmp: d: No such file or directory
|
|
2
|
|
cmp d b
|
|
cmp: d: No such file or directory
|
|
2
|
|
cmp d c
|
|
cmp: d: No such file or directory
|
|
2
|
|
cmp d d
|
|
cmp: d: No such file or directory
|
|
2
|
|
cmp -l a a
|
|
0
|
|
cmp -l a b
|
|
1 141 142
|
|
1
|
|
cmp -l a c
|
|
cmp: EOF on 'c' which is empty
|
|
1
|
|
cmp -l a d
|
|
cmp: d: No such file or directory
|
|
2
|
|
cmp -l b a
|
|
1 142 141
|
|
1
|
|
cmp -l b b
|
|
0
|
|
cmp -l b c
|
|
cmp: EOF on 'c' which is empty
|
|
1
|
|
cmp -l b d
|
|
cmp: d: No such file or directory
|
|
2
|
|
cmp -l c a
|
|
cmp: EOF on 'c' which is empty
|
|
1
|
|
cmp -l c b
|
|
cmp: EOF on 'c' which is empty
|
|
1
|
|
cmp -l c c
|
|
0
|
|
cmp -l c d
|
|
cmp: d: No such file or directory
|
|
2
|
|
cmp -l d a
|
|
cmp: d: No such file or directory
|
|
2
|
|
cmp -l d b
|
|
cmp: d: No such file or directory
|
|
2
|
|
cmp -l d c
|
|
cmp: d: No such file or directory
|
|
2
|
|
cmp -l d d
|
|
cmp: d: No such file or directory
|
|
2
|
|
cmp -s a a
|
|
0
|
|
cmp -s a b
|
|
1
|
|
cmp -s a c
|
|
1
|
|
cmp -s a d
|
|
2
|
|
cmp -s b a
|
|
1
|
|
cmp -s b b
|
|
0
|
|
cmp -s b c
|
|
1
|
|
cmp -s b d
|
|
2
|
|
cmp -s c a
|
|
1
|
|
cmp -s c b
|
|
1
|
|
cmp -s c c
|
|
0
|
|
cmp -s c d
|
|
2
|
|
cmp -s d a
|
|
2
|
|
cmp -s d b
|
|
2
|
|
cmp -s d c
|
|
2
|
|
cmp -s d d
|
|
2
|
|
EOF
|
|
|
|
echo a >a
|
|
echo b >b
|
|
: >c
|
|
rm -f d
|
|
|
|
for option in '' -l -s; do
|
|
for i in a b c d; do
|
|
for j in a b c d; do
|
|
echo cmp $option $i $j
|
|
cmp $option $i $j >stdout 2>stderr
|
|
status=$?
|
|
cat stderr stdout
|
|
echo $status
|
|
done
|
|
done
|
|
done >out
|
|
|
|
compare exp out || fail=1
|
|
|
|
cat <<'EOF' > exp1 || fail=1
|
|
cmp a0 a1
|
|
cmp: EOF on 'a0' which is empty
|
|
1
|
|
cmp a1 a2
|
|
cmp: EOF on 'a1' after byte 2, line 1
|
|
1
|
|
cmp a2 a3
|
|
cmp: EOF on 'a2' after byte 5, in line 2
|
|
1
|
|
cmp -l a0 a1
|
|
cmp: EOF on 'a0' which is empty
|
|
1
|
|
cmp -l a1 a2
|
|
cmp: EOF on 'a1' after byte 2
|
|
1
|
|
cmp -l a2 a3
|
|
cmp: EOF on 'a2' after byte 5
|
|
1
|
|
cmp -s a0 a1
|
|
1
|
|
cmp -s a1 a2
|
|
1
|
|
cmp -s a2 a3
|
|
1
|
|
EOF
|
|
|
|
printf '' >a0
|
|
printf '1\n' >a1
|
|
printf '1\nfoo' >a2
|
|
printf '1\nfoolery\n' >a3
|
|
|
|
for option in '' -l -s; do
|
|
for files in 'a0 a1' 'a1 a2' 'a2 a3'; do
|
|
echo cmp $option $files
|
|
cmp $option $files >stdout 2>stderr
|
|
status=$?
|
|
cat stderr stdout
|
|
echo $status
|
|
done
|
|
done >out1
|
|
|
|
compare exp1 out1 || fail=1
|
|
|
|
printf 'bad\n' >bad
|
|
printf 'bug\n' >bug
|
|
echo LC_ALL=C cmp -b bad bug
|
|
LC_ALL=C cmp -b bad bug
|
|
test $? -eq 1 || fail=1
|
|
case `LC_ALL=C cmp -b bad bug` in
|
|
'bad bug differ: byte 2, line 1 is '*' a '*' u') ;;
|
|
*) echo 'expected cmp -b to report a and u'; fail=1;;
|
|
esac
|
|
|
|
printf 'Jackdaws love my big sphinx of quartz!' > j1
|
|
printf 'jackdaws love my big sphinx of quartz.' > j2
|
|
cat <<'EOF' > exp2 || fail=1
|
|
1 112 J 152 j
|
|
38 41 ! 56 .
|
|
EOF
|
|
cmp -bl j1 j2 > out2
|
|
test $? -eq 1 || fail=1
|
|
compare exp2 out2 || fail=1
|
|
|
|
if (LC_ALL=en_US.iso8859-1 locale charmap) >/dev/null 2>&1; then
|
|
printf '\200\300\377\n' >j3
|
|
printf '\0@\177\n' >j4
|
|
cat <<'EOF' >exp3 || fail=1
|
|
1 200 M-^@ 0 ^@
|
|
2 300 M-@ 100 @
|
|
3 377 M-^? 177 ^?
|
|
EOF
|
|
LC_ALL=en_US.iso8859-1 cmp -bl j3 j4 >out3
|
|
test $? -eq 1 || fail=1
|
|
compare exp3 out3 || fail=1
|
|
fi
|
|
|
|
big=99999999999999999999999999999999999999999999999999999999999
|
|
cmp -i $big j1 j2 || fail=1
|
|
cmp -i 1000 -n $big j1 j2 || fail=1
|
|
|
|
rm -f a b
|
|
if timeout 0.1 true && truncate -s 14T a && truncate -s 15T b; then
|
|
returns_ 1 timeout 0.1 cmp a b >/dev/null || fail=1
|
|
fi
|
|
rm -f a b
|
|
|
|
Exit $fail
|