diff options
| author | Egor Tensin <egor@tensin.name> | 2026-09-27 15:32:05 +0500 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-09-27 15:33:42 +0500 |
| commit | 8cdbc58be21ed83644dab6a5391014ab4e35c9ab (patch) | |
| tree | 78ecb2897146b593601da52b1438d89434b560a8 | |
| parent | test/local: allow filtering tests (diff) | |
| download | config-links-8cdbc58be21ed83644dab6a5391014ab4e35c9ab.tar.gz config-links-8cdbc58be21ed83644dab6a5391014ab4e35c9ab.zip | |
test: move the linux-home test to test/local/
| -rw-r--r-- | Makefile | 8 | ||||
| -rw-r--r-- | test/docker/Dockerfile | 2 | ||||
| -rwxr-xr-x | test/linux-home/test.sh | 95 | ||||
| -rw-r--r-- | test/local/tst-linux-home.sh | 42 |
4 files changed, 43 insertions, 104 deletions
@@ -9,18 +9,10 @@ all: test .PHONY: test test: test/local -.PHONY: test/all -test/all: test/local test/docker - .PHONY: test/local test/local: ./test/local/main.sh -# This is deliberately excluded from test/all, because it's quite destructive. -.PHONY: test/linux-home -test/linux-home: - ./test/linux-home/test.sh - test/docker/%: DO cd test/docker && \ DISTRO='$*' docker compose --progress plain build --force-rm --pull -q && \ diff --git a/test/docker/Dockerfile b/test/docker/Dockerfile index 1090ccf..f1d4dbc 100644 --- a/test/docker/Dockerfile +++ b/test/docker/Dockerfile @@ -12,4 +12,4 @@ COPY [".", "/src"] WORKDIR /src -CMD ["make", "test/local", "test/linux-home"] +CMD ["make", "test/local"] diff --git a/test/linux-home/test.sh b/test/linux-home/test.sh deleted file mode 100755 index 5021048..0000000 --- a/test/linux-home/test.sh +++ /dev/null @@ -1,95 +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 - -src_name='linux-home' -readonly src_name -src_url="https://github.com/egor-tensin/$src_name.git" -readonly src_url - -test_root_dir= -test_src_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_name" - - echo "Root directory: $test_root_dir" - echo "Shared directory: $test_src_dir" - echo ====================================================================== - - git clone -q -- "$src_url" "$test_src_dir" - cd -- "$test_src_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 - "$@" --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" "$@" -} - -test_my_dotfiles_work() { - new_test - call_update - # Again: - call_update -} - -show_env() { - echo - echo ====================================================================== - echo Environment - echo ====================================================================== - - bash --version -} - -main() { - if [ -z "${CI:+x}" ]; then - echo "$script_name: please don't run it outside of CI runs" >&2 - exit 1 - fi - - show_env - test_my_dotfiles_work -} - -main diff --git a/test/local/tst-linux-home.sh b/test/local/tst-linux-home.sh new file mode 100644 index 0000000..4d099ee --- /dev/null +++ b/test/local/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 +} |
