]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
CMake: Add test_scripts.sh to the tests.
authorLasse Collin <lasse.collin@tukaani.org>
Sat, 17 Feb 2024 13:35:35 +0000 (15:35 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Mon, 19 Feb 2024 10:21:37 +0000 (12:21 +0200)
In contrast to Automake, skipping of this test when decoders
are disabled is handled at CMake side instead of test_scripts.sh
because CMake-build doesn't create config.h.

CMakeLists.txt
tests/test_scripts.sh

index 57013fa2576d53c27dce3e5c1fcd6b48dd86607f..fae52cd186e76f94ec79ede46b238c28dc48e705 100644 (file)
@@ -1803,4 +1803,18 @@ if(BUILD_TESTING)
             SKIP_RETURN_CODE 77
         )
     endforeach()
+
+    if(UNIX AND HAVE_DECODERS)
+        file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test_scripts")
+
+        add_test(NAME test_scripts.sh
+            COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_scripts.sh" ".."
+            WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test_scripts"
+        )
+
+        set_tests_properties(test_scripts.sh PROPERTIES
+            ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}/tests"
+            SKIP_RETURN_CODE 77
+        )
+    endif()
 endif()
index 9b9384664f2d5601fbc47122fe8075493625979c..ca9600ec1fc01c836edf2d5a18e543987baaf490 100755 (executable)
@@ -8,9 +8,11 @@
 ###############################################################################
 
 # If scripts weren't built, this test is skipped.
-XZ=../src/xz/xz
-XZDIFF=../src/scripts/xzdiff
-XZGREP=../src/scripts/xzgrep
+# When this is run from CMake, $1 is a relative path
+# to the directory with the executables and the scripts.
+XZ=${1:-../src/xz}/xz
+XZDIFF=${1:-../src/scripts}/xzdiff
+XZGREP=${1:-../src/scripts}/xzgrep
 
 for i in XZ XZDIFF XZGREP; do
        eval test -x "\$$i" && continue
@@ -21,14 +23,15 @@ done
 # Installing the scripts in this case is a bit silly but they
 # could still be used with other decompression tools so configure
 # doesn't automatically disable scripts if decoders are disabled.
-if grep 'define HAVE_DECODERS' ../config.h > /dev/null ; then
+if test ! -f ../config.h \
+               || grep 'define HAVE_DECODERS' ../config.h > /dev/null ; then
        :
 else
        echo "Decompression support is disabled, skipping this test."
        exit 77
 fi
 
-PATH=`pwd`/../src/xz:$PATH
+PATH=`pwd`/${1:-../src/xz}:$PATH
 export PATH
 
 test -z "$srcdir" && srcdir=.