From aad165ae6cc9c9a70e1b712bc7b98f4f3e4c0ad8 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sun, 30 Jul 2023 23:05:24 +0200 Subject: [PATCH] more checks --- tests-ng/compare-negative-ignore-all-but.sh | 88 +++++++++++++++++++++ tests-ng/import-negative-ignore-all-but.sh | 88 +++++++++++++++++++++ tests-ng/install-negative-ignore-all-but.sh | 87 ++++++++++++++++++++ tests-ng/update-negative-ignore-all-but.sh | 4 +- 4 files changed, 265 insertions(+), 2 deletions(-) create mode 100755 tests-ng/compare-negative-ignore-all-but.sh create mode 100755 tests-ng/import-negative-ignore-all-but.sh create mode 100755 tests-ng/install-negative-ignore-all-but.sh diff --git a/tests-ng/compare-negative-ignore-all-but.sh b/tests-ng/compare-negative-ignore-all-but.sh new file mode 100755 index 0000000..6a3de88 --- /dev/null +++ b/tests-ng/compare-negative-ignore-all-but.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash +# author: deadc0de6 +# +# test negative ignore on compare +# returns 1 in case of error +# + +## start-cookie +set -e +cur=$(cd "$(dirname "${0}")" && pwd) +ddpath="${cur}/../" +export PYTHONPATH="${ddpath}:${PYTHONPATH}" +altbin="python3 -m dotdrop.dotdrop" +if hash coverage 2>/dev/null; then + altbin="coverage run -p --source=dotdrop -m dotdrop.dotdrop" +fi +bin="${DT_BIN:-${altbin}}" +# shellcheck source=tests-ng/helpers +source "${cur}"/helpers +echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" +## end-cookie + +################################################################ +# this is the test +################################################################ + +# dotdrop directory +basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) +# the dotfile to be updated +tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) + +echo "[+] dotdrop dir: ${basedir}" +echo "[+] dotpath dir: ${basedir}/dotfiles" +echo "[+] dst dir: ${tmpd}" + +# dotfiles in dotdrop +mkdir -p "${basedir}"/dotfiles/a/{b,c,x} +echo 'original' > "${basedir}"/dotfiles/a/b/abfile1 +echo 'original' > "${basedir}"/dotfiles/a/b/abfile2 +echo 'original' > "${basedir}"/dotfiles/a/b/abfile3 +echo 'original' > "${basedir}"/dotfiles/a/c/acfile +echo 'original' > "${basedir}"/dotfiles/a/x/axfile + +# filesystem +mkdir -p "${tmpd}"/a/{b,c,d,x} +echo "updated" > "${tmpd}/a/b/abfile1" +echo "updated" > "${tmpd}/a/b/abfile2" +echo "updated" > "${tmpd}/a/b/abfile3" +echo "updated" > "${tmpd}/a/c/acfile" +echo "updated" > "${tmpd}/a/d/adfile" +echo "updated" > "${tmpd}/a/x/axfile" + +clear_on_exit "${basedir}" +clear_on_exit "${tmpd}" + +# create the config file +cfg="${basedir}/config.yaml" +cat > "${cfg}" << _EOF +config: + backup: false + create: true + dotpath: dotfiles +dotfiles: + d_abc: + dst: ${tmpd}/a + src: a + cmpignore: + - "*" + - "!*/c/**" + - "!*/d/**" + - "!x/**" +profiles: + p1: + dotfiles: + - d_abc +_EOF + +# compare +echo "[+] compare" +set +e +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose --profile=p1 +ret="$?" +echo "return code: ${ret}" +[ "${ret}" != "1" ] && exit 1 +set -e + +echo "OK" +exit 0 diff --git a/tests-ng/import-negative-ignore-all-but.sh b/tests-ng/import-negative-ignore-all-but.sh new file mode 100755 index 0000000..c3207b8 --- /dev/null +++ b/tests-ng/import-negative-ignore-all-but.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash +# author: deadc0de6 +# +# test negative ignore on import +# returns 1 in case of error +# + +## start-cookie +set -e +cur=$(cd "$(dirname "${0}")" && pwd) +ddpath="${cur}/../" +export PYTHONPATH="${ddpath}:${PYTHONPATH}" +altbin="python3 -m dotdrop.dotdrop" +if hash coverage 2>/dev/null; then + altbin="coverage run -p --source=dotdrop -m dotdrop.dotdrop" +fi +bin="${DT_BIN:-${altbin}}" +# shellcheck source=tests-ng/helpers +source "${cur}"/helpers +echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" +## end-cookie + +################################################################ +# this is the test +################################################################ + +# $1 pattern +# $2 path +grep_or_fail() +{ + [ ! -e "${2}" ] && (echo "file ${2} does not exist" && exit 1) + grep "${1}" "${2}" >/dev/null 2>&1 || (echo "pattern \"${1}\" not found in ${2}" && exit 1) +} + +# dotdrop directory +basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) +# the dotfile to be updated +tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) + +echo "[+] dotdrop dir: ${basedir}" +echo "[+] dotpath dir: ${basedir}/dotfiles" +echo "[+] dst dir: ${tmpd}" + +# filesystem +mkdir -p "${tmpd}"/a/{b,c,d,x} +echo "updated" > "${tmpd}/a/b/abfile1" +echo "updated" > "${tmpd}/a/b/abfile2" +echo "updated" > "${tmpd}/a/b/abfile3" +echo "updated" > "${tmpd}/a/c/acfile" +echo "updated" > "${tmpd}/a/d/adfile" +echo "updated" > "${tmpd}/a/x/axfile" + +clear_on_exit "${basedir}" +clear_on_exit "${tmpd}" + +# create the config file +cfg="${basedir}/config.yaml" +cat > "${cfg}" << _EOF +config: + backup: false + create: true + dotpath: dotfiles + impignore: + - "*" + - "!*/c" + - "!*/d" + - "!*/x" +dotfiles: +profiles: + p1: +_EOF + +# import +echo "[+] import" +set +e +cd "${ddpath}" | ${bin} import -c "${cfg}" --verbose --profile=p1 "${tmpd}/a/b" +cd "${ddpath}" | ${bin} import -c "${cfg}" --verbose --profile=p1 "${tmpd}/a/c" +cd "${ddpath}" | ${bin} import -c "${cfg}" --verbose --profile=p1 "${tmpd}/a/d" +cd "${ddpath}" | ${bin} import -c "${cfg}" --verbose --profile=p1 "${tmpd}/a/x" +set -e + +[ -d "${basedir}/dotfiles/a/b" ] && (echo "/a/b created" && exit 1) +grep_or_fail "updated" "${basedir}/dotfiles/a/c/acfile" +grep_or_fail "updated" "${basedir}/dotfiles/a/d/adfile" +grep_or_fail "updated" "${basedir}/dotfiles/a/x/axfile" + +echo "OK" +exit 0 diff --git a/tests-ng/install-negative-ignore-all-but.sh b/tests-ng/install-negative-ignore-all-but.sh new file mode 100755 index 0000000..45e21b7 --- /dev/null +++ b/tests-ng/install-negative-ignore-all-but.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash +# author: deadc0de6 +# +# test negative ignore on install +# returns 1 in case of error +# + +## start-cookie +set -e +cur=$(cd "$(dirname "${0}")" && pwd) +ddpath="${cur}/../" +export PYTHONPATH="${ddpath}:${PYTHONPATH}" +altbin="python3 -m dotdrop.dotdrop" +if hash coverage 2>/dev/null; then + altbin="coverage run -p --source=dotdrop -m dotdrop.dotdrop" +fi +bin="${DT_BIN:-${altbin}}" +# shellcheck source=tests-ng/helpers +source "${cur}"/helpers +echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" +## end-cookie + +################################################################ +# this is the test +################################################################ + +# $1 pattern +# $2 path +grep_or_fail() +{ + [ ! -e "${2}" ] && (echo "file ${2} does not exist" && exit 1) + grep "${1}" "${2}" >/dev/null 2>&1 || (echo "pattern \"${1}\" not found in ${2}" && exit 1) +} + +# dotdrop directory +basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) +# the dotfile to be updated +tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) + +echo "[+] dotdrop dir: ${basedir}" +echo "[+] dotpath dir: ${basedir}/dotfiles" +echo "[+] dst dir: ${tmpd}" + +# dotfiles in dotdrop +mkdir -p "${basedir}"/dotfiles/a/{b,c,x} +echo 'original' > "${basedir}"/dotfiles/a/b/abfile1 +echo 'original' > "${basedir}"/dotfiles/a/b/abfile2 +echo 'original' > "${basedir}"/dotfiles/a/b/abfile3 +echo 'original' > "${basedir}"/dotfiles/a/c/acfile +echo 'original' > "${basedir}"/dotfiles/a/x/axfile + +clear_on_exit "${basedir}" +clear_on_exit "${tmpd}" + +# create the config file +cfg="${basedir}/config.yaml" +cat > "${cfg}" << _EOF +config: + backup: false + create: true + dotpath: dotfiles +dotfiles: + d_abc: + dst: ${tmpd}/a + src: a + instignore: + - "*" + - "!*/c/**" + - "!*/d/**" + - "!x/**" +profiles: + p1: + dotfiles: + - d_abc +_EOF + +# install +echo "[+] install" +cd "${ddpath}" | ${bin} install -f -c "${cfg}" --verbose --profile=p1 + +[ -d "${tmpd}/a/b" ] && (echo "/a/b created" && exit 1) +grep_or_fail "original" "${tmpd}/a/c/acfile" +#grep_or_fail "original" "${tmpd}/a/d/adfile" +grep_or_fail "original" "${tmpd}/a/x/axfile" + +echo "OK" +exit 0 diff --git a/tests-ng/update-negative-ignore-all-but.sh b/tests-ng/update-negative-ignore-all-but.sh index ae51a31..4bbe8ad 100755 --- a/tests-ng/update-negative-ignore-all-but.sh +++ b/tests-ng/update-negative-ignore-all-but.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -# author: jtt9340 (https://github.com/jtt9340) +# author: deadc0de6 # -# test negative ignore update +# test negative ignore on update # returns 1 in case of error #