1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-12 08:58:29 +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

@@ -27,30 +27,33 @@ 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
################################################################
# the dotfile source
tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
mkdir -p ${tmps}/dotfiles
mkdir -p ${tmps}/dotfiles-other
tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
mkdir -p "${tmps}"/dotfiles
mkdir -p "${tmps}"/dotfiles-other
# 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}"
@@ -59,7 +62,7 @@ clear_on_exit "${tmpd}"
cfg1="${tmps}/config1.yaml"
cfg2="${tmps}/config2.yaml"
cat > ${cfg1} << _EOF
cat > "${cfg1}" << _EOF
config:
backup: true
create: true
@@ -91,7 +94,7 @@ profiles:
- psubsub
_EOF
cat > ${cfg2} << _EOF
cat > "${cfg2}" << _EOF
config:
backup: true
create: true
@@ -117,47 +120,47 @@ profiles:
_EOF
# create the source
mkdir -p ${tmps}/dotfiles/
echo "abc" > ${tmps}/dotfiles/abc
echo "{{@@ _dotfile_abs_dst @@}}" >> ${tmps}/dotfiles/abc
mkdir -p "${tmps}"/dotfiles/
echo "abc" > "${tmps}"/dotfiles/abc
echo "{{@@ _dotfile_abs_dst @@}}" >> "${tmps}"/dotfiles/abc
echo "def" > ${tmps}/dotfiles-other/def
echo "{{@@ _dotfile_abs_dst @@}}" >> ${tmps}/dotfiles-other/def
echo "def" > "${tmps}"/dotfiles-other/def
echo "{{@@ _dotfile_abs_dst @@}}" >> "${tmps}"/dotfiles-other/def
echo "ghi" > ${tmps}/dotfiles-other/ghi
echo "{{@@ _dotfile_abs_dst @@}}" >> ${tmps}/dotfiles-other/ghi
echo "ghi" > "${tmps}"/dotfiles-other/ghi
echo "{{@@ _dotfile_abs_dst @@}}" >> "${tmps}"/dotfiles-other/ghi
echo "zzz" > ${tmps}/dotfiles/zzz
echo "{{@@ _dotfile_abs_dst @@}}" >> ${tmps}/dotfiles/zzz
echo "zzz" > "${tmps}"/dotfiles/zzz
echo "{{@@ _dotfile_abs_dst @@}}" >> "${tmps}"/dotfiles/zzz
echo "sub" > ${tmps}/dotfiles/sub
echo "{{@@ _dotfile_abs_dst @@}}" >> ${tmps}/dotfiles/sub
echo "sub" > "${tmps}"/dotfiles/sub
echo "{{@@ _dotfile_abs_dst @@}}" >> "${tmps}"/dotfiles/sub
mkdir -p ${tmps}/dotfiles-other/subdir/sub
echo "subsub" > ${tmps}/dotfiles-other/subdir/sub/asub
echo "{{@@ _dotfile_abs_dst @@}}" >> ${tmps}/dotfiles-other/subdir/sub/asub
mkdir -p "${tmps}"/dotfiles-other/subdir/sub
echo "subsub" > "${tmps}"/dotfiles-other/subdir/sub/asub
echo "{{@@ _dotfile_abs_dst @@}}" >> "${tmps}"/dotfiles-other/subdir/sub/asub
# files comparison
cd ${ddpath} | ${bin} files -c ${cfg1} -G -p p0 | grep '^f_def'
cd ${ddpath} | ${bin} files -c ${cfg1} -G -p p1 | grep '^f_abc'
cd ${ddpath} | ${bin} files -c ${cfg1} -G -p p2 | grep '^f_def'
cd ${ddpath} | ${bin} files -c ${cfg1} -G -p p3 | grep '^f_zzz'
cd ${ddpath} | ${bin} files -c ${cfg1} -G -p pup | grep '^f_sub'
cd ${ddpath} | ${bin} files -c ${cfg1} -G -p psubsub | grep '^f_sub'
cd "${ddpath}" | ${bin} files -c "${cfg1}" -G -p p0 | grep '^f_def'
cd "${ddpath}" | ${bin} files -c "${cfg1}" -G -p p1 | grep '^f_abc'
cd "${ddpath}" | ${bin} files -c "${cfg1}" -G -p p2 | grep '^f_def'
cd "${ddpath}" | ${bin} files -c "${cfg1}" -G -p p3 | grep '^f_zzz'
cd "${ddpath}" | ${bin} files -c "${cfg1}" -G -p pup | grep '^f_sub'
cd "${ddpath}" | ${bin} files -c "${cfg1}" -G -p psubsub | grep '^f_sub'
# test compare too
cd ${ddpath} | ${bin} install -c ${cfg1} -p p2 -V -f
cd ${ddpath} | ${bin} compare -c ${cfg1} -p p2 -V
cd "${ddpath}" | ${bin} install -c "${cfg1}" -p p2 -V -f
cd "${ddpath}" | ${bin} compare -c "${cfg1}" -p p2 -V
[ ! -s ${tmpd}/def ] && echo "def not installed" && exit 1
[ ! -s ${tmpd}/subdir/sub/asub ] && echo "asub not installed" && exit 1
[ ! -s "${tmpd}"/def ] && echo "def not installed" && exit 1
[ ! -s "${tmpd}"/subdir/sub/asub ] && echo "asub not installed" && exit 1
# test with non-existing dotpath this time
rm -rf ${tmps}/dotfiles
rm -rf ${tmpd}/*
rm -rf "${tmps}"/dotfiles
rm -rf "${tmpd}"/*
cat > ${cfg1} << _EOF
cat > "${cfg1}" << _EOF
config:
backup: true
create: true
@@ -167,7 +170,7 @@ config:
dotfiles:
profiles:
_EOF
cat > ${cfg2} << _EOF
cat > "${cfg2}" << _EOF
config:
backup: true
create: true
@@ -182,14 +185,14 @@ profiles:
- f_asub
_EOF
cd ${ddpath} | ${bin} install -c ${cfg1} -p p2 -V -f
cd ${ddpath} | ${bin} compare -c ${cfg1} -p p2 -V
cd "${ddpath}" | ${bin} install -c "${cfg1}" -p p2 -V -f
cd "${ddpath}" | ${bin} compare -c "${cfg1}" -p p2 -V
# test with same profile defined in both
rm -rf ${tmps}/dotfiles
rm -rf ${tmpd}/*
rm -rf "${tmps}"/dotfiles
rm -rf "${tmpd}"/*
cat > ${cfg1} << _EOF
cat > "${cfg1}" << _EOF
config:
backup: true
create: true
@@ -205,7 +208,7 @@ profiles:
dotfiles:
- f_abc
_EOF
cat > ${cfg2} << _EOF
cat > "${cfg2}" << _EOF
config:
backup: true
create: true
@@ -221,30 +224,30 @@ profiles:
_EOF
# create the source
mkdir -p ${tmps}/dotfiles/
mkdir -p "${tmps}"/dotfiles/
echo "abc" > ${tmps}/dotfiles/abc
echo "{{@@ _dotfile_abs_dst @@}}" >> ${tmps}/dotfiles/abc
rm -f ${tmpd}/abc
echo "abc" > "${tmps}"/dotfiles/abc
echo "{{@@ _dotfile_abs_dst @@}}" >> "${tmps}"/dotfiles/abc
rm -f "${tmpd}"/abc
echo "def" > ${tmps}/dotfiles/def
echo "{{@@ _dotfile_abs_dst @@}}" >> ${tmps}/dotfiles/def
rm -f ${tmpd}/def
echo "def" > "${tmps}"/dotfiles/def
echo "{{@@ _dotfile_abs_dst @@}}" >> "${tmps}"/dotfiles/def
rm -f "${tmpd}"/def
# files listing
echo "file listing"
cd ${ddpath} | ${bin} files -c ${cfg1} -p p1 -G | grep '^f_abc'
cd ${ddpath} | ${bin} files -c ${cfg1} -p p1 -G | grep '^f_def'
cd "${ddpath}" | ${bin} files -c "${cfg1}" -p p1 -G | grep '^f_abc'
cd "${ddpath}" | ${bin} files -c "${cfg1}" -p p1 -G | grep '^f_def'
# install and compare
echo "installing ..."
cd ${ddpath} | ${bin} install -c ${cfg1} -p p1 -V -f
cd "${ddpath}" | ${bin} install -c "${cfg1}" -p p1 -V -f
echo "comparing ..."
cd ${ddpath} | ${bin} compare -c ${cfg1} -p p1 -V
cd "${ddpath}" | ${bin} compare -c "${cfg1}" -p p1 -V
# check exists
[ ! -s ${tmpd}/abc ] && echo "(same) abc not installed" && exit 1
[ ! -s ${tmpd}/def ] && echo "(same) def not installed" && exit 1
[ ! -s "${tmpd}"/abc ] && echo "(same) abc not installed" && exit 1
[ ! -s "${tmpd}"/def ] && echo "(same) def not installed" && exit 1
echo "OK"