From 89ccc2b233822409c7f104facac9d3293252eea4 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 21 May 2023 20:08:00 +0200 Subject: test: shuffle files around --- test/linux-home/test.sh | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 test/linux-home/test.sh (limited to 'test/linux-home') diff --git a/test/linux-home/test.sh b/test/linux-home/test.sh new file mode 100755 index 0000000..f4b1028 --- /dev/null +++ b/test/linux-home/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 -- cgit v1.2.3 From a87914970bb985176ad09c422f0942908492de0f Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 21 May 2023 20:23:16 +0200 Subject: t/l: fail unless $CI is set --- test/linux-home/test.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test/linux-home') diff --git a/test/linux-home/test.sh b/test/linux-home/test.sh index f4b1028..edb2d5b 100755 --- a/test/linux-home/test.sh +++ b/test/linux-home/test.sh @@ -83,8 +83,12 @@ show_env() { } main() { - show_env + 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 } -- cgit v1.2.3