]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
Tests: Add new test for xz -r, --recursive option. xz_recursive2
authorJia Tan <jiat0218@gmail.com>
Thu, 9 Nov 2023 15:47:03 +0000 (23:47 +0800)
committerJia Tan <jiat0218@gmail.com>
Mon, 29 Jan 2024 13:50:14 +0000 (21:50 +0800)
tests/Makefile.am
tests/test_recursive.sh [new file with mode: 0755]

index 8a0ec53ec24c896c520f3309f69ca91f010f29de..baf1c051cf22eb39bef56fcf630dcdad1259ec5b 100644 (file)
@@ -11,6 +11,7 @@ EXTRA_DIST = \
        tuktest.h \
        tests.h \
        test_files.sh \
+       test_recursive.sh \
        test_compress.sh \
        test_compress_prepared_bcj_sparc \
        test_compress_prepared_bcj_x86 \
@@ -62,6 +63,7 @@ TESTS = \
        test_lzip_decoder \
        test_vli \
        test_files.sh \
+       test_recursive.sh \
        test_suffix.sh \
        test_compress_prepared_bcj_sparc \
        test_compress_prepared_bcj_x86 \
diff --git a/tests/test_recursive.sh b/tests/test_recursive.sh
new file mode 100755 (executable)
index 0000000..b4e4a10
--- /dev/null
@@ -0,0 +1,87 @@
+#!/bin/sh
+
+###############################################################################
+#
+# Author: Jia Tan
+#
+# This file has been put into the public domain.
+# You can do whatever you want with this file.
+#
+###############################################################################
+
+# If xz wasn't built, this test is skipped.
+XZ="../src/xz/xz"
+if test -x "$XZ" ; then
+       :
+else
+       echo "xz was not built, skipping this test $XZ"
+       exit 77
+fi
+
+# If decompression support is missing, this test is skipped.
+if grep 'define HAVE_DECODERS' ../config.h > /dev/null ; then
+       :
+else
+       echo "Decompression support is disabled, skipping this test."
+       exit 77
+fi
+
+# Setup nested directory structure, but first
+# delete it first if it already exists
+rm -rf xz_recursive_level_one
+
+mkdir -p xz_recursive_level_one/level_two/level_three
+
+FILES="file_one "\
+"file_two "\
+"level_two/file_one "\
+"level_two/file_two "\
+"level_two/level_three/file_one "\
+"level_two/level_three/file_two "
+
+for FILE in $FILES
+do
+       cp "$srcdir/files/good-0-empty.xz" "xz_recursive_level_one/$FILE.xz"
+done
+
+# Decompress with -r, --recursive option
+if "$XZ" -dr xz_recursive_level_one; then
+       :
+else
+       echo "Recursive decompression failed: $*"
+       exit 1
+fi
+
+# Verify the files were all decompressed.
+for FILE in $FILES
+do
+       if test -e "xz_recursive_level_one/$FILE"; then
+               :
+       else
+               echo "File not decompressed: xz_recursive_level_one/$FILE.xz"
+               exit 1
+       fi
+
+       # Remove decompressed files to prevent warnings in symlink test.
+       rm "xz_recursive_level_one/$FILE"
+done
+
+# Create a symlink to a directory to create a loop in the file system
+# to test that xz will not have infinite recursion. Creating the symlink
+# may fail, for instance on MSYS2 where the default behavior is to create
+# a copy of the target instead of an actual symlink.
+if ln -s ../ xz_recursive_level_one/level_two/loop_link; then
+       # The symlink should cause a warning and skip that directory.
+       "$XZ" -drf xz_recursive_level_one
+
+       if test $? != 2 ; then
+               echo "Recursive decompression did not give warning with symlink: $*"
+               exit 1
+       fi
+else
+       echo "Symlink could not be created, skipping this test"
+       exit 77
+fi
+
+# Clean up nested directory
+rm -rf xz_recursive_level_one