Build: Sync the compile check changes from CMakeLists.txt
[xz/debian.git] / tests / test_scripts.sh
blobca9600ec1fc01c836edf2d5a18e543987baaf490
1 #!/bin/sh
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.
13 XZ=${1:-../src/xz}/xz
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
19 exit 77
20 done
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
29 else
30 echo "Decompression support is disabled, skipping this test."
31 exit 77
34 PATH=`pwd`/${1:-../src/xz}:$PATH
35 export 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
43 status=$?
44 if test "$status" != 0 ; then
45 echo "xzdiff with no changes exited with status $status != 0"
46 exit 1
49 "$XZDIFF" "$preimage" "$otherpostimage" >/dev/null
50 status=$?
51 if test "$status" != 1 ; then
52 echo "xzdiff with changes exited with status $status != 1"
53 exit 1
56 "$XZDIFF" "$preimage" "$srcdir/files/missing.xz" >/dev/null 2>&1
57 status=$?
58 if test "$status" != 2 ; then
59 echo "xzdiff with missing operand exited with status $status != 2"
60 exit 1
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
71 echo retval $?
72 done
73 done > xzgrep_test_output 2>&1
75 if cmp -s "$srcdir/xzgrep_expected_output" xzgrep_test_output ; then
77 else
78 echo "unexpected output from xzgrep"
79 exit 1
82 exit 0