From 516f8693c2c9dd4fd4c9294ee81f4d5599fe3524 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 27 Sep 2026 15:37:44 +0500 Subject: test/local/ -> test/ --- Makefile | 7 +- test/data/dest/1.txt | 1 + test/data/dest/bar/3.txt | 1 + test/data/src/%DEST%/1.txt | 1 + test/data/src/%DEST%/bar/3.txt | 1 + test/data/src/%DEST%/bar/baz/4.txt | 1 + test/data/src/%DEST%/foo/2.txt | 1 + test/docker/Dockerfile | 2 +- test/lib/log.sh | 128 +++++++++++++++++++++ test/lib/test.sh | 123 ++++++++++++++++++++ test/local/data/dest/1.txt | 1 - test/local/data/dest/bar/3.txt | 1 - test/local/data/src/%DEST%/1.txt | 1 - test/local/data/src/%DEST%/bar/3.txt | 1 - test/local/data/src/%DEST%/bar/baz/4.txt | 1 - test/local/data/src/%DEST%/foo/2.txt | 1 - test/local/lib/log.sh | 128 --------------------- test/local/lib/test.sh | 123 -------------------- test/local/main.sh | 79 ------------- test/local/tst-chmod.sh | 22 ---- test/local/tst-dir-symlink-delete.sh | 25 ---- test/local/tst-dir-symlink-remove-shared-file.sh | 30 ----- test/local/tst-linux-home.sh | 42 ------- test/local/tst-remove-dir-symlink.sh | 13 --- test/local/tst-remove-does-not-delete-user-dirs.sh | 19 --- test/local/tst-remove-does-not-overwrite-files.sh | 20 ---- test/local/tst-remove-symlink.sh | 20 ---- test/local/tst-remove.sh | 11 -- test/local/tst-update-chmod.sh | 19 --- test/local/tst-update-dir-symlink.sh | 29 ----- test/local/tst-update-symlink.sh | 28 ----- test/local/tst-update.sh | 18 --- test/main.sh | 79 +++++++++++++ test/tst-chmod.sh | 22 ++++ test/tst-dir-symlink-delete.sh | 25 ++++ test/tst-dir-symlink-remove-shared-file.sh | 30 +++++ test/tst-linux-home.sh | 42 +++++++ test/tst-remove-dir-symlink.sh | 13 +++ test/tst-remove-does-not-delete-user-dirs.sh | 19 +++ test/tst-remove-does-not-overwrite-files.sh | 20 ++++ test/tst-remove-symlink.sh | 20 ++++ test/tst-remove.sh | 11 ++ test/tst-update-chmod.sh | 19 +++ test/tst-update-dir-symlink.sh | 29 +++++ test/tst-update-symlink.sh | 28 +++++ test/tst-update.sh | 18 +++ 46 files changed, 635 insertions(+), 638 deletions(-) create mode 100644 test/data/dest/1.txt create mode 100644 test/data/dest/bar/3.txt create mode 100644 test/data/src/%DEST%/1.txt create mode 100644 test/data/src/%DEST%/bar/3.txt create mode 100644 test/data/src/%DEST%/bar/baz/4.txt create mode 100644 test/data/src/%DEST%/foo/2.txt create mode 100644 test/lib/log.sh create mode 100644 test/lib/test.sh delete mode 100644 test/local/data/dest/1.txt delete mode 100644 test/local/data/dest/bar/3.txt delete mode 100644 test/local/data/src/%DEST%/1.txt delete mode 100644 test/local/data/src/%DEST%/bar/3.txt delete mode 100644 test/local/data/src/%DEST%/bar/baz/4.txt delete mode 100644 test/local/data/src/%DEST%/foo/2.txt delete mode 100644 test/local/lib/log.sh delete mode 100644 test/local/lib/test.sh delete mode 100755 test/local/main.sh delete mode 100644 test/local/tst-chmod.sh delete mode 100644 test/local/tst-dir-symlink-delete.sh delete mode 100644 test/local/tst-dir-symlink-remove-shared-file.sh delete mode 100644 test/local/tst-linux-home.sh delete mode 100644 test/local/tst-remove-dir-symlink.sh delete mode 100644 test/local/tst-remove-does-not-delete-user-dirs.sh delete mode 100644 test/local/tst-remove-does-not-overwrite-files.sh delete mode 100644 test/local/tst-remove-symlink.sh delete mode 100644 test/local/tst-remove.sh delete mode 100644 test/local/tst-update-chmod.sh delete mode 100644 test/local/tst-update-dir-symlink.sh delete mode 100644 test/local/tst-update-symlink.sh delete mode 100644 test/local/tst-update.sh create mode 100755 test/main.sh create mode 100644 test/tst-chmod.sh create mode 100644 test/tst-dir-symlink-delete.sh create mode 100644 test/tst-dir-symlink-remove-shared-file.sh create mode 100644 test/tst-linux-home.sh create mode 100644 test/tst-remove-dir-symlink.sh create mode 100644 test/tst-remove-does-not-delete-user-dirs.sh create mode 100644 test/tst-remove-does-not-overwrite-files.sh create mode 100644 test/tst-remove-symlink.sh create mode 100644 test/tst-remove.sh create mode 100644 test/tst-update-chmod.sh create mode 100644 test/tst-update-dir-symlink.sh create mode 100644 test/tst-update-symlink.sh create mode 100644 test/tst-update.sh diff --git a/Makefile b/Makefile index a6576e5..fe20548 100644 --- a/Makefile +++ b/Makefile @@ -7,11 +7,8 @@ DO: all: test .PHONY: test -test: test/local - -.PHONY: test/local -test/local: - ./test/local/main.sh +test: + ./test/main.sh test/docker/%: DO cd test/docker && \ diff --git a/test/data/dest/1.txt b/test/data/dest/1.txt new file mode 100644 index 0000000..3a2e3f4 --- /dev/null +++ b/test/data/dest/1.txt @@ -0,0 +1 @@ +-1 diff --git a/test/data/dest/bar/3.txt b/test/data/dest/bar/3.txt new file mode 100644 index 0000000..a83d1d5 --- /dev/null +++ b/test/data/dest/bar/3.txt @@ -0,0 +1 @@ +-3 diff --git a/test/data/src/%DEST%/1.txt b/test/data/src/%DEST%/1.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test/data/src/%DEST%/1.txt @@ -0,0 +1 @@ +1 diff --git a/test/data/src/%DEST%/bar/3.txt b/test/data/src/%DEST%/bar/3.txt new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/test/data/src/%DEST%/bar/3.txt @@ -0,0 +1 @@ +3 diff --git a/test/data/src/%DEST%/bar/baz/4.txt b/test/data/src/%DEST%/bar/baz/4.txt new file mode 100644 index 0000000..b8626c4 --- /dev/null +++ b/test/data/src/%DEST%/bar/baz/4.txt @@ -0,0 +1 @@ +4 diff --git a/test/data/src/%DEST%/foo/2.txt b/test/data/src/%DEST%/foo/2.txt new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/test/data/src/%DEST%/foo/2.txt @@ -0,0 +1 @@ +2 diff --git a/test/docker/Dockerfile b/test/docker/Dockerfile index f1d4dbc..8cbae4f 100644 --- a/test/docker/Dockerfile +++ b/test/docker/Dockerfile @@ -12,4 +12,4 @@ COPY [".", "/src"] WORKDIR /src -CMD ["make", "test/local"] +CMD ["make", "test"] diff --git a/test/lib/log.sh b/test/lib/log.sh new file mode 100644 index 0000000..b26e16a --- /dev/null +++ b/test/lib/log.sh @@ -0,0 +1,128 @@ +# Copyright (c) 2026 Egor Tensin +# This file is part of the "config-links" project. +# For details, see https://github.com/egor-tensin/config-links +# Distributed under the MIT License. + +log() { + local msg + for msg; do + echo -e "$test_file | $msg" >&2 + done +} + +fail() { + local msg + for msg; do + log "FAIL: $msg" + done +} + +fail_details() { + local msg + for msg; do + fail " $msg" + done +} + +log_numof_tests_ok=0 +log_numof_tests_failed=0 +declare -a log_tests_failed=() +declare -A log_tests_should_fail=() + +log_test_start() { + if [ "$#" -ne 1 ]; then + echo "usage: ${FUNCNAME[0]} TEST_FILE" >&2 + return 1 + fi + + local test_file="$1" + + if [ -n "${test_should_fail:-}" ]; then + log_tests_should_fail["$test_file"]=1 + fi + + cat <&2 + +====================================================================== +TEST: $test_file +====================================================================== +EOF + + log "Should fail: ${test_should_fail:-No}" +} + +log_test_ok() { + if [ "$#" -ne 1 ]; then + echo "usage: ${FUNCNAME[0]} TEST_FILE" >&2 + return 1 + fi + + log_numof_tests_ok=$((log_numof_tests_ok + 1)) + + cat <&2 +---------------------------------------------------------------------- +OK: $1 +---------------------------------------------------------------------- +EOF +} + +log_test_fail() { + if [ "$#" -ne 1 ]; then + echo "usage: ${FUNCNAME[0]} TEST_FILE" >&2 + return 1 + fi + + log_numof_tests_failed=$((log_numof_tests_failed + 1)) + log_tests_failed+=("$1") + + cat <&2 +---------------------------------------------------------------------- +FAIL: $1 +---------------------------------------------------------------------- +EOF +} + +log_test_finish() { + if [ "$#" -ne 2 ]; then + echo "usage: ${FUNCNAME[0]} TEST_FILE EXIT_CODE" >&2 + return 1 + fi + + local test_file="$1" + local ret="$2" + local test_should_fail + test_should_fail="${log_tests_should_fail["$test_file"]:+x}" + + if [ "$ret" -eq 0 ] || [ -n "$test_should_fail" ]; then + log_test_ok "$test_file" + else + log_test_fail "$test_file" + fi +} + +log_tests_summary() { + cat <&2 + +====================================================================== +SUMMARY +====================================================================== +OK: $log_numof_tests_ok +FAIL: $log_numof_tests_failed +EOF + + local test_file + for test_file in ${log_tests_failed[@]+"${log_tests_failed[@]}"}; do + cat <&2 +FAIL: $test_file +EOF + done + + cat <&2 +---------------------------------------------------------------------- +EOF + + local ret=0 + [ "$log_numof_tests_failed" -gt 0 ] && ret=1 + + return "$ret" +} diff --git a/test/lib/test.sh b/test/lib/test.sh new file mode 100644 index 0000000..1406a78 --- /dev/null +++ b/test/lib/test.sh @@ -0,0 +1,123 @@ +# Copyright (c) 2026 Egor Tensin +# This file is part of the "config-links" project. +# For details, see https://github.com/egor-tensin/config-links +# Distributed under the MIT License. + +test_should_fail= + +src_dir_name='src' +dest_dir_name='dest' +alt_dest_dir_name='alt_dest' + +test_root_dir= +test_src_dir= +test_dest_dir= +test_alt_dest_dir= + +test_setup() { + test_root_dir="$( mktemp -d )" + # mktemp returns /var/..., which is actually in /private/var/... on macOS. + test_root_dir="$( readlink -e -- "$test_root_dir" )" + + test_src_dir="$test_root_dir/$src_dir_name" + test_dest_dir="$test_root_dir/$dest_dir_name" + test_alt_dest_dir="$test_root_dir/$alt_dest_dir_name" + + log "Root directory: $test_root_dir" + log "Shared directory: $test_src_dir" + log "%DEST% directory: $test_dest_dir" + log "%ALT_DEST% directory: $test_alt_dest_dir" + + cp -r -- "$script_dir/data/$src_dir_name" "$test_src_dir" + cp -r -- "$script_dir/data/$dest_dir_name" "$test_dest_dir" + cp -r -- "$script_dir/data/$dest_dir_name" "$test_alt_dest_dir" +} + +test_setup_symlink() { + test_setup + + # Create a stupid symlink. + ln -s -- 'bar/3.txt' "$test_src_dir/%DEST%/3_copy.txt" +} + +test_setup_dir_symlink() { + test_setup + + # Files will get symlinks in the directory pointed to by $DEST, as well as + # by $ALT_DEST. + ln -s -- '%DEST%' "$test_src_dir/%ALT_DEST%" +} + +test_cleanup_default() { + if [ -n "$test_root_dir" ]; then + log "Removing test's root directory: $test_root_dir" + rm -rf -- "$test_root_dir" + fi +} + +test_run_script() { + local msg='Executing script:' + msg="$msg$( printf -- ' %q' "$@" --shared-dir "$test_src_dir" --database "$test_root_dir/links.bin" )" + log "$msg" + + DEST="$test_dest_dir" ALT_DEST="$test_alt_dest_dir" "$@" \ + --shared-dir "$test_src_dir" \ + --database "$test_root_dir/links.bin" +} + +test_run_update() { + test_run_script "$script_dir/../bin/links-update" "$@" +} + +test_run_remove() { + test_run_script "$script_dir/../bin/links-remove" +} + +test_run_chmod() { + test_run_script "$script_dir/../bin/links-chmod" "$@" +} + +test_verify_output() { + if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then + echo "usage: ${FUNCNAME[0]} DEST_DIR EXPECTED_OUTPUT" >&2 + return 1 + fi + + local dest_dir="$1" + local expected_output="$2" + + log "Verifying directory structure in $dest_dir..." + + local actual_output + actual_output="$( find "$dest_dir" -printf '%h/%f->%l\n' | sort )" + + if [ "$actual_output" != "$expected_output" ]; then + fail "The actual files do not match the expected directory structure!" + fail_details "Expected:\n$expected_output" + fail_details "Actual:\n$actual_output" + return 1 + fi +} + +test_verify_mode() { + if [ "$#" -ne 2 ]; then + echo "usage: ${FUNCNAME[0]} PATH EXPECTED_MODE" >&2 + return 1 + fi + + local path="$1" + local expected_mode="$2" + + log "Checking permissions for file: $path" + + local actual_mode + actual_mode="$( stat -c '%a' -- "$path" )" + actual_mode="0$actual_mode" + + if [ "$actual_mode" != "$expected_mode" ]; then + fail "They don't match" + fail_details "Expected: $expected_mode" + fail_details "Actual: $actual_mode" + return 1 + fi +} diff --git a/test/local/data/dest/1.txt b/test/local/data/dest/1.txt deleted file mode 100644 index 3a2e3f4..0000000 --- a/test/local/data/dest/1.txt +++ /dev/null @@ -1 +0,0 @@ --1 diff --git a/test/local/data/dest/bar/3.txt b/test/local/data/dest/bar/3.txt deleted file mode 100644 index a83d1d5..0000000 --- a/test/local/data/dest/bar/3.txt +++ /dev/null @@ -1 +0,0 @@ --3 diff --git a/test/local/data/src/%DEST%/1.txt b/test/local/data/src/%DEST%/1.txt deleted file mode 100644 index d00491f..0000000 --- a/test/local/data/src/%DEST%/1.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/test/local/data/src/%DEST%/bar/3.txt b/test/local/data/src/%DEST%/bar/3.txt deleted file mode 100644 index 00750ed..0000000 --- a/test/local/data/src/%DEST%/bar/3.txt +++ /dev/null @@ -1 +0,0 @@ -3 diff --git a/test/local/data/src/%DEST%/bar/baz/4.txt b/test/local/data/src/%DEST%/bar/baz/4.txt deleted file mode 100644 index b8626c4..0000000 --- a/test/local/data/src/%DEST%/bar/baz/4.txt +++ /dev/null @@ -1 +0,0 @@ -4 diff --git a/test/local/data/src/%DEST%/foo/2.txt b/test/local/data/src/%DEST%/foo/2.txt deleted file mode 100644 index 0cfbf08..0000000 --- a/test/local/data/src/%DEST%/foo/2.txt +++ /dev/null @@ -1 +0,0 @@ -2 diff --git a/test/local/lib/log.sh b/test/local/lib/log.sh deleted file mode 100644 index b26e16a..0000000 --- a/test/local/lib/log.sh +++ /dev/null @@ -1,128 +0,0 @@ -# Copyright (c) 2026 Egor Tensin -# This file is part of the "config-links" project. -# For details, see https://github.com/egor-tensin/config-links -# Distributed under the MIT License. - -log() { - local msg - for msg; do - echo -e "$test_file | $msg" >&2 - done -} - -fail() { - local msg - for msg; do - log "FAIL: $msg" - done -} - -fail_details() { - local msg - for msg; do - fail " $msg" - done -} - -log_numof_tests_ok=0 -log_numof_tests_failed=0 -declare -a log_tests_failed=() -declare -A log_tests_should_fail=() - -log_test_start() { - if [ "$#" -ne 1 ]; then - echo "usage: ${FUNCNAME[0]} TEST_FILE" >&2 - return 1 - fi - - local test_file="$1" - - if [ -n "${test_should_fail:-}" ]; then - log_tests_should_fail["$test_file"]=1 - fi - - cat <&2 - -====================================================================== -TEST: $test_file -====================================================================== -EOF - - log "Should fail: ${test_should_fail:-No}" -} - -log_test_ok() { - if [ "$#" -ne 1 ]; then - echo "usage: ${FUNCNAME[0]} TEST_FILE" >&2 - return 1 - fi - - log_numof_tests_ok=$((log_numof_tests_ok + 1)) - - cat <&2 ----------------------------------------------------------------------- -OK: $1 ----------------------------------------------------------------------- -EOF -} - -log_test_fail() { - if [ "$#" -ne 1 ]; then - echo "usage: ${FUNCNAME[0]} TEST_FILE" >&2 - return 1 - fi - - log_numof_tests_failed=$((log_numof_tests_failed + 1)) - log_tests_failed+=("$1") - - cat <&2 ----------------------------------------------------------------------- -FAIL: $1 ----------------------------------------------------------------------- -EOF -} - -log_test_finish() { - if [ "$#" -ne 2 ]; then - echo "usage: ${FUNCNAME[0]} TEST_FILE EXIT_CODE" >&2 - return 1 - fi - - local test_file="$1" - local ret="$2" - local test_should_fail - test_should_fail="${log_tests_should_fail["$test_file"]:+x}" - - if [ "$ret" -eq 0 ] || [ -n "$test_should_fail" ]; then - log_test_ok "$test_file" - else - log_test_fail "$test_file" - fi -} - -log_tests_summary() { - cat <&2 - -====================================================================== -SUMMARY -====================================================================== -OK: $log_numof_tests_ok -FAIL: $log_numof_tests_failed -EOF - - local test_file - for test_file in ${log_tests_failed[@]+"${log_tests_failed[@]}"}; do - cat <&2 -FAIL: $test_file -EOF - done - - cat <&2 ----------------------------------------------------------------------- -EOF - - local ret=0 - [ "$log_numof_tests_failed" -gt 0 ] && ret=1 - - return "$ret" -} diff --git a/test/local/lib/test.sh b/test/local/lib/test.sh deleted file mode 100644 index 43cf55b..0000000 --- a/test/local/lib/test.sh +++ /dev/null @@ -1,123 +0,0 @@ -# Copyright (c) 2026 Egor Tensin -# This file is part of the "config-links" project. -# For details, see https://github.com/egor-tensin/config-links -# Distributed under the MIT License. - -test_should_fail= - -src_dir_name='src' -dest_dir_name='dest' -alt_dest_dir_name='alt_dest' - -test_root_dir= -test_src_dir= -test_dest_dir= -test_alt_dest_dir= - -test_setup() { - test_root_dir="$( mktemp -d )" - # mktemp returns /var/..., which is actually in /private/var/... on macOS. - test_root_dir="$( readlink -e -- "$test_root_dir" )" - - test_src_dir="$test_root_dir/$src_dir_name" - test_dest_dir="$test_root_dir/$dest_dir_name" - test_alt_dest_dir="$test_root_dir/$alt_dest_dir_name" - - log "Root directory: $test_root_dir" - log "Shared directory: $test_src_dir" - log "%DEST% directory: $test_dest_dir" - log "%ALT_DEST% directory: $test_alt_dest_dir" - - cp -r -- "$script_dir/data/$src_dir_name" "$test_src_dir" - cp -r -- "$script_dir/data/$dest_dir_name" "$test_dest_dir" - cp -r -- "$script_dir/data/$dest_dir_name" "$test_alt_dest_dir" -} - -test_setup_symlink() { - test_setup - - # Create a stupid symlink. - ln -s -- 'bar/3.txt' "$test_src_dir/%DEST%/3_copy.txt" -} - -test_setup_dir_symlink() { - test_setup - - # Files will get symlinks in the directory pointed to by $DEST, as well as - # by $ALT_DEST. - ln -s -- '%DEST%' "$test_src_dir/%ALT_DEST%" -} - -test_cleanup_default() { - if [ -n "$test_root_dir" ]; then - log "Removing test's root directory: $test_root_dir" - rm -rf -- "$test_root_dir" - fi -} - -test_run_script() { - local msg='Executing script:' - msg="$msg$( printf -- ' %q' "$@" --shared-dir "$test_src_dir" --database "$test_root_dir/links.bin" )" - log "$msg" - - DEST="$test_dest_dir" ALT_DEST="$test_alt_dest_dir" "$@" \ - --shared-dir "$test_src_dir" \ - --database "$test_root_dir/links.bin" -} - -test_run_update() { - test_run_script "$script_dir/../../bin/links-update" "$@" -} - -test_run_remove() { - test_run_script "$script_dir/../../bin/links-remove" -} - -test_run_chmod() { - test_run_script "$script_dir/../../bin/links-chmod" "$@" -} - -test_verify_output() { - if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then - echo "usage: ${FUNCNAME[0]} DEST_DIR EXPECTED_OUTPUT" >&2 - return 1 - fi - - local dest_dir="$1" - local expected_output="$2" - - log "Verifying directory structure in $dest_dir..." - - local actual_output - actual_output="$( find "$dest_dir" -printf '%h/%f->%l\n' | sort )" - - if [ "$actual_output" != "$expected_output" ]; then - fail "The actual files do not match the expected directory structure!" - fail_details "Expected:\n$expected_output" - fail_details "Actual:\n$actual_output" - return 1 - fi -} - -test_verify_mode() { - if [ "$#" -ne 2 ]; then - echo "usage: ${FUNCNAME[0]} PATH EXPECTED_MODE" >&2 - return 1 - fi - - local path="$1" - local expected_mode="$2" - - log "Checking permissions for file: $path" - - local actual_mode - actual_mode="$( stat -c '%a' -- "$path" )" - actual_mode="0$actual_mode" - - if [ "$actual_mode" != "$expected_mode" ]; then - fail "They don't match" - fail_details "Expected: $expected_mode" - fail_details "Actual: $actual_mode" - return 1 - fi -} diff --git a/test/local/main.sh b/test/local/main.sh deleted file mode 100755 index 52b19ad..0000000 --- a/test/local/main.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env bash - -# Copyright (c) 2026 Egor Tensin -# This file is part of the "config-links" project. -# For details, see https://github.com/egor-tensin/config-links -# Distributed under the MIT License. - -set -o errexit -o nounset -o pipefail -shopt -s inherit_errexit 2> /dev/null || true -shopt -s lastpipe - -script_dir="$( dirname -- "${BASH_SOURCE[0]}" )" -script_dir="$( cd -- "$script_dir" && pwd )" -readonly script_dir -script_name="$( basename -- "${BASH_SOURCE[0]}" )" -readonly script_name - -source "$script_dir/lib/log.sh" - -run_test_file() { - local test_file - for test_file; do - source "$script_dir/lib/test.sh" - source "$script_dir/$test_file" - - log_test_start "$test_file" - - set +e - ( - set -o errexit -o nounset -o pipefail - shopt -s inherit_errexit 2> /dev/null || true - shopt -s lastpipe - - if [ "$( type -t test_cleanup )" == function ]; then - trap test_cleanup EXIT - else - trap test_cleanup_default EXIT - fi - - test_run - ) - local ret="$?" - set -e - - log_test_finish "$test_file" "$ret" - done -} - -main() { - if [ "$#" -gt 1 ]; then - echo "usage: $script_name [PATTERN]" >&2 - return 1 - fi - - local -a test_files=() - local test_file - - local pattern='*' - [ "$#" -gt 0 ] && pattern="$1" - - find "$script_dir" \ - -mindepth 1 \ - -maxdepth 1 \ - -type f \ - -regex '.*/tst-.*\.sh$' \ - -regextype posix-basic \ - -name "$pattern" \ - -printf '%P\0' \ - | sort -z \ - | \ - while IFS= read -d '' -r test_file; do - test_files+=("$test_file") - done - - run_test_file ${test_files[@]+"${test_files[@]}"} - log_tests_summary -} - -main "$@" diff --git a/test/local/tst-chmod.sh b/test/local/tst-chmod.sh deleted file mode 100644 index b118e5e..0000000 --- a/test/local/tst-chmod.sh +++ /dev/null @@ -1,22 +0,0 @@ -test_run() { - # Test that links-chmod works. - - test_setup - test_run_update - - local expected_output="$test_dest_dir-> -$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt -$test_dest_dir/bar-> -$test_dest_dir/bar/3.txt->$test_src_dir/%DEST%/bar/3.txt -$test_dest_dir/bar/baz-> -$test_dest_dir/bar/baz/4.txt->$test_src_dir/%DEST%/bar/baz/4.txt -$test_dest_dir/foo-> -$test_dest_dir/foo/2.txt->$test_src_dir/%DEST%/foo/2.txt" - test_verify_output "$test_dest_dir" "$expected_output" - - log "Verifying 1.txt's (the shared file) permissions..." - - test_verify_mode "$test_src_dir/%DEST%/1.txt" 0644 - test_run_chmod 0600 - test_verify_mode "$test_src_dir/%DEST%/1.txt" 0600 -} diff --git a/test/local/tst-dir-symlink-delete.sh b/test/local/tst-dir-symlink-delete.sh deleted file mode 100644 index f53d87c..0000000 --- a/test/local/tst-dir-symlink-delete.sh +++ /dev/null @@ -1,25 +0,0 @@ -test_run() { - # If we remove a directory symlink in --shared-dir, all the symlinks - # accessible through this directory symlink should be removed. - - test_setup_dir_symlink - test_run_update - - # Remove the directory symlink: - rm -- "$test_src_dir/%ALT_DEST%" - test_run_update - - local expected_output="$test_dest_dir-> -$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt -$test_dest_dir/bar-> -$test_dest_dir/bar/3.txt->$test_src_dir/%DEST%/bar/3.txt -$test_dest_dir/bar/baz-> -$test_dest_dir/bar/baz/4.txt->$test_src_dir/%DEST%/bar/baz/4.txt -$test_dest_dir/foo-> -$test_dest_dir/foo/2.txt->$test_src_dir/%DEST%/foo/2.txt" - - test_verify_output "$test_dest_dir" "$expected_output" - - expected_output="$test_alt_dest_dir->" - test_verify_output "$test_alt_dest_dir" "$expected_output" -} diff --git a/test/local/tst-dir-symlink-remove-shared-file.sh b/test/local/tst-dir-symlink-remove-shared-file.sh deleted file mode 100644 index 3e20ab0..0000000 --- a/test/local/tst-dir-symlink-remove-shared-file.sh +++ /dev/null @@ -1,30 +0,0 @@ -test_run() { - # If we remove a shared file, both of the symlinks should be removed. - - test_setup_dir_symlink - test_run_update - - # Remove a random shared file: - rm -- "$test_src_dir/%DEST%/bar/3.txt" - test_run_update - - local expected_output="$test_dest_dir-> -$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt -$test_dest_dir/bar-> -$test_dest_dir/bar/baz-> -$test_dest_dir/bar/baz/4.txt->$test_src_dir/%DEST%/bar/baz/4.txt -$test_dest_dir/foo-> -$test_dest_dir/foo/2.txt->$test_src_dir/%DEST%/foo/2.txt" - - test_verify_output "$test_dest_dir" "$expected_output" - - expected_output="$test_alt_dest_dir-> -$test_alt_dest_dir/1.txt->$test_src_dir/%ALT_DEST%/1.txt -$test_alt_dest_dir/bar-> -$test_alt_dest_dir/bar/baz-> -$test_alt_dest_dir/bar/baz/4.txt->$test_src_dir/%ALT_DEST%/bar/baz/4.txt -$test_alt_dest_dir/foo-> -$test_alt_dest_dir/foo/2.txt->$test_src_dir/%ALT_DEST%/foo/2.txt" - - test_verify_output "$test_alt_dest_dir" "$expected_output" -} diff --git a/test/local/tst-linux-home.sh b/test/local/tst-linux-home.sh deleted file mode 100644 index 4d099ee..0000000 --- a/test/local/tst-linux-home.sh +++ /dev/null @@ -1,42 +0,0 @@ -[ -z "${CI+y}" ] && test_should_fail=y - -test_run() { - if [ -z "${CI+y}" ]; then - fail "Don't run this test locally, it'll mess up your \$HOME" - return 1 - fi - - readonly src_name=linux-home - src_url="https://github.com/egor-tensin/$src_name.git" - readonly src_url - - test_root_dir="$( mktemp -d )" - # mktemp returns /var/..., which is actually in /private/var/... on macOS. - test_root_dir="$( readlink -e -- "$test_root_dir" )" - - test_src_dir="$test_root_dir/$src_name" - - log "Cloning $src_url to $test_src_dir..." - git clone -q -- "$src_url" "$test_src_dir" - - test_run_update - # Again: - test_run_update - - log "Checking a couple of well-known files..." - local file - for file in .gitconfig .ssh/config; do - local actual - actual="$( readlink -e -- "$HOME/$file" )" - - local expected - expected="$test_src_dir/%HOME%/$file" - - if [ "$actual" != "$expected" ]; then - fail "There was a problem with symlink $file:" - fail_details "Expected target: $expected" - fail_details "Actual target: $actual" - return 1 - fi - done -} diff --git a/test/local/tst-remove-dir-symlink.sh b/test/local/tst-remove-dir-symlink.sh deleted file mode 100644 index c524ee6..0000000 --- a/test/local/tst-remove-dir-symlink.sh +++ /dev/null @@ -1,13 +0,0 @@ -test_run() { - # Test that links-remove works for directory symlinks inside --shared-dir. - - test_setup_dir_symlink - test_run_update - test_run_remove - - local expected_output="$test_dest_dir->" - test_verify_output "$test_dest_dir" "$expected_output" - - expected_output="$test_alt_dest_dir->" - test_verify_output "$test_alt_dest_dir" "$expected_output" -} diff --git a/test/local/tst-remove-does-not-delete-user-dirs.sh b/test/local/tst-remove-does-not-delete-user-dirs.sh deleted file mode 100644 index aa013c8..0000000 --- a/test/local/tst-remove-does-not-delete-user-dirs.sh +++ /dev/null @@ -1,19 +0,0 @@ -test_run() { - # Check that if a user adds a file to a destination directory, it's not - # deleted by links-remove. - - test_setup - test_run_update - - # User adds his own file to the directory: - echo 'User content' > "$test_dest_dir/bar/my-file" - - test_run_remove - - # bar/ and bar/my-file must be kept: - local expected_output="$test_dest_dir-> -$test_dest_dir/bar-> -$test_dest_dir/bar/my-file->" - - test_verify_output "$test_dest_dir" "$expected_output" -} diff --git a/test/local/tst-remove-does-not-overwrite-files.sh b/test/local/tst-remove-does-not-overwrite-files.sh deleted file mode 100644 index baef2ef..0000000 --- a/test/local/tst-remove-does-not-overwrite-files.sh +++ /dev/null @@ -1,20 +0,0 @@ -test_run() { - # Check that if a user overwrites a symlink with his own file, links-remove - # keeps it. - - test_setup - test_run_update - - # Simulate a user overwriting one of the symlinks with his own file. - rm -- "$test_dest_dir/bar/3.txt" - echo 'User content' > "$test_dest_dir/bar/3.txt" - - test_run_remove - - # 3.txt must be kept: - local expected_output="$test_dest_dir-> -$test_dest_dir/bar-> -$test_dest_dir/bar/3.txt->" - - test_verify_output "$test_dest_dir" "$expected_output" -} diff --git a/test/local/tst-remove-symlink.sh b/test/local/tst-remove-symlink.sh deleted file mode 100644 index aa27435..0000000 --- a/test/local/tst-remove-symlink.sh +++ /dev/null @@ -1,20 +0,0 @@ -test_run() { - # Verify that links-remove doesn't delete shared symlinks. - - test_setup_symlink - test_run_update - test_run_remove - - local expected_output="$test_dest_dir->" - test_verify_output "$test_dest_dir" "$expected_output" - - log 'Verifying 3_copy.txt (the shared file) is valid...' - - local copy_target - copy_target="$( readlink -e -- "$test_src_dir/%DEST%/3_copy.txt" )" - test "$copy_target" = "$test_src_dir/%DEST%/bar/3.txt" - - local copy_content - copy_content="$( cat -- "$test_src_dir/%DEST%/3_copy.txt" )" - test "$copy_content" = '3' -} diff --git a/test/local/tst-remove.sh b/test/local/tst-remove.sh deleted file mode 100644 index c79a3b4..0000000 --- a/test/local/tst-remove.sh +++ /dev/null @@ -1,11 +0,0 @@ -test_run() { - # Basic test to make sure links-remove actually removes the created - # symlinks. - - test_setup - test_run_update - test_run_remove - - local expected_output="$test_dest_dir->" - test_verify_output "$test_dest_dir" "$expected_output" -} diff --git a/test/local/tst-update-chmod.sh b/test/local/tst-update-chmod.sh deleted file mode 100644 index a78ee15..0000000 --- a/test/local/tst-update-chmod.sh +++ /dev/null @@ -1,19 +0,0 @@ -test_run() { - # Test that links-update --mode works. - - test_setup - local expected_mode='0622' - test_run_update --mode "$expected_mode" - - local expected_output="$test_dest_dir-> -$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt -$test_dest_dir/bar-> -$test_dest_dir/bar/3.txt->$test_src_dir/%DEST%/bar/3.txt -$test_dest_dir/bar/baz-> -$test_dest_dir/bar/baz/4.txt->$test_src_dir/%DEST%/bar/baz/4.txt -$test_dest_dir/foo-> -$test_dest_dir/foo/2.txt->$test_src_dir/%DEST%/foo/2.txt" - - test_verify_output "$test_dest_dir" "$expected_output" - test_verify_mode "$test_src_dir/%DEST%/1.txt" "$expected_mode" -} diff --git a/test/local/tst-update-dir-symlink.sh b/test/local/tst-update-dir-symlink.sh deleted file mode 100644 index 27418ab..0000000 --- a/test/local/tst-update-dir-symlink.sh +++ /dev/null @@ -1,29 +0,0 @@ -test_run() { - # We can symlink files to multiple directories by creating symlinks inside - # --shared-dir. - - test_setup_dir_symlink - test_run_update - - local expected_output="$test_dest_dir-> -$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt -$test_dest_dir/bar-> -$test_dest_dir/bar/3.txt->$test_src_dir/%DEST%/bar/3.txt -$test_dest_dir/bar/baz-> -$test_dest_dir/bar/baz/4.txt->$test_src_dir/%DEST%/bar/baz/4.txt -$test_dest_dir/foo-> -$test_dest_dir/foo/2.txt->$test_src_dir/%DEST%/foo/2.txt" - - test_verify_output "$test_dest_dir" "$expected_output" - - expected_output="$test_alt_dest_dir-> -$test_alt_dest_dir/1.txt->$test_src_dir/%ALT_DEST%/1.txt -$test_alt_dest_dir/bar-> -$test_alt_dest_dir/bar/3.txt->$test_src_dir/%ALT_DEST%/bar/3.txt -$test_alt_dest_dir/bar/baz-> -$test_alt_dest_dir/bar/baz/4.txt->$test_src_dir/%ALT_DEST%/bar/baz/4.txt -$test_alt_dest_dir/foo-> -$test_alt_dest_dir/foo/2.txt->$test_src_dir/%ALT_DEST%/foo/2.txt" - - test_verify_output "$test_alt_dest_dir" "$expected_output" -} diff --git a/test/local/tst-update-symlink.sh b/test/local/tst-update-symlink.sh deleted file mode 100644 index 6a90491..0000000 --- a/test/local/tst-update-symlink.sh +++ /dev/null @@ -1,28 +0,0 @@ -test_run() { - # Shared files can also be symlinks, pointing to something else. - - test_setup_symlink - test_run_update - - local expected_output="$test_dest_dir-> -$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt -$test_dest_dir/3_copy.txt->$test_src_dir/%DEST%/3_copy.txt -$test_dest_dir/bar-> -$test_dest_dir/bar/3.txt->$test_src_dir/%DEST%/bar/3.txt -$test_dest_dir/bar/baz-> -$test_dest_dir/bar/baz/4.txt->$test_src_dir/%DEST%/bar/baz/4.txt -$test_dest_dir/foo-> -$test_dest_dir/foo/2.txt->$test_src_dir/%DEST%/foo/2.txt" - - test_verify_output "$test_dest_dir" "$expected_output" - - log 'Verifying 3_copy.txt (the symlink) is valid...' - - local copy_target - copy_target="$( readlink -- "$test_dest_dir/3_copy.txt" )" - test "$copy_target" = "$test_src_dir/%DEST%/3_copy.txt" - - local copy_content - copy_content="$( cat -- "$test_dest_dir/3_copy.txt" )" - test "$copy_content" = '3' -} diff --git a/test/local/tst-update.sh b/test/local/tst-update.sh deleted file mode 100644 index f33b929..0000000 --- a/test/local/tst-update.sh +++ /dev/null @@ -1,18 +0,0 @@ -test_run() { - # Basic test to make sure that links-update actually creates the proper - # symlinks. - - test_setup - test_run_update - - local expected_output="$test_dest_dir-> -$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt -$test_dest_dir/bar-> -$test_dest_dir/bar/3.txt->$test_src_dir/%DEST%/bar/3.txt -$test_dest_dir/bar/baz-> -$test_dest_dir/bar/baz/4.txt->$test_src_dir/%DEST%/bar/baz/4.txt -$test_dest_dir/foo-> -$test_dest_dir/foo/2.txt->$test_src_dir/%DEST%/foo/2.txt" - - test_verify_output "$test_dest_dir" "$expected_output" -} diff --git a/test/main.sh b/test/main.sh new file mode 100755 index 0000000..52b19ad --- /dev/null +++ b/test/main.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +# Copyright (c) 2026 Egor Tensin +# This file is part of the "config-links" project. +# For details, see https://github.com/egor-tensin/config-links +# Distributed under the MIT License. + +set -o errexit -o nounset -o pipefail +shopt -s inherit_errexit 2> /dev/null || true +shopt -s lastpipe + +script_dir="$( dirname -- "${BASH_SOURCE[0]}" )" +script_dir="$( cd -- "$script_dir" && pwd )" +readonly script_dir +script_name="$( basename -- "${BASH_SOURCE[0]}" )" +readonly script_name + +source "$script_dir/lib/log.sh" + +run_test_file() { + local test_file + for test_file; do + source "$script_dir/lib/test.sh" + source "$script_dir/$test_file" + + log_test_start "$test_file" + + set +e + ( + set -o errexit -o nounset -o pipefail + shopt -s inherit_errexit 2> /dev/null || true + shopt -s lastpipe + + if [ "$( type -t test_cleanup )" == function ]; then + trap test_cleanup EXIT + else + trap test_cleanup_default EXIT + fi + + test_run + ) + local ret="$?" + set -e + + log_test_finish "$test_file" "$ret" + done +} + +main() { + if [ "$#" -gt 1 ]; then + echo "usage: $script_name [PATTERN]" >&2 + return 1 + fi + + local -a test_files=() + local test_file + + local pattern='*' + [ "$#" -gt 0 ] && pattern="$1" + + find "$script_dir" \ + -mindepth 1 \ + -maxdepth 1 \ + -type f \ + -regex '.*/tst-.*\.sh$' \ + -regextype posix-basic \ + -name "$pattern" \ + -printf '%P\0' \ + | sort -z \ + | \ + while IFS= read -d '' -r test_file; do + test_files+=("$test_file") + done + + run_test_file ${test_files[@]+"${test_files[@]}"} + log_tests_summary +} + +main "$@" diff --git a/test/tst-chmod.sh b/test/tst-chmod.sh new file mode 100644 index 0000000..b118e5e --- /dev/null +++ b/test/tst-chmod.sh @@ -0,0 +1,22 @@ +test_run() { + # Test that links-chmod works. + + test_setup + test_run_update + + local expected_output="$test_dest_dir-> +$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt +$test_dest_dir/bar-> +$test_dest_dir/bar/3.txt->$test_src_dir/%DEST%/bar/3.txt +$test_dest_dir/bar/baz-> +$test_dest_dir/bar/baz/4.txt->$test_src_dir/%DEST%/bar/baz/4.txt +$test_dest_dir/foo-> +$test_dest_dir/foo/2.txt->$test_src_dir/%DEST%/foo/2.txt" + test_verify_output "$test_dest_dir" "$expected_output" + + log "Verifying 1.txt's (the shared file) permissions..." + + test_verify_mode "$test_src_dir/%DEST%/1.txt" 0644 + test_run_chmod 0600 + test_verify_mode "$test_src_dir/%DEST%/1.txt" 0600 +} diff --git a/test/tst-dir-symlink-delete.sh b/test/tst-dir-symlink-delete.sh new file mode 100644 index 0000000..f53d87c --- /dev/null +++ b/test/tst-dir-symlink-delete.sh @@ -0,0 +1,25 @@ +test_run() { + # If we remove a directory symlink in --shared-dir, all the symlinks + # accessible through this directory symlink should be removed. + + test_setup_dir_symlink + test_run_update + + # Remove the directory symlink: + rm -- "$test_src_dir/%ALT_DEST%" + test_run_update + + local expected_output="$test_dest_dir-> +$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt +$test_dest_dir/bar-> +$test_dest_dir/bar/3.txt->$test_src_dir/%DEST%/bar/3.txt +$test_dest_dir/bar/baz-> +$test_dest_dir/bar/baz/4.txt->$test_src_dir/%DEST%/bar/baz/4.txt +$test_dest_dir/foo-> +$test_dest_dir/foo/2.txt->$test_src_dir/%DEST%/foo/2.txt" + + test_verify_output "$test_dest_dir" "$expected_output" + + expected_output="$test_alt_dest_dir->" + test_verify_output "$test_alt_dest_dir" "$expected_output" +} diff --git a/test/tst-dir-symlink-remove-shared-file.sh b/test/tst-dir-symlink-remove-shared-file.sh new file mode 100644 index 0000000..3e20ab0 --- /dev/null +++ b/test/tst-dir-symlink-remove-shared-file.sh @@ -0,0 +1,30 @@ +test_run() { + # If we remove a shared file, both of the symlinks should be removed. + + test_setup_dir_symlink + test_run_update + + # Remove a random shared file: + rm -- "$test_src_dir/%DEST%/bar/3.txt" + test_run_update + + local expected_output="$test_dest_dir-> +$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt +$test_dest_dir/bar-> +$test_dest_dir/bar/baz-> +$test_dest_dir/bar/baz/4.txt->$test_src_dir/%DEST%/bar/baz/4.txt +$test_dest_dir/foo-> +$test_dest_dir/foo/2.txt->$test_src_dir/%DEST%/foo/2.txt" + + test_verify_output "$test_dest_dir" "$expected_output" + + expected_output="$test_alt_dest_dir-> +$test_alt_dest_dir/1.txt->$test_src_dir/%ALT_DEST%/1.txt +$test_alt_dest_dir/bar-> +$test_alt_dest_dir/bar/baz-> +$test_alt_dest_dir/bar/baz/4.txt->$test_src_dir/%ALT_DEST%/bar/baz/4.txt +$test_alt_dest_dir/foo-> +$test_alt_dest_dir/foo/2.txt->$test_src_dir/%ALT_DEST%/foo/2.txt" + + test_verify_output "$test_alt_dest_dir" "$expected_output" +} diff --git a/test/tst-linux-home.sh b/test/tst-linux-home.sh new file mode 100644 index 0000000..4d099ee --- /dev/null +++ b/test/tst-linux-home.sh @@ -0,0 +1,42 @@ +[ -z "${CI+y}" ] && test_should_fail=y + +test_run() { + if [ -z "${CI+y}" ]; then + fail "Don't run this test locally, it'll mess up your \$HOME" + return 1 + fi + + readonly src_name=linux-home + src_url="https://github.com/egor-tensin/$src_name.git" + readonly src_url + + test_root_dir="$( mktemp -d )" + # mktemp returns /var/..., which is actually in /private/var/... on macOS. + test_root_dir="$( readlink -e -- "$test_root_dir" )" + + test_src_dir="$test_root_dir/$src_name" + + log "Cloning $src_url to $test_src_dir..." + git clone -q -- "$src_url" "$test_src_dir" + + test_run_update + # Again: + test_run_update + + log "Checking a couple of well-known files..." + local file + for file in .gitconfig .ssh/config; do + local actual + actual="$( readlink -e -- "$HOME/$file" )" + + local expected + expected="$test_src_dir/%HOME%/$file" + + if [ "$actual" != "$expected" ]; then + fail "There was a problem with symlink $file:" + fail_details "Expected target: $expected" + fail_details "Actual target: $actual" + return 1 + fi + done +} diff --git a/test/tst-remove-dir-symlink.sh b/test/tst-remove-dir-symlink.sh new file mode 100644 index 0000000..c524ee6 --- /dev/null +++ b/test/tst-remove-dir-symlink.sh @@ -0,0 +1,13 @@ +test_run() { + # Test that links-remove works for directory symlinks inside --shared-dir. + + test_setup_dir_symlink + test_run_update + test_run_remove + + local expected_output="$test_dest_dir->" + test_verify_output "$test_dest_dir" "$expected_output" + + expected_output="$test_alt_dest_dir->" + test_verify_output "$test_alt_dest_dir" "$expected_output" +} diff --git a/test/tst-remove-does-not-delete-user-dirs.sh b/test/tst-remove-does-not-delete-user-dirs.sh new file mode 100644 index 0000000..aa013c8 --- /dev/null +++ b/test/tst-remove-does-not-delete-user-dirs.sh @@ -0,0 +1,19 @@ +test_run() { + # Check that if a user adds a file to a destination directory, it's not + # deleted by links-remove. + + test_setup + test_run_update + + # User adds his own file to the directory: + echo 'User content' > "$test_dest_dir/bar/my-file" + + test_run_remove + + # bar/ and bar/my-file must be kept: + local expected_output="$test_dest_dir-> +$test_dest_dir/bar-> +$test_dest_dir/bar/my-file->" + + test_verify_output "$test_dest_dir" "$expected_output" +} diff --git a/test/tst-remove-does-not-overwrite-files.sh b/test/tst-remove-does-not-overwrite-files.sh new file mode 100644 index 0000000..baef2ef --- /dev/null +++ b/test/tst-remove-does-not-overwrite-files.sh @@ -0,0 +1,20 @@ +test_run() { + # Check that if a user overwrites a symlink with his own file, links-remove + # keeps it. + + test_setup + test_run_update + + # Simulate a user overwriting one of the symlinks with his own file. + rm -- "$test_dest_dir/bar/3.txt" + echo 'User content' > "$test_dest_dir/bar/3.txt" + + test_run_remove + + # 3.txt must be kept: + local expected_output="$test_dest_dir-> +$test_dest_dir/bar-> +$test_dest_dir/bar/3.txt->" + + test_verify_output "$test_dest_dir" "$expected_output" +} diff --git a/test/tst-remove-symlink.sh b/test/tst-remove-symlink.sh new file mode 100644 index 0000000..aa27435 --- /dev/null +++ b/test/tst-remove-symlink.sh @@ -0,0 +1,20 @@ +test_run() { + # Verify that links-remove doesn't delete shared symlinks. + + test_setup_symlink + test_run_update + test_run_remove + + local expected_output="$test_dest_dir->" + test_verify_output "$test_dest_dir" "$expected_output" + + log 'Verifying 3_copy.txt (the shared file) is valid...' + + local copy_target + copy_target="$( readlink -e -- "$test_src_dir/%DEST%/3_copy.txt" )" + test "$copy_target" = "$test_src_dir/%DEST%/bar/3.txt" + + local copy_content + copy_content="$( cat -- "$test_src_dir/%DEST%/3_copy.txt" )" + test "$copy_content" = '3' +} diff --git a/test/tst-remove.sh b/test/tst-remove.sh new file mode 100644 index 0000000..c79a3b4 --- /dev/null +++ b/test/tst-remove.sh @@ -0,0 +1,11 @@ +test_run() { + # Basic test to make sure links-remove actually removes the created + # symlinks. + + test_setup + test_run_update + test_run_remove + + local expected_output="$test_dest_dir->" + test_verify_output "$test_dest_dir" "$expected_output" +} diff --git a/test/tst-update-chmod.sh b/test/tst-update-chmod.sh new file mode 100644 index 0000000..a78ee15 --- /dev/null +++ b/test/tst-update-chmod.sh @@ -0,0 +1,19 @@ +test_run() { + # Test that links-update --mode works. + + test_setup + local expected_mode='0622' + test_run_update --mode "$expected_mode" + + local expected_output="$test_dest_dir-> +$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt +$test_dest_dir/bar-> +$test_dest_dir/bar/3.txt->$test_src_dir/%DEST%/bar/3.txt +$test_dest_dir/bar/baz-> +$test_dest_dir/bar/baz/4.txt->$test_src_dir/%DEST%/bar/baz/4.txt +$test_dest_dir/foo-> +$test_dest_dir/foo/2.txt->$test_src_dir/%DEST%/foo/2.txt" + + test_verify_output "$test_dest_dir" "$expected_output" + test_verify_mode "$test_src_dir/%DEST%/1.txt" "$expected_mode" +} diff --git a/test/tst-update-dir-symlink.sh b/test/tst-update-dir-symlink.sh new file mode 100644 index 0000000..27418ab --- /dev/null +++ b/test/tst-update-dir-symlink.sh @@ -0,0 +1,29 @@ +test_run() { + # We can symlink files to multiple directories by creating symlinks inside + # --shared-dir. + + test_setup_dir_symlink + test_run_update + + local expected_output="$test_dest_dir-> +$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt +$test_dest_dir/bar-> +$test_dest_dir/bar/3.txt->$test_src_dir/%DEST%/bar/3.txt +$test_dest_dir/bar/baz-> +$test_dest_dir/bar/baz/4.txt->$test_src_dir/%DEST%/bar/baz/4.txt +$test_dest_dir/foo-> +$test_dest_dir/foo/2.txt->$test_src_dir/%DEST%/foo/2.txt" + + test_verify_output "$test_dest_dir" "$expected_output" + + expected_output="$test_alt_dest_dir-> +$test_alt_dest_dir/1.txt->$test_src_dir/%ALT_DEST%/1.txt +$test_alt_dest_dir/bar-> +$test_alt_dest_dir/bar/3.txt->$test_src_dir/%ALT_DEST%/bar/3.txt +$test_alt_dest_dir/bar/baz-> +$test_alt_dest_dir/bar/baz/4.txt->$test_src_dir/%ALT_DEST%/bar/baz/4.txt +$test_alt_dest_dir/foo-> +$test_alt_dest_dir/foo/2.txt->$test_src_dir/%ALT_DEST%/foo/2.txt" + + test_verify_output "$test_alt_dest_dir" "$expected_output" +} diff --git a/test/tst-update-symlink.sh b/test/tst-update-symlink.sh new file mode 100644 index 0000000..6a90491 --- /dev/null +++ b/test/tst-update-symlink.sh @@ -0,0 +1,28 @@ +test_run() { + # Shared files can also be symlinks, pointing to something else. + + test_setup_symlink + test_run_update + + local expected_output="$test_dest_dir-> +$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt +$test_dest_dir/3_copy.txt->$test_src_dir/%DEST%/3_copy.txt +$test_dest_dir/bar-> +$test_dest_dir/bar/3.txt->$test_src_dir/%DEST%/bar/3.txt +$test_dest_dir/bar/baz-> +$test_dest_dir/bar/baz/4.txt->$test_src_dir/%DEST%/bar/baz/4.txt +$test_dest_dir/foo-> +$test_dest_dir/foo/2.txt->$test_src_dir/%DEST%/foo/2.txt" + + test_verify_output "$test_dest_dir" "$expected_output" + + log 'Verifying 3_copy.txt (the symlink) is valid...' + + local copy_target + copy_target="$( readlink -- "$test_dest_dir/3_copy.txt" )" + test "$copy_target" = "$test_src_dir/%DEST%/3_copy.txt" + + local copy_content + copy_content="$( cat -- "$test_dest_dir/3_copy.txt" )" + test "$copy_content" = '3' +} diff --git a/test/tst-update.sh b/test/tst-update.sh new file mode 100644 index 0000000..f33b929 --- /dev/null +++ b/test/tst-update.sh @@ -0,0 +1,18 @@ +test_run() { + # Basic test to make sure that links-update actually creates the proper + # symlinks. + + test_setup + test_run_update + + local expected_output="$test_dest_dir-> +$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt +$test_dest_dir/bar-> +$test_dest_dir/bar/3.txt->$test_src_dir/%DEST%/bar/3.txt +$test_dest_dir/bar/baz-> +$test_dest_dir/bar/baz/4.txt->$test_src_dir/%DEST%/bar/baz/4.txt +$test_dest_dir/foo-> +$test_dest_dir/foo/2.txt->$test_src_dir/%DEST%/foo/2.txt" + + test_verify_output "$test_dest_dir" "$expected_output" +} -- cgit v1.3