summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-09-22 13:05:09 +0500
committerEgor Tensin <egor@tensin.name>2026-09-22 13:14:08 +0500
commit3241740ce3378d78db543ebab4f8ea127e184c73 (patch)
tree45bc883febadf5809ce62abea6845eb42840e12b
parentremove annoying trailing period from repo URLs (diff)
downloadconfig-links-3241740ce3378d78db543ebab4f8ea127e184c73.tar.gz
config-links-3241740ce3378d78db543ebab4f8ea127e184c73.zip
test/local: split test.sh into many files
-rw-r--r--Makefile2
-rw-r--r--test/local/lib/common.sh137
-rwxr-xr-xtest/local/main.sh87
-rwxr-xr-xtest/local/test.sh449
-rw-r--r--test/local/tst-chmod.sh23
-rw-r--r--test/local/tst-dir-symlink-delete.sh25
-rw-r--r--test/local/tst-dir-symlink-remove-shared-file.sh30
-rw-r--r--test/local/tst-remove-dir-symlink.sh13
-rw-r--r--test/local/tst-remove-does-not-delete-user-dirs.sh19
-rw-r--r--test/local/tst-remove-does-not-overwrite-files.sh20
-rw-r--r--test/local/tst-remove-symlink.sh21
-rw-r--r--test/local/tst-remove.sh11
-rw-r--r--test/local/tst-update-chmod.sh19
-rw-r--r--test/local/tst-update-dir-symlink.sh29
-rw-r--r--test/local/tst-update-symlink.sh29
-rw-r--r--test/local/tst-update.sh18
16 files changed, 482 insertions, 450 deletions
diff --git a/Makefile b/Makefile
index 24be841..b9c6cb2 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ test/all: test/local test/docker
.PHONY: test/local
test/local:
- ./test/local/test.sh
+ ./test/local/main.sh
# This is deliberately excluded from test/all, because it's quite destructive.
.PHONY: test/linux-home
diff --git a/test/local/lib/common.sh b/test/local/lib/common.sh
new file mode 100644
index 0000000..9179376
--- /dev/null
+++ b/test/local/lib/common.sh
@@ -0,0 +1,137 @@
+# Copyright (c) 2026 Egor Tensin <egor@tensin.name>
+# This file is part of the "config-links" project.
+# For details, see https://github.com/egor-tensin/config-links
+# Distributed under the MIT License.
+
+root_dir=
+
+src_dir_name='src'
+dest_dir_name='dest'
+alt_dest_dir_name='alt_dest'
+
+src_dir_path="$script_dir/dirs/$src_dir_name"
+dest_dir_path="$script_dir/dirs/$dest_dir_name"
+
+test_root_dir=
+test_src_dir=
+test_dest_dir=
+test_alt_dest_dir=
+
+new_test() {
+ root_dir="$( git -C "$script_dir" rev-parse --show-toplevel )"
+
+ 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"
+
+ echo "Root directory: $test_root_dir"
+ echo "Shared directory: $test_src_dir"
+ echo "%DEST% directory: $test_dest_dir"
+ echo "%ALT_DEST% directory: $test_alt_dest_dir"
+
+ cp -r -- "$src_dir_path" "$test_src_dir"
+ cp -r -- "$dest_dir_path" "$test_dest_dir"
+ cp -r -- "$dest_dir_path" "$test_alt_dest_dir"
+}
+
+new_test_symlink() {
+ new_test
+
+ # Create a stupid symlink.
+ ln -s -- 'bar/3.txt' "$test_src_dir/%DEST%/3_copy.txt"
+}
+
+new_test_dir_symlink() {
+ new_test "${FUNCNAME[1]}"
+
+ # 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() {
+ [ -n "$test_root_dir" ] && rm -rf -- "$test_root_dir"
+}
+
+call_bin_script() {
+ echo
+ echo -n 'Executing script:'
+
+ printf -- ' %q' "$@" --shared-dir "$test_src_dir" --database "$test_root_dir/links.bin"
+ printf -- '\n'
+
+ echo
+ DEST="$test_dest_dir" ALT_DEST="$test_alt_dest_dir" "$@" --shared-dir "$test_src_dir" --database "$test_root_dir/links.bin"
+}
+
+call_update() {
+ call_bin_script "$root_dir/bin/links-update" "$@"
+}
+
+call_remove() {
+ call_bin_script "$root_dir/bin/links-remove"
+}
+
+call_chmod() {
+ call_bin_script "$root_dir/bin/links-chmod" "$@"
+}
+
+verify_output() {
+ if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
+ echo "usage: ${FUNCNAME[0]} EXPECTED_OUTPUT [DEST_DIR]" >&2
+ return 1
+ fi
+
+ local expected_output="$1"
+ echo
+ echo 'Expected directory structure:'
+ echo "$expected_output"
+
+ local dest_dir="$test_dest_dir"
+ [ "$#" -ge 2 ] && dest_dir="$2"
+
+ local actual_output
+ actual_output="$( find "$dest_dir" -printf '%h/%f->%l\n' | sort )"
+ echo
+ echo 'Actual directory structure:'
+ echo "$actual_output"
+ echo
+
+ if [ "$actual_output" = "$expected_output" ]; then
+ echo "... They match!"
+ else
+ echo "... The actual directory structure does not match the expected directory structure!" >&2
+ return 1
+ fi
+}
+
+verify_mode() {
+ if [ "$#" -ne 2 ]; then
+ echo "usage: ${FUNCNAME[0]} EXPECTED_MODE FILE" >&2
+ return 1
+ fi
+
+ local expected_mode="$1"
+ local path="$2"
+
+ echo
+ echo "Checking permissions for file: $path"
+ echo "Expected mode: $expected_mode"
+
+ local actual_mode
+ actual_mode="$( stat -c '%a' -- "$path" )"
+ actual_mode="0$actual_mode"
+
+ echo "Actual mode: $actual_mode"
+
+ if [ "$actual_mode" = "$expected_mode" ]; then
+ echo "... They match!"
+ else
+ echo "... They don't match."
+ return 1
+ fi
+}
diff --git a/test/local/main.sh b/test/local/main.sh
new file mode 100755
index 0000000..cba7ab7
--- /dev/null
+++ b/test/local/main.sh
@@ -0,0 +1,87 @@
+#!/usr/bin/env bash
+
+# Copyright (c) 2026 Egor Tensin <egor@tensin.name>
+# 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
+
+declare -a failed_tests=()
+
+run_test_file() {
+ local test_file
+ for test_file; do
+ echo
+ echo ======================================================================
+ echo "Running test: $test_file"
+ echo ======================================================================
+
+ source "$script_dir/lib/common.sh"
+ source "$script_dir/$test_file"
+
+ echo "Should fail? ${test_should_fail:-No}"
+
+ 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 ec="$?"
+ set -e
+
+ if [ "$ec" -eq 0 ] || [ -n "${test_should_fail:+Yes}" ]; then
+ echo ----------------------------------------------------------------------
+ echo "OK: $test_file"
+ echo ----------------------------------------------------------------------
+ else
+ echo ----------------------------------------------------------------------
+ echo "FAIL: $test_file"
+ echo ----------------------------------------------------------------------
+ failed_tests+=("$test_file")
+ fi
+ done
+}
+
+main() {
+ local -a test_files=()
+
+ find "$script_dir" \
+ -mindepth 1 \
+ -maxdepth 1 \
+ -type f \
+ -regex '.*/tst-.*\.sh$' \
+ -regextype posix-basic \
+ -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[@]}"}
+
+ if [ "${#failed_tests[@]}" -gt 0 ]; then
+ echo
+ echo ======================================================================
+ echo "FAILED TESTS:" ${failed_tests[@]+"${failed_tests[@]}"}
+ echo ======================================================================
+ return 1
+ fi
+}
+
+main
diff --git a/test/local/test.sh b/test/local/test.sh
deleted file mode 100755
index 1e8567f..0000000
--- a/test/local/test.sh
+++ /dev/null
@@ -1,449 +0,0 @@
-#!/usr/bin/env bash
-
-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
-
-root_dir="$( git -C "$script_dir" rev-parse --show-toplevel )"
-readonly root_dir
-
-readonly src_dir_name='src'
-readonly dest_dir_name='dest'
-readonly alt_dest_dir_name='alt_dest'
-
-src_dir_path="$script_dir/dirs/$src_dir_name"
-readonly src_dir_path
-dest_dir_path="$script_dir/dirs/$dest_dir_name"
-readonly dest_dir_path
-
-test_root_dir=
-test_src_dir=
-test_dest_dir=
-test_alt_dest_dir=
-
-new_test() {
- local test_name=
- [ "${#FUNCNAME[@]}" -gt 1 ] && test_name="${FUNCNAME[1]}"
- [ "$#" -gt 0 ] && test_name="$1"
-
- echo
- echo ======================================================================
- echo "New test: $test_name"
-
- 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"
-
- echo "Root directory: $test_root_dir"
- echo "Shared directory: $test_src_dir"
- echo "%DEST% directory: $test_dest_dir"
- echo "%ALT_DEST% directory: $test_alt_dest_dir"
- echo ======================================================================
-
- cp -r -- "$src_dir_path" "$test_src_dir"
- cp -r -- "$dest_dir_path" "$test_dest_dir"
- cp -r -- "$dest_dir_path" "$test_alt_dest_dir"
-}
-
-call_bin_script() {
- echo
- echo -n 'Executing script:'
-
- printf -- ' %q' "$@" --shared-dir "$test_src_dir" --database "$test_root_dir/links.bin"
- printf -- '\n'
-
- echo
- DEST="$test_dest_dir" ALT_DEST="$test_alt_dest_dir" "$@" --shared-dir "$test_src_dir" --database "$test_root_dir/links.bin"
-}
-
-call_update() {
- call_bin_script "$root_dir/bin/links-update" "$@"
-}
-
-call_remove() {
- call_bin_script "$root_dir/bin/links-remove"
-}
-
-call_chmod() {
- call_bin_script "$root_dir/bin/links-chmod" "$@"
-}
-
-verify_output() {
- if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
- echo "usage: ${FUNCNAME[0]} EXPECTED_OUTPUT [DEST_DIR]" >&2
- return 1
- fi
-
- local expected_output="$1"
- echo
- echo 'Expected directory structure:'
- echo "$expected_output"
-
- local dest_dir="$test_dest_dir"
- [ "$#" -ge 2 ] && dest_dir="$2"
-
- local actual_output
- actual_output="$( find "$dest_dir" -printf '%h/%f->%l\n' | sort )"
- echo
- echo 'Actual directory structure:'
- echo "$actual_output"
- echo
-
- if [ "$actual_output" = "$expected_output" ]; then
- echo "... They match!"
- else
- echo "... The actual directory structure does not match the expected directory structure!" >&2
- return 1
- fi
-}
-
-verify_mode() {
- if [ "$#" -ne 2 ]; then
- echo "usage: ${FUNCNAME[0]} EXPECTED_MODE FILE" >&2
- return 1
- fi
-
- local expected_mode="$1"
- local path="$2"
-
- echo
- echo "Checking permissions for file: $path"
- echo "Expected mode: $expected_mode"
-
- local actual_mode
- actual_mode="$( stat -c '%a' -- "$path" )"
- actual_mode="0$actual_mode"
-
- echo "Actual mode: $actual_mode"
-
- if [ "$actual_mode" = "$expected_mode" ]; then
- echo "... They match!"
- else
- echo "... They don't match."
- return 1
- fi
-}
-
-test_update_works() {
- # Basic test to make sure that links-update actually creates the proper
- # symlinks.
-
- new_test
- call_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"
-
- verify_output "$expected_output"
-}
-
-test_remove_works() {
- # Basic test to make sure links-remove actually removes the created
- # symlinks.
-
- new_test
- call_update
- call_remove
-
- local expected_output="$test_dest_dir->"
- verify_output "$expected_output"
-}
-
-test_remove_does_not_overwrite_files() {
- # Check that if a user overwrites a symlink with his own file, links-remove
- # keeps it.
-
- new_test
- call_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"
-
- call_remove
-
- # 3.txt must be kept:
- local expected_output="$test_dest_dir->
-$test_dest_dir/bar->
-$test_dest_dir/bar/3.txt->"
-
- verify_output "$expected_output"
-}
-
-test_remove_does_not_delete_used_dirs() {
- # Check that if a user adds a file to a destination directory, it's not
- # deleted by links-remove.
-
- new_test
- call_update
-
- # User adds his own file to the directory:
- echo 'User content' > "$test_dest_dir/bar/my-file"
-
- call_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->"
-
- verify_output "$expected_output"
-}
-
-new_test_dir_symlink() {
- new_test "${FUNCNAME[1]}"
-
- # 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_dir_symlink_update_works() {
- # We can symlink files to multiple directories by creating symlinks inside
- # --shared-dir.
-
- new_test_dir_symlink
- call_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"
-
- verify_output "$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"
-
- verify_output "$expected_output" "$test_alt_dest_dir"
-}
-
-test_dir_symlink_remove_works() {
- # Test that links-remove works for directory symlinks inside --shared-dir.
-
- new_test_dir_symlink
- call_update
- call_remove
-
- local expected_output="$test_dest_dir->"
- verify_output "$expected_output"
-
- expected_output="$test_alt_dest_dir->"
- verify_output "$expected_output" "$test_alt_dest_dir"
-}
-
-test_dir_symlink_remove_shared_file() {
- # If we remove a shared file, both of the symlinks should be removed.
-
- new_test_dir_symlink
- call_update
-
- # Remove a random shared file:
- rm -- "$test_src_dir/%DEST%/bar/3.txt"
- call_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"
-
- verify_output "$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"
-
- verify_output "$expected_output" "$test_alt_dest_dir"
-}
-
-test_dir_symlink_remove_dir_symlink() {
- # If we remove a directory symlink in --shared-dir, all the symlinks
- # accessible through this directory symlink should be removed.
-
- new_test_dir_symlink
- call_update
-
- # Remove the directory symlink:
- rm -- "$test_src_dir/%ALT_DEST%"
- call_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"
-
- verify_output "$expected_output"
-
- expected_output="$test_alt_dest_dir->"
- verify_output "$expected_output" "$test_alt_dest_dir"
-}
-
-new_test_symlink() {
- new_test "${FUNCNAME[1]}"
-
- # Create a stupid symlink.
- ln -s -- 'bar/3.txt' "$test_src_dir/%DEST%/3_copy.txt"
-}
-
-test_symlink_update_works() {
- # Shared files can also be symlinks, pointing to something else.
-
- new_test_symlink
- call_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"
-
- verify_output "$expected_output"
-
- echo
- echo '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'
-}
-
-test_symlink_remove_works() {
- # Verify that links-remove doesn't delete shared symlinks.
-
- new_test_symlink
- call_update
- call_remove
-
- local expected_output="$test_dest_dir->"
- verify_output "$expected_output"
-
- echo
- echo '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'
-}
-
-test_chmod_works() {
- # Test that links-chmod works.
-
- new_test
- call_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"
- verify_output "$expected_output"
-
- echo
- echo 'Verifying 1.txt (the shared file) permissions...'
-
- verify_mode 0644 "$test_src_dir/%DEST%/1.txt"
- call_chmod 0600
- verify_mode 0600 "$test_src_dir/%DEST%/1.txt"
-}
-
-test_update_chmod() {
- # Test that links-update --mode works.
-
- new_test
- local expected_mode='0622'
- call_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"
- verify_output "$expected_output"
-
- verify_mode "$expected_mode" "$test_src_dir/%DEST%/1.txt"
-}
-
-show_env() {
- echo
- echo ======================================================================
- echo Environment
- echo ======================================================================
-
- bash --version
-}
-
-main() {
- show_env
-
- test_update_works
- test_remove_works
- test_remove_does_not_overwrite_files
- test_remove_does_not_delete_used_dirs
-
- test_dir_symlink_update_works
- test_dir_symlink_remove_works
- test_dir_symlink_remove_shared_file
- test_dir_symlink_remove_dir_symlink
-
- test_symlink_update_works
- test_symlink_remove_works
-
- test_chmod_works
- test_update_chmod
-}
-
-main
diff --git a/test/local/tst-chmod.sh b/test/local/tst-chmod.sh
new file mode 100644
index 0000000..c28c55b
--- /dev/null
+++ b/test/local/tst-chmod.sh
@@ -0,0 +1,23 @@
+test_run() {
+ # Test that links-chmod works.
+
+ new_test
+ call_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"
+ verify_output "$expected_output"
+
+ echo
+ echo 'Verifying 1.txt (the shared file) permissions...'
+
+ verify_mode 0644 "$test_src_dir/%DEST%/1.txt"
+ call_chmod 0600
+ verify_mode 0600 "$test_src_dir/%DEST%/1.txt"
+}
diff --git a/test/local/tst-dir-symlink-delete.sh b/test/local/tst-dir-symlink-delete.sh
new file mode 100644
index 0000000..5d94bce
--- /dev/null
+++ b/test/local/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.
+
+ new_test_dir_symlink
+ call_update
+
+ # Remove the directory symlink:
+ rm -- "$test_src_dir/%ALT_DEST%"
+ call_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"
+
+ verify_output "$expected_output"
+
+ expected_output="$test_alt_dest_dir->"
+ verify_output "$expected_output" "$test_alt_dest_dir"
+}
diff --git a/test/local/tst-dir-symlink-remove-shared-file.sh b/test/local/tst-dir-symlink-remove-shared-file.sh
new file mode 100644
index 0000000..758874d
--- /dev/null
+++ b/test/local/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.
+
+ new_test_dir_symlink
+ call_update
+
+ # Remove a random shared file:
+ rm -- "$test_src_dir/%DEST%/bar/3.txt"
+ call_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"
+
+ verify_output "$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"
+
+ verify_output "$expected_output" "$test_alt_dest_dir"
+}
diff --git a/test/local/tst-remove-dir-symlink.sh b/test/local/tst-remove-dir-symlink.sh
new file mode 100644
index 0000000..143541c
--- /dev/null
+++ b/test/local/tst-remove-dir-symlink.sh
@@ -0,0 +1,13 @@
+test_run() {
+ # Test that links-remove works for directory symlinks inside --shared-dir.
+
+ new_test_dir_symlink
+ call_update
+ call_remove
+
+ local expected_output="$test_dest_dir->"
+ verify_output "$expected_output"
+
+ expected_output="$test_alt_dest_dir->"
+ verify_output "$expected_output" "$test_alt_dest_dir"
+}
diff --git a/test/local/tst-remove-does-not-delete-user-dirs.sh b/test/local/tst-remove-does-not-delete-user-dirs.sh
new file mode 100644
index 0000000..ef0e609
--- /dev/null
+++ b/test/local/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.
+
+ new_test
+ call_update
+
+ # User adds his own file to the directory:
+ echo 'User content' > "$test_dest_dir/bar/my-file"
+
+ call_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->"
+
+ verify_output "$expected_output"
+}
diff --git a/test/local/tst-remove-does-not-overwrite-files.sh b/test/local/tst-remove-does-not-overwrite-files.sh
new file mode 100644
index 0000000..cb51eb9
--- /dev/null
+++ b/test/local/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.
+
+ new_test
+ call_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"
+
+ call_remove
+
+ # 3.txt must be kept:
+ local expected_output="$test_dest_dir->
+$test_dest_dir/bar->
+$test_dest_dir/bar/3.txt->"
+
+ verify_output "$expected_output"
+}
diff --git a/test/local/tst-remove-symlink.sh b/test/local/tst-remove-symlink.sh
new file mode 100644
index 0000000..d9cf788
--- /dev/null
+++ b/test/local/tst-remove-symlink.sh
@@ -0,0 +1,21 @@
+test_run() {
+ # Verify that links-remove doesn't delete shared symlinks.
+
+ new_test_symlink
+ call_update
+ call_remove
+
+ local expected_output="$test_dest_dir->"
+ verify_output "$expected_output"
+
+ echo
+ echo '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
new file mode 100644
index 0000000..ebe6197
--- /dev/null
+++ b/test/local/tst-remove.sh
@@ -0,0 +1,11 @@
+test_run() {
+ # Basic test to make sure links-remove actually removes the created
+ # symlinks.
+
+ new_test
+ call_update
+ call_remove
+
+ local expected_output="$test_dest_dir->"
+ verify_output "$expected_output"
+}
diff --git a/test/local/tst-update-chmod.sh b/test/local/tst-update-chmod.sh
new file mode 100644
index 0000000..3f83f0f
--- /dev/null
+++ b/test/local/tst-update-chmod.sh
@@ -0,0 +1,19 @@
+test_run() {
+ # Test that links-update --mode works.
+
+ new_test
+ local expected_mode='0622'
+ call_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"
+ verify_output "$expected_output"
+
+ verify_mode "$expected_mode" "$test_src_dir/%DEST%/1.txt"
+}
diff --git a/test/local/tst-update-dir-symlink.sh b/test/local/tst-update-dir-symlink.sh
new file mode 100644
index 0000000..003fd3c
--- /dev/null
+++ b/test/local/tst-update-dir-symlink.sh
@@ -0,0 +1,29 @@
+test_run() {
+ # We can symlink files to multiple directories by creating symlinks inside
+ # --shared-dir.
+
+ new_test_dir_symlink
+ call_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"
+
+ verify_output "$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"
+
+ verify_output "$expected_output" "$test_alt_dest_dir"
+}
diff --git a/test/local/tst-update-symlink.sh b/test/local/tst-update-symlink.sh
new file mode 100644
index 0000000..9954b7f
--- /dev/null
+++ b/test/local/tst-update-symlink.sh
@@ -0,0 +1,29 @@
+test_run() {
+ # Shared files can also be symlinks, pointing to something else.
+
+ new_test_symlink
+ call_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"
+
+ verify_output "$expected_output"
+
+ echo
+ echo '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
new file mode 100644
index 0000000..644114d
--- /dev/null
+++ b/test/local/tst-update.sh
@@ -0,0 +1,18 @@
+test_run() {
+ # Basic test to make sure that links-update actually creates the proper
+ # symlinks.
+
+ new_test
+ call_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"
+
+ verify_output "$expected_output"
+}