2 # SPDX-License-Identifier: 0BSD
4 ###############################################################################
6 # Author: Jonathan Nieder
8 ###############################################################################
10 # If scripts weren't built, this test is skipped.
11 # When this is run from CMake, $1 is a relative path
12 # to the directory with the executables and the scripts.
14 XZDIFF
=${1:-../src/scripts}/xzdiff
15 XZGREP
=${1:-../src/scripts}/xzgrep
17 for i
in XZ XZDIFF XZGREP
; do
18 eval test -x "\$$i" && continue
22 # If decompression support is missing, this test is skipped.
23 # Installing the scripts in this case is a bit silly but they
24 # could still be used with other decompression tools so configure
25 # doesn't automatically disable scripts if decoders are disabled.
26 if test ! -f ..
/config.h \
27 ||
grep 'define HAVE_DECODERS' ..
/config.h
> /dev
/null
; then
30 echo "Decompression support is disabled, skipping this test."
34 PATH
=`pwd`/${1:-../src/xz}:$PATH
37 test -z "$srcdir" && srcdir
=.
38 preimage
=$srcdir/files
/good-1-check-crc32.xz
39 samepostimage
=$srcdir/files
/good-1-check-crc64.xz
40 otherpostimage
=$srcdir/files
/good-1-lzma2-1.xz
42 "$XZDIFF" "$preimage" "$samepostimage" >/dev
/null
44 if test "$status" != 0 ; then
45 echo "xzdiff with no changes exited with status $status != 0"
49 "$XZDIFF" "$preimage" "$otherpostimage" >/dev
/null
51 if test "$status" != 1 ; then
52 echo "xzdiff with changes exited with status $status != 1"
56 "$XZDIFF" "$preimage" "$srcdir/files/missing.xz" >/dev
/null
2>&1
58 if test "$status" != 2 ; then
59 echo "xzdiff with missing operand exited with status $status != 2"
63 # The exit status must be 0 when a match was found at least from one file,
64 # and 1 when no match was found in any file.
65 cp "$srcdir/files/good-1-lzma2-1.xz" xzgrep_test_1.xz
66 cp "$srcdir/files/good-2-lzma2.xz" xzgrep_test_2.xz
67 for pattern
in el Hello NOMATCH
; do
68 for opts
in "" "-l" "-h" "-H"; do
69 echo "=> xzgrep $opts $pattern <="
70 "$XZGREP" $opts $pattern xzgrep_test_1.xz xzgrep_test_2.xz
73 done > xzgrep_test_output
2>&1
75 if cmp -s "$srcdir/xzgrep_expected_output" xzgrep_test_output
; then
78 echo "unexpected output from xzgrep"