Skip to content

Commit

Permalink
Merge pull request #3055 from terrelln/cli-test-symlinks
Browse files Browse the repository at this point in the history
[cli-tests] Fix zstd symlinks
  • Loading branch information
terrelln authored Feb 8, 2022
2 parents b848c16 + 169f8c1 commit 7e364e8
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
4 changes: 3 additions & 1 deletion tests/cli-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
scratch/
!bin/
!datagen
!zstdcat

scratch/
bin/symlinks
6 changes: 4 additions & 2 deletions tests/cli-tests/bin/zstd
Original file line number Diff line number Diff line change
@@ -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
37 changes: 34 additions & 3 deletions tests/cli-tests/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@
import typing


ZSTD_SYMLINKS = [
"zstd",
"zstdmt",
"unzstd",
"zstdcat",
"zcat",
"gzip",
"gunzip",
"gzcat",
"lzma",
"unlzma",
"xz",
"unxz",
"lz4",
"unlz4",
]


EXCLUDED_DIRS = {
"bin",
"common",
Expand Down Expand Up @@ -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, "..", "..")
Expand Down Expand Up @@ -655,17 +683,20 @@ def run_tests(test_suites: TestSuites, options: Options) -> bool:
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,
Expand Down
6 changes: 6 additions & 0 deletions tests/cli-tests/zstd-symlinks/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
set -e

println "hello" > hello
println "world" > world
zstd hello world
12 changes: 12 additions & 0 deletions tests/cli-tests/zstd-symlinks/zstdcat.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions tests/cli-tests/zstd-symlinks/zstdcat.sh.stdout.exact
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
hello
hello
world
hello
world
hello
world
hello

0 comments on commit 7e364e8

Please sign in to comment.