]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[cli-tests] Fix zstd symlinks 3055/head
authorNick Terrell <terrelln@fb.com>
Mon, 7 Feb 2022 23:20:42 +0000 (15:20 -0800)
committerNick Terrell <terrelln@fb.com>
Mon, 7 Feb 2022 23:20:42 +0000 (15:20 -0800)
The zstd symlinks, notably `zstdcat`, weren't working as expected
because only the `tests/cli-tests/bin/zstd` wrapper was symlinked. We
still invoked `zstd` with the name `zstd`. The fix is to create a
directory of zstd symlinks in `tests/cli-tests/bin/symlinks` for each
name that zstd recognizes. And when `tets/cli-tests/bin/zstd` is
invoked, it selects the correct symlink to call.

See the test `zstd-cli/zstdcat.sh` for an example of how it would work.

tests/cli-tests/.gitignore
tests/cli-tests/bin/zstd
tests/cli-tests/run.py
tests/cli-tests/zstd-symlinks/setup [new file with mode: 0755]
tests/cli-tests/zstd-symlinks/zstdcat.sh [new file with mode: 0755]
tests/cli-tests/zstd-symlinks/zstdcat.sh.stdout.exact [new file with mode: 0644]

index 4bb425b613955f21516a0b8008ac20e74e060bff..0ad01b24effab1fb91fd25006a38a38a636e71b9 100644 (file)
@@ -1,4 +1,6 @@
-scratch/
 !bin/
 !datagen
 !zstdcat
+
+scratch/
+bin/symlinks
index 198fc6d2d9347257f12c37d7c9bc555cba82c4c8..7a40aec90d4dbba7ee14a592cb07850335e406cc 100755 (executable)
@@ -1,7 +1,9 @@
 #!/bin/sh
 
+zstdname=$(basename $0)
+
 if [ -z "$EXEC_PREFIX" ]; then
-    "$ZSTD_BIN" $@
+    "$ZSTD_SYMLINK_DIR/$zstdname" $@
 else
-    $EXEC_PREFIX "$ZSTD_BIN" $@
+    $EXEC_PREFIX "$ZSTD_SYMLINK_DIR/$zstdname" $@
 fi
index 39b53a09bc5d48dfd2672470ed4384521ef7832d..f2614b059f66bbdf0f28a566da0f69815bb6ab9d 100755 (executable)
@@ -21,6 +21,24 @@ import tempfile
 import typing
 
 
+ZSTD_SYMLINKS = [
+    "zstd",
+    "zstdmt",
+    "unzstd",
+    "zstdcat",
+    "zcat",
+    "gzip",
+    "gunzip",
+    "gzcat",
+    "lzma",
+    "unlzma",
+    "xz",
+    "unxz",
+    "lz4",
+    "unlz4",
+]
+
+
 EXCLUDED_DIRS = {
     "bin",
     "common",
@@ -592,6 +610,16 @@ def run_tests(test_suites: TestSuites, options: Options) -> bool:
         return False
 
 
+def setup_zstd_symlink_dir(zstd_symlink_dir: str, zstd: str) -> None:
+    assert os.path.join("bin", "symlinks") in zstd_symlink_dir
+    if not os.path.exists(zstd_symlink_dir):
+        os.makedirs(zstd_symlink_dir)
+    for symlink in ZSTD_SYMLINKS:
+        path = os.path.join(zstd_symlink_dir, symlink)
+        if os.path.exists(path):
+            os.remove(path)
+        os.symlink(zstd, path)
+
 if __name__ == "__main__":
     CLI_TEST_DIR = os.path.dirname(sys.argv[0])
     REPO_DIR = os.path.join(CLI_TEST_DIR, "..", "..")
@@ -655,17 +683,20 @@ if __name__ == "__main__":
         args.timeout = None
 
     args.test_dir = os.path.normpath(os.path.abspath(args.test_dir))
-    bin_dir = os.path.join(args.test_dir, "bin")
+    bin_dir = os.path.abspath(os.path.join(args.test_dir, "bin"))
+    zstd_symlink_dir = os.path.join(bin_dir, "symlinks")
     scratch_dir = os.path.join(args.test_dir, "scratch")
 
+    setup_zstd_symlink_dir(zstd_symlink_dir, os.path.abspath(args.zstd))
+
     env = {}
     if args.exec_prefix is not None:
         env["EXEC_PREFIX"] = args.exec_prefix
-    env["ZSTD_BIN"] = os.path.abspath(args.zstd)
+    env["ZSTD_SYMLINK_DIR"] = zstd_symlink_dir
     env["DATAGEN_BIN"] = os.path.abspath(args.datagen)
     env["ZSTDGREP_BIN"] = os.path.abspath(args.zstdgrep)
     env["COMMON"] = os.path.abspath(os.path.join(args.test_dir, "common"))
-    env["PATH"] = os.path.abspath(bin_dir) + ":" + os.getenv("PATH", "")
+    env["PATH"] = bin_dir + ":" + os.getenv("PATH", "")
 
     opts = Options(
         env=env,
diff --git a/tests/cli-tests/zstd-symlinks/setup b/tests/cli-tests/zstd-symlinks/setup
new file mode 100755 (executable)
index 0000000..cf391ed
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+set -e
+
+println "hello" > hello
+println "world" > world
+zstd hello world
diff --git a/tests/cli-tests/zstd-symlinks/zstdcat.sh b/tests/cli-tests/zstd-symlinks/zstdcat.sh
new file mode 100755 (executable)
index 0000000..74ec063
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+set -e
+
+# Test zstdcat symlink in bin/
+zstdcat hello.zst
+zstdcat hello.zst world
+zstdcat hello world.zst
+zstdcat hello.zst world.zst
+
+# Test local zstdcat symlink
+ln -s $(which zstd) ./zstdcat
+./zstdcat hello.zst
diff --git a/tests/cli-tests/zstd-symlinks/zstdcat.sh.stdout.exact b/tests/cli-tests/zstd-symlinks/zstdcat.sh.stdout.exact
new file mode 100644 (file)
index 0000000..3205b05
--- /dev/null
@@ -0,0 +1,8 @@
+hello
+hello
+world
+hello
+world
+hello
+world
+hello