diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-02-04 12:31:31 +0100 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-02-04 12:31:31 +0100 |
commit | c1f4b790c458f0de368f32487a007d571858207c (patch) | |
tree | 45d7293ea14d0b4249e2e286327b4d8490ff563e /test | |
parent | debian/README: update (diff) | |
parent | t/i: call links-update twice, just in case (diff) | |
download | config-links-c1f4b790c458f0de368f32487a007d571858207c.tar.gz config-links-c1f4b790c458f0de368f32487a007d571858207c.zip |
Merge tag 'v2.0.3' into debian
Diffstat (limited to '')
-rw-r--r-- | test/docker-compose.yml | 13 | ||||
-rw-r--r-- | test/docker/Dockerfile | 9 | ||||
-rwxr-xr-x | test/integration/test.sh | 91 | ||||
-rw-r--r-- | test/unit/dest/1.txt (renamed from test/dest/1.txt) | 0 | ||||
-rw-r--r-- | test/unit/dest/bar/3.txt (renamed from test/dest/bar/3.txt) | 0 | ||||
-rw-r--r-- | test/unit/src/%DEST%/1.txt (renamed from test/src/%DEST%/1.txt) | 0 | ||||
-rw-r--r-- | test/unit/src/%DEST%/bar/3.txt (renamed from test/src/%DEST%/bar/3.txt) | 0 | ||||
-rw-r--r-- | test/unit/src/%DEST%/bar/baz/4.txt (renamed from test/src/%DEST%/bar/baz/4.txt) | 0 | ||||
-rw-r--r-- | test/unit/src/%DEST%/foo/2.txt (renamed from test/src/%DEST%/foo/2.txt) | 0 | ||||
-rwxr-xr-x | test/unit/test.sh (renamed from test/test.sh) | 23 |
10 files changed, 132 insertions, 4 deletions
diff --git a/test/docker-compose.yml b/test/docker-compose.yml new file mode 100644 index 0000000..76546c4 --- /dev/null +++ b/test/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3' +services: + test: + build: + context: docker/ + args: + DISTRO: "${DISTRO:-xenial}" + volumes: + - ../:/src + command: + - sh + - -c + - /src/test/unit/test.sh && /src/test/integration/test.sh diff --git a/test/docker/Dockerfile b/test/docker/Dockerfile new file mode 100644 index 0000000..5d4d016 --- /dev/null +++ b/test/docker/Dockerfile @@ -0,0 +1,9 @@ +ARG DISTRO=xenial + +FROM ubuntu:$DISTRO + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive \ + apt-get install -y --no-install-recommends ca-certificates git + +RUN git config --global --add safe.directory /src diff --git a/test/integration/test.sh b/test/integration/test.sh new file mode 100755 index 0000000..f4b1028 --- /dev/null +++ b/test/integration/test.sh @@ -0,0 +1,91 @@ +#!/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/links-update" "$@" +} + +call_remove() { + call_bin_script "$root_dir/links-remove" +} + +call_chmod() { + call_bin_script "$root_dir/links-chmod" "$@" +} + +test_my_dotfiles_work() { + new_test + call_update + # Again: + call_update +} + +show_env() { + echo + echo ====================================================================== + echo Environment + echo ====================================================================== + + bash --version +} + +main() { + show_env + + test_my_dotfiles_work +} + +main diff --git a/test/dest/1.txt b/test/unit/dest/1.txt index 3a2e3f4..3a2e3f4 100644 --- a/test/dest/1.txt +++ b/test/unit/dest/1.txt diff --git a/test/dest/bar/3.txt b/test/unit/dest/bar/3.txt index a83d1d5..a83d1d5 100644 --- a/test/dest/bar/3.txt +++ b/test/unit/dest/bar/3.txt diff --git a/test/src/%DEST%/1.txt b/test/unit/src/%DEST%/1.txt index d00491f..d00491f 100644 --- a/test/src/%DEST%/1.txt +++ b/test/unit/src/%DEST%/1.txt diff --git a/test/src/%DEST%/bar/3.txt b/test/unit/src/%DEST%/bar/3.txt index 00750ed..00750ed 100644 --- a/test/src/%DEST%/bar/3.txt +++ b/test/unit/src/%DEST%/bar/3.txt diff --git a/test/src/%DEST%/bar/baz/4.txt b/test/unit/src/%DEST%/bar/baz/4.txt index b8626c4..b8626c4 100644 --- a/test/src/%DEST%/bar/baz/4.txt +++ b/test/unit/src/%DEST%/bar/baz/4.txt diff --git a/test/src/%DEST%/foo/2.txt b/test/unit/src/%DEST%/foo/2.txt index 0cfbf08..0cfbf08 100644 --- a/test/src/%DEST%/foo/2.txt +++ b/test/unit/src/%DEST%/foo/2.txt diff --git a/test/test.sh b/test/unit/test.sh index 05c5d65..f693aa1 100755 --- a/test/test.sh +++ b/test/unit/test.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash set -o errexit -o nounset -o pipefail -shopt -s inherit_errexit lastpipe +shopt -s inherit_errexit 2> /dev/null || true +shopt -s lastpipe script_dir="$( dirname -- "${BASH_SOURCE[0]}" )" script_dir="$( cd -- "$script_dir" && pwd )" @@ -9,6 +10,9 @@ 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' @@ -62,15 +66,15 @@ call_bin_script() { } call_update() { - call_bin_script "$script_dir/../links-update" "$@" + call_bin_script "$root_dir/links-update" "$@" } call_remove() { - call_bin_script "$script_dir/../links-remove" + call_bin_script "$root_dir/links-remove" } call_chmod() { - call_bin_script "$script_dir/../links-chmod" "$@" + call_bin_script "$root_dir/links-chmod" "$@" } verify_output() { @@ -413,7 +417,18 @@ $test_dest_dir/foo/2.txt->$test_src_dir/%DEST%/foo/2.txt" 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 |