1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-11 07:54:15 +00:00

shellcheck fixes

This commit is contained in:
deadc0de6
2023-01-27 16:44:19 +01:00
committed by deadc0de
parent fd26eb89b3
commit 2f1bbeacee
135 changed files with 4083 additions and 3950 deletions

View File

@@ -28,19 +28,22 @@ cur=$(dirname "$(${rl} "${0}")")
# dotdrop path can be pass as argument
ddpath="${cur}/../"
[ "${1}" != "" ] && ddpath="${1}"
[ ! -d ${ddpath} ] && echo "ddpath \"${ddpath}\" is not a directory" && exit 1
[ ! -d "${ddpath}" ] && echo "ddpath \"${ddpath}\" is not a directory" && exit 1
export PYTHONPATH="${ddpath}:${PYTHONPATH}"
bin="python3 -m dotdrop.dotdrop"
hash coverage 2>/dev/null && bin="coverage run -a --source=dotdrop -m dotdrop.dotdrop" || true
if hash coverage 2>/dev/null; then
bin="coverage run -a --source=dotdrop -m dotdrop.dotdrop"
fi
echo "dotdrop path: ${ddpath}"
echo "pythonpath: ${PYTHONPATH}"
# get the helpers
source ${cur}/helpers
# shellcheck source=tests-ng/helpers
source "${cur}"/helpers
echo -e "$(tput setaf 6)==> RUNNING $(basename $BASH_SOURCE) <==$(tput sgr0)"
echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)"
################################################################
# this is the test
@@ -54,12 +57,12 @@ grep_or_fail()
}
# the action temp
tmpa=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
tmpa=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
# the dotfile source
tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
mkdir -p ${tmps}/dotfiles
tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
mkdir -p "${tmps}"/dotfiles
# the dotfile destination
tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
clear_on_exit "${tmps}"
clear_on_exit "${tmpd}"
@@ -68,7 +71,7 @@ clear_on_exit "${tmpa}"
# create the config file
cfg="${tmps}/config.yaml"
cat > ${cfg} << _EOF
cat > "${cfg}" << _EOF
actions:
pre:
failpre: "false"
@@ -130,53 +133,53 @@ _EOF
#cat ${cfg}
# create the dotfile
echo 'test' > ${tmps}/dotfiles/abc
echo 'link' > ${tmps}/dotfiles/link
echo 'fail' > ${tmps}/dotfiles/fail
echo 'test' > "${tmps}"/dotfiles/abc
echo 'link' > "${tmps}"/dotfiles/link
echo 'fail' > "${tmps}"/dotfiles/fail
mkdir -p ${tmps}/dotfiles/dir
echo 'test1' > ${tmps}/dotfiles/dir/file1
echo 'test2' > ${tmps}/dotfiles/dir/file2
mkdir -p "${tmps}"/dotfiles/dir
echo 'test1' > "${tmps}"/dotfiles/dir/file1
echo 'test2' > "${tmps}"/dotfiles/dir/file2
mkdir -p ${tmps}/dotfiles/dlink
echo 'test3' > ${tmps}/dotfiles/dlink/dfile1
echo 'test4' > ${tmps}/dotfiles/dlink/dfile2
mkdir -p "${tmps}"/dotfiles/dlink
echo 'test3' > "${tmps}"/dotfiles/dlink/dfile1
echo 'test4' > "${tmps}"/dotfiles/dlink/dfile2
# install
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V
# checks
[ ! -e ${tmpa}/pre ] && echo 'pre action not executed' && exit 1
grep_or_fail pre ${tmpa}/pre
[ ! -e ${tmpa}/naked ] && echo 'naked action not executed' && exit 1
grep_or_fail naked ${tmpa}/naked
[ ! -e "${tmpa}"/pre ] && echo 'pre action not executed' && exit 1
grep_or_fail pre "${tmpa}"/pre
[ ! -e "${tmpa}"/naked ] && echo 'naked action not executed' && exit 1
grep_or_fail naked "${tmpa}"/naked
[ ! -e ${tmpa}/multiple ] && echo 'pre action multiple not executed' && exit 1
grep_or_fail multiple ${tmpa}/multiple
[ "`wc -l ${tmpa}/multiple | awk '{print $1}'`" -gt "1" ] && echo 'pre action multiple executed twice' && exit 1
[ ! -e "${tmpa}"/multiple ] && echo 'pre action multiple not executed' && exit 1
grep_or_fail multiple "${tmpa}"/multiple
[ "$(wc -l "${tmpa}"/multiple | awk '{print $1}')" -gt "1" ] && echo 'pre action multiple executed twice' && exit 1
[ ! -e ${tmpa}/pre2 ] && echo 'pre action 2 not executed' && exit 1
grep_or_fail pre2 ${tmpa}/pre2
[ ! -e ${tmpa}/naked2 ] && echo 'naked action 2 not executed' && exit 1
grep_or_fail naked2 ${tmpa}/naked2
[ ! -e "${tmpa}"/pre2 ] && echo 'pre action 2 not executed' && exit 1
grep_or_fail pre2 "${tmpa}"/pre2
[ ! -e "${tmpa}"/naked2 ] && echo 'naked action 2 not executed' && exit 1
grep_or_fail naked2 "${tmpa}"/naked2
[ ! -e ${tmpa}/multiple2 ] && echo 'pre action multiple 2 not executed' && exit 1
grep_or_fail multiple2 ${tmpa}/multiple2
[ "`wc -l ${tmpa}/multiple2 | awk '{print $1}'`" -gt "1" ] && echo 'pre action multiple 2 executed twice' && exit 1
[ ! -e ${tmpa}/naked3 ] && echo 'naked action 3 not executed' && exit 1
grep_or_fail naked3 ${tmpa}/naked3
[ ! -e "${tmpa}"/multiple2 ] && echo 'pre action multiple 2 not executed' && exit 1
grep_or_fail multiple2 "${tmpa}"/multiple2
[ "$(wc -l "${tmpa}"/multiple2 | awk '{print $1}')" -gt "1" ] && echo 'pre action multiple 2 executed twice' && exit 1
[ ! -e "${tmpa}"/naked3 ] && echo 'naked action 3 not executed' && exit 1
grep_or_fail naked3 "${tmpa}"/naked3
# remove the pre action result and re-install
rm ${tmpa}/pre
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
[ -e ${tmpa}/pre ] && echo "pre exists" && exit 1
rm "${tmpa}"/pre
cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V
[ -e "${tmpa}"/pre ] && echo "pre exists" && exit 1
# ensure failing actions make the installation fail
# install
set +e
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p2 -V
cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p2 -V
set -e
[ -e ${tmpd}/fail ] && echo "fail exists" && exit 1
[ -e "${tmpd}"/fail ] && echo "fail exists" && exit 1
echo "OK"
exit 0