aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/local
diff options
context:
space:
mode:
Diffstat (limited to 'test/local')
-rw-r--r--test/local/data/dest/1.txt (renamed from test/local/dirs/dest/1.txt)0
-rw-r--r--test/local/data/dest/bar/3.txt (renamed from test/local/dirs/dest/bar/3.txt)0
-rw-r--r--test/local/data/src/%DEST%/1.txt (renamed from test/local/dirs/src/%DEST%/1.txt)0
-rw-r--r--test/local/data/src/%DEST%/bar/3.txt (renamed from test/local/dirs/src/%DEST%/bar/3.txt)0
-rw-r--r--test/local/data/src/%DEST%/bar/baz/4.txt (renamed from test/local/dirs/src/%DEST%/bar/baz/4.txt)0
-rw-r--r--test/local/data/src/%DEST%/foo/2.txt (renamed from test/local/dirs/src/%DEST%/foo/2.txt)0
-rw-r--r--test/local/lib/common.sh41
-rw-r--r--test/local/tst-chmod.sh12
-rw-r--r--test/local/tst-dir-symlink-delete.sh10
-rw-r--r--test/local/tst-dir-symlink-remove-shared-file.sh10
-rw-r--r--test/local/tst-remove-dir-symlink.sh10
-rw-r--r--test/local/tst-remove-does-not-delete-user-dirs.sh8
-rw-r--r--test/local/tst-remove-does-not-overwrite-files.sh8
-rw-r--r--test/local/tst-remove-symlink.sh8
-rw-r--r--test/local/tst-remove.sh8
-rw-r--r--test/local/tst-update-chmod.sh8
-rw-r--r--test/local/tst-update-dir-symlink.sh8
-rw-r--r--test/local/tst-update-symlink.sh6
-rw-r--r--test/local/tst-update.sh6
19 files changed, 68 insertions, 75 deletions
diff --git a/test/local/dirs/dest/1.txt b/test/local/data/dest/1.txt
index 3a2e3f4..3a2e3f4 100644
--- a/test/local/dirs/dest/1.txt
+++ b/test/local/data/dest/1.txt
diff --git a/test/local/dirs/dest/bar/3.txt b/test/local/data/dest/bar/3.txt
index a83d1d5..a83d1d5 100644
--- a/test/local/dirs/dest/bar/3.txt
+++ b/test/local/data/dest/bar/3.txt
diff --git a/test/local/dirs/src/%DEST%/1.txt b/test/local/data/src/%DEST%/1.txt
index d00491f..d00491f 100644
--- a/test/local/dirs/src/%DEST%/1.txt
+++ b/test/local/data/src/%DEST%/1.txt
diff --git a/test/local/dirs/src/%DEST%/bar/3.txt b/test/local/data/src/%DEST%/bar/3.txt
index 00750ed..00750ed 100644
--- a/test/local/dirs/src/%DEST%/bar/3.txt
+++ b/test/local/data/src/%DEST%/bar/3.txt
diff --git a/test/local/dirs/src/%DEST%/bar/baz/4.txt b/test/local/data/src/%DEST%/bar/baz/4.txt
index b8626c4..b8626c4 100644
--- a/test/local/dirs/src/%DEST%/bar/baz/4.txt
+++ b/test/local/data/src/%DEST%/bar/baz/4.txt
diff --git a/test/local/dirs/src/%DEST%/foo/2.txt b/test/local/data/src/%DEST%/foo/2.txt
index 0cfbf08..0cfbf08 100644
--- a/test/local/dirs/src/%DEST%/foo/2.txt
+++ b/test/local/data/src/%DEST%/foo/2.txt
diff --git a/test/local/lib/common.sh b/test/local/lib/common.sh
index 9179376..fd9612b 100644
--- a/test/local/lib/common.sh
+++ b/test/local/lib/common.sh
@@ -3,23 +3,16 @@
# 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_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" )"
@@ -33,20 +26,20 @@ new_test() {
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"
+ 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"
}
-new_test_symlink() {
- new_test
+test_setup_symlink() {
+ test_setup
# Create a stupid symlink.
ln -s -- 'bar/3.txt' "$test_src_dir/%DEST%/3_copy.txt"
}
-new_test_dir_symlink() {
- new_test "${FUNCNAME[1]}"
+test_setup_dir_symlink() {
+ test_setup "${FUNCNAME[1]}"
# Files will get symlinks in the directory pointed to by $DEST, as well as
# by $ALT_DEST.
@@ -57,7 +50,7 @@ test_cleanup_default() {
[ -n "$test_root_dir" ] && rm -rf -- "$test_root_dir"
}
-call_bin_script() {
+test_run_script() {
echo
echo -n 'Executing script:'
@@ -68,19 +61,19 @@ call_bin_script() {
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" "$@"
+test_run_update() {
+ test_run_script "$script_dir/../../bin/links-update" "$@"
}
-call_remove() {
- call_bin_script "$root_dir/bin/links-remove"
+test_run_remove() {
+ test_run_script "$script_dir/../../bin/links-remove"
}
-call_chmod() {
- call_bin_script "$root_dir/bin/links-chmod" "$@"
+test_run_chmod() {
+ test_run_script "$script_dir/../../bin/links-chmod" "$@"
}
-verify_output() {
+test_verify_output() {
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
echo "usage: ${FUNCNAME[0]} EXPECTED_OUTPUT [DEST_DIR]" >&2
return 1
@@ -109,7 +102,7 @@ verify_output() {
fi
}
-verify_mode() {
+test_verify_mode() {
if [ "$#" -ne 2 ]; then
echo "usage: ${FUNCNAME[0]} EXPECTED_MODE FILE" >&2
return 1
diff --git a/test/local/tst-chmod.sh b/test/local/tst-chmod.sh
index c28c55b..2d70e06 100644
--- a/test/local/tst-chmod.sh
+++ b/test/local/tst-chmod.sh
@@ -1,8 +1,8 @@
test_run() {
# Test that links-chmod works.
- new_test
- call_update
+ test_setup
+ test_run_update
local expected_output="$test_dest_dir->
$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt
@@ -12,12 +12,12 @@ $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_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_verify_mode 0644 "$test_src_dir/%DEST%/1.txt"
+ test_run_chmod 0600
+ test_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
index 5d94bce..c8a9b46 100644
--- a/test/local/tst-dir-symlink-delete.sh
+++ b/test/local/tst-dir-symlink-delete.sh
@@ -2,12 +2,12 @@ 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
+ test_setup_dir_symlink
+ test_run_update
# Remove the directory symlink:
rm -- "$test_src_dir/%ALT_DEST%"
- call_update
+ test_run_update
local expected_output="$test_dest_dir->
$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt
@@ -18,8 +18,8 @@ $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_verify_output "$expected_output"
expected_output="$test_alt_dest_dir->"
- verify_output "$expected_output" "$test_alt_dest_dir"
+ test_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
index 758874d..7ac246b 100644
--- a/test/local/tst-dir-symlink-remove-shared-file.sh
+++ b/test/local/tst-dir-symlink-remove-shared-file.sh
@@ -1,12 +1,12 @@
test_run() {
# If we remove a shared file, both of the symlinks should be removed.
- new_test_dir_symlink
- call_update
+ test_setup_dir_symlink
+ test_run_update
# Remove a random shared file:
rm -- "$test_src_dir/%DEST%/bar/3.txt"
- call_update
+ test_run_update
local expected_output="$test_dest_dir->
$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt
@@ -16,7 +16,7 @@ $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_verify_output "$expected_output"
expected_output="$test_alt_dest_dir->
$test_alt_dest_dir/1.txt->$test_src_dir/%ALT_DEST%/1.txt
@@ -26,5 +26,5 @@ $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_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
index 143541c..ae32250 100644
--- a/test/local/tst-remove-dir-symlink.sh
+++ b/test/local/tst-remove-dir-symlink.sh
@@ -1,13 +1,13 @@
test_run() {
# Test that links-remove works for directory symlinks inside --shared-dir.
- new_test_dir_symlink
- call_update
- call_remove
+ test_setup_dir_symlink
+ test_run_update
+ test_run_remove
local expected_output="$test_dest_dir->"
- verify_output "$expected_output"
+ test_verify_output "$expected_output"
expected_output="$test_alt_dest_dir->"
- verify_output "$expected_output" "$test_alt_dest_dir"
+ test_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
index ef0e609..83c3869 100644
--- a/test/local/tst-remove-does-not-delete-user-dirs.sh
+++ b/test/local/tst-remove-does-not-delete-user-dirs.sh
@@ -2,18 +2,18 @@ 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
+ test_setup
+ test_run_update
# User adds his own file to the directory:
echo 'User content' > "$test_dest_dir/bar/my-file"
- call_remove
+ 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->"
- verify_output "$expected_output"
+ test_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
index cb51eb9..14641de 100644
--- a/test/local/tst-remove-does-not-overwrite-files.sh
+++ b/test/local/tst-remove-does-not-overwrite-files.sh
@@ -2,19 +2,19 @@ test_run() {
# Check that if a user overwrites a symlink with his own file, links-remove
# keeps it.
- new_test
- call_update
+ 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"
- call_remove
+ test_run_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_verify_output "$expected_output"
}
diff --git a/test/local/tst-remove-symlink.sh b/test/local/tst-remove-symlink.sh
index d9cf788..da61867 100644
--- a/test/local/tst-remove-symlink.sh
+++ b/test/local/tst-remove-symlink.sh
@@ -1,12 +1,12 @@
test_run() {
# Verify that links-remove doesn't delete shared symlinks.
- new_test_symlink
- call_update
- call_remove
+ test_setup_symlink
+ test_run_update
+ test_run_remove
local expected_output="$test_dest_dir->"
- verify_output "$expected_output"
+ test_verify_output "$expected_output"
echo
echo 'Verifying 3_copy.txt (the shared file) is valid...'
diff --git a/test/local/tst-remove.sh b/test/local/tst-remove.sh
index ebe6197..9e262c3 100644
--- a/test/local/tst-remove.sh
+++ b/test/local/tst-remove.sh
@@ -2,10 +2,10 @@ test_run() {
# Basic test to make sure links-remove actually removes the created
# symlinks.
- new_test
- call_update
- call_remove
+ test_setup
+ test_run_update
+ test_run_remove
local expected_output="$test_dest_dir->"
- verify_output "$expected_output"
+ test_verify_output "$expected_output"
}
diff --git a/test/local/tst-update-chmod.sh b/test/local/tst-update-chmod.sh
index 3f83f0f..8873c82 100644
--- a/test/local/tst-update-chmod.sh
+++ b/test/local/tst-update-chmod.sh
@@ -1,9 +1,9 @@
test_run() {
# Test that links-update --mode works.
- new_test
+ test_setup
local expected_mode='0622'
- call_update --mode "$expected_mode"
+ test_run_update --mode "$expected_mode"
local expected_output="$test_dest_dir->
$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt
@@ -13,7 +13,7 @@ $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_verify_output "$expected_output"
- verify_mode "$expected_mode" "$test_src_dir/%DEST%/1.txt"
+ test_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
index 003fd3c..5736481 100644
--- a/test/local/tst-update-dir-symlink.sh
+++ b/test/local/tst-update-dir-symlink.sh
@@ -2,8 +2,8 @@ test_run() {
# We can symlink files to multiple directories by creating symlinks inside
# --shared-dir.
- new_test_dir_symlink
- call_update
+ test_setup_dir_symlink
+ test_run_update
local expected_output="$test_dest_dir->
$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt
@@ -14,7 +14,7 @@ $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_verify_output "$expected_output"
expected_output="$test_alt_dest_dir->
$test_alt_dest_dir/1.txt->$test_src_dir/%ALT_DEST%/1.txt
@@ -25,5 +25,5 @@ $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_verify_output "$expected_output" "$test_alt_dest_dir"
}
diff --git a/test/local/tst-update-symlink.sh b/test/local/tst-update-symlink.sh
index 9954b7f..1a1f24c 100644
--- a/test/local/tst-update-symlink.sh
+++ b/test/local/tst-update-symlink.sh
@@ -1,8 +1,8 @@
test_run() {
# Shared files can also be symlinks, pointing to something else.
- new_test_symlink
- call_update
+ test_setup_symlink
+ test_run_update
local expected_output="$test_dest_dir->
$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt
@@ -14,7 +14,7 @@ $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_verify_output "$expected_output"
echo
echo 'Verifying 3_copy.txt (the symlink) is valid...'
diff --git a/test/local/tst-update.sh b/test/local/tst-update.sh
index 644114d..df22b71 100644
--- a/test/local/tst-update.sh
+++ b/test/local/tst-update.sh
@@ -2,8 +2,8 @@ test_run() {
# Basic test to make sure that links-update actually creates the proper
# symlinks.
- new_test
- call_update
+ test_setup
+ test_run_update
local expected_output="$test_dest_dir->
$test_dest_dir/1.txt->$test_src_dir/%DEST%/1.txt
@@ -14,5 +14,5 @@ $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_verify_output "$expected_output"
}