mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 15:04:43 +00:00
shellcheck fixes
This commit is contained in:
203
tests-ng/dry.sh
vendored
203
tests-ng/dry.sh
vendored
@@ -27,34 +27,37 @@ 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
|
||||
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)
|
||||
#echo "dotfile destination: ${tmpd}"
|
||||
# workdir
|
||||
tmpw=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
|
||||
tmpw=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
|
||||
export DOTDROP_WORKDIR="${tmpw}"
|
||||
# temp
|
||||
tmpa=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
|
||||
tmpa=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
|
||||
|
||||
clear_on_exit "${tmps}"
|
||||
clear_on_exit "${tmpd}"
|
||||
@@ -65,23 +68,23 @@ clear_on_exit "${tmpa}"
|
||||
# test install
|
||||
# -----------------------------
|
||||
# cleaning
|
||||
rm -rf ${tmps}/*
|
||||
mkdir -p ${tmps}/dotfiles
|
||||
rm -rf ${tmpw}/*
|
||||
rm -rf ${tmpd}/*
|
||||
rm -rf ${tmpa}/*
|
||||
rm -rf "${tmps:?}"/*
|
||||
mkdir -p "${tmps}"/dotfiles
|
||||
rm -rf "${tmpw:?}"/*
|
||||
rm -rf "${tmpd:?}"/*
|
||||
rm -rf "${tmpa:?}"/*
|
||||
# create the config file
|
||||
cfg="${tmps}/config.yaml"
|
||||
|
||||
echo '{{@@ profile @@}}' > ${tmps}/dotfiles/file
|
||||
echo '{{@@ profile @@}}' > ${tmps}/dotfiles/link
|
||||
mkdir -p ${tmps}/dotfiles/dir
|
||||
echo "{{@@ profile @@}}" > ${tmps}/dotfiles/dir/f1
|
||||
mkdir -p ${tmps}/dotfiles/dirchildren
|
||||
echo "{{@@ profile @@}}" > ${tmps}/dotfiles/dirchildren/f1
|
||||
echo "{{@@ profile @@}}" > ${tmps}/dotfiles/dirchildren/f2
|
||||
echo '{{@@ profile @@}}' > "${tmps}"/dotfiles/file
|
||||
echo '{{@@ profile @@}}' > "${tmps}"/dotfiles/link
|
||||
mkdir -p "${tmps}"/dotfiles/dir
|
||||
echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/dir/f1
|
||||
mkdir -p "${tmps}"/dotfiles/dirchildren
|
||||
echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/dirchildren/f1
|
||||
echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/dirchildren/f2
|
||||
|
||||
cat > ${cfg} << _EOF
|
||||
cat > "${cfg}" << _EOF
|
||||
config:
|
||||
backup: true
|
||||
create: true
|
||||
@@ -130,33 +133,33 @@ _EOF
|
||||
|
||||
# install
|
||||
echo "dry install"
|
||||
cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 -V --dry
|
||||
cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 -V --dry
|
||||
|
||||
cnt=`ls -1 ${tmpd} | wc -l`
|
||||
ls -1 ${tmpd}
|
||||
cnt=$(find "${tmpd}" -type f | wc -l)
|
||||
ls -1 "${tmpd}"
|
||||
[ "${cnt}" != "0" ] && echo "dry install failed (1)" && exit 1
|
||||
|
||||
cnt=`ls -1 ${tmpw} | wc -l`
|
||||
ls -1 ${tmpw}
|
||||
cnt=$(find "${tmpw}" -type f | wc -l)
|
||||
ls -1 "${tmpw}"
|
||||
[ "${cnt}" != "0" ] && echo "dry install failed (2)" && exit 1
|
||||
|
||||
cnt=`ls -1 ${tmpa} | wc -l`
|
||||
ls -1 ${tmpa}
|
||||
cnt=$(find "${tmpa}" -type f | wc -l)
|
||||
ls -1 "${tmpa}"
|
||||
[ "${cnt}" != "0" ] && echo "dry install failed (3)" && exit 1
|
||||
|
||||
# -----------------------------
|
||||
# test import
|
||||
# -----------------------------
|
||||
# cleaning
|
||||
rm -rf ${tmps}/*
|
||||
mkdir -p ${tmps}/dotfiles
|
||||
rm -rf ${tmpw}/*
|
||||
rm -rf ${tmpd}/*
|
||||
rm -rf ${tmpa}/*
|
||||
rm -rf "${tmps:?}"/*
|
||||
mkdir -p "${tmps}"/dotfiles
|
||||
rm -rf "${tmpw:?}"/*
|
||||
rm -rf "${tmpd:?}"/*
|
||||
rm -rf "${tmpa:?}"/*
|
||||
|
||||
# create the config file
|
||||
cfg="${tmps}/config.yaml"
|
||||
cat > ${cfg} << _EOF
|
||||
cat > "${cfg}" << _EOF
|
||||
config:
|
||||
backup: true
|
||||
create: true
|
||||
@@ -165,54 +168,52 @@ config:
|
||||
dotfiles:
|
||||
profiles:
|
||||
_EOF
|
||||
cp ${cfg} ${tmpa}/config.yaml
|
||||
cp "${cfg}" "${tmpa}"/config.yaml
|
||||
|
||||
echo 'content' > ${tmpd}/file
|
||||
echo 'content' > ${tmpd}/link
|
||||
mkdir -p ${tmpd}/dir
|
||||
echo "content" > ${tmpd}/dir/f1
|
||||
mkdir -p ${tmpd}/dirchildren
|
||||
echo "content" > ${tmpd}/dirchildren/f1
|
||||
echo "content" > ${tmpd}/dirchildren/f2
|
||||
|
||||
dotfiles="${tmpd}/file ${tmpd}/link ${tmpd}/dir ${tmpd}/dirchildren"
|
||||
echo 'content' > "${tmpd}"/file
|
||||
echo 'content' > "${tmpd}"/link
|
||||
mkdir -p "${tmpd}"/dir
|
||||
echo "content" > "${tmpd}"/dir/f1
|
||||
mkdir -p "${tmpd}"/dirchildren
|
||||
echo "content" > "${tmpd}"/dirchildren/f1
|
||||
echo "content" > "${tmpd}"/dirchildren/f2
|
||||
|
||||
echo "dry import"
|
||||
cd ${ddpath} | ${bin} import -c ${cfg} -f -p p1 -V --dry ${dotfiles}
|
||||
cd "${ddpath}" | ${bin} import -c "${cfg}" -f -p p1 -V --dry "${tmpd}"/file "${tmpd}"/link "${tmpd}"/dir "${tmpd}"/dirchildren
|
||||
|
||||
cnt=`ls -1 ${tmps}/dotfiles | wc -l`
|
||||
ls -1 ${tmps}/dotfiles
|
||||
cnt=$(find "${tmps}"/dotfiles | wc -l)
|
||||
ls -1 "${tmps}"/dotfiles
|
||||
[ "${cnt}" != "0" ] && echo "dry import failed (1)" && exit 1
|
||||
|
||||
diff ${cfg} ${tmpa}/config.yaml || (echo "dry import failed (2)" && exit 1)
|
||||
diff "${cfg}" "${tmpa}"/config.yaml || (echo "dry import failed (2)" && exit 1)
|
||||
|
||||
# -----------------------------
|
||||
# test update
|
||||
# -----------------------------
|
||||
# cleaning
|
||||
rm -rf ${tmps}/*
|
||||
mkdir -p ${tmps}/dotfiles
|
||||
rm -rf ${tmpw}/*
|
||||
rm -rf ${tmpd}/*
|
||||
rm -rf ${tmpa}/*
|
||||
rm -rf "${tmps:?}"/*
|
||||
mkdir -p "${tmps}"/dotfiles
|
||||
rm -rf "${tmpw:?}"/*
|
||||
rm -rf "${tmpd:?}"/*
|
||||
rm -rf "${tmpa:?}"/*
|
||||
|
||||
echo 'original' > ${tmps}/dotfiles/file
|
||||
echo 'original' > ${tmps}/dotfiles/link
|
||||
mkdir -p ${tmps}/dotfiles/dir
|
||||
echo "original" > ${tmps}/dotfiles/dir/f1
|
||||
mkdir -p ${tmps}/dotfiles/dirchildren
|
||||
echo "original" > ${tmps}/dotfiles/dirchildren/f1
|
||||
echo "original" > ${tmps}/dotfiles/dirchildren/f2
|
||||
echo 'original' > "${tmps}"/dotfiles/file
|
||||
echo 'original' > "${tmps}"/dotfiles/link
|
||||
mkdir -p "${tmps}"/dotfiles/dir
|
||||
echo "original" > "${tmps}"/dotfiles/dir/f1
|
||||
mkdir -p "${tmps}"/dotfiles/dirchildren
|
||||
echo "original" > "${tmps}"/dotfiles/dirchildren/f1
|
||||
echo "original" > "${tmps}"/dotfiles/dirchildren/f2
|
||||
|
||||
echo 'modified' > ${tmpd}/file
|
||||
echo 'modified' > ${tmpd}/link
|
||||
mkdir -p ${tmpd}/dir
|
||||
echo "modified" > ${tmpd}/dir/f1
|
||||
mkdir -p ${tmpd}/dirchildren
|
||||
echo "modified" > ${tmpd}/dirchildren/f1
|
||||
echo "modified" > ${tmpd}/dirchildren/f2
|
||||
echo 'modified' > "${tmpd}"/file
|
||||
echo 'modified' > "${tmpd}"/link
|
||||
mkdir -p "${tmpd}"/dir
|
||||
echo "modified" > "${tmpd}"/dir/f1
|
||||
mkdir -p "${tmpd}"/dirchildren
|
||||
echo "modified" > "${tmpd}"/dirchildren/f1
|
||||
echo "modified" > "${tmpd}"/dirchildren/f2
|
||||
|
||||
cat > ${cfg} << _EOF
|
||||
cat > "${cfg}" << _EOF
|
||||
config:
|
||||
backup: true
|
||||
create: true
|
||||
@@ -241,39 +242,38 @@ profiles:
|
||||
- d_dir
|
||||
- d_dirchildren
|
||||
_EOF
|
||||
cp ${cfg} ${tmpa}/config.yaml
|
||||
cp "${cfg}" "${tmpa}"/config.yaml
|
||||
|
||||
echo "dry update"
|
||||
dotfiles="${tmpd}/file ${tmpd}/link ${tmpd}/dir ${tmpd}/dirchildren"
|
||||
cd ${ddpath} | ${bin} update -c ${cfg} -f -p p1 -V --dry ${dotfiles}
|
||||
cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 -V --dry "${tmpd}"/file "${tmpd}"/link "${tmpd}"/dir "${tmpd}"/dirchildren
|
||||
|
||||
grep 'modified' ${tmps}/dotfiles/file && echo "dry update failed (1)" && exit 1
|
||||
grep 'modified' ${tmps}/dotfiles/link && echo "dry update failed (2)" && exit 1
|
||||
grep "modified" ${tmps}/dotfiles/dir/f1 && echo "dry update failed (3)" && exit 1
|
||||
grep "modified" ${tmps}/dotfiles/dirchildren/f1 && echo "dry update failed (4)" && exit 1
|
||||
grep "modified" ${tmps}/dotfiles/dirchildren/f2 && echo "dry update failed (5)" && exit 1
|
||||
grep 'modified' "${tmps}"/dotfiles/file && echo "dry update failed (1)" && exit 1
|
||||
grep 'modified' "${tmps}"/dotfiles/link && echo "dry update failed (2)" && exit 1
|
||||
grep "modified" "${tmps}"/dotfiles/dir/f1 && echo "dry update failed (3)" && exit 1
|
||||
grep "modified" "${tmps}"/dotfiles/dirchildren/f1 && echo "dry update failed (4)" && exit 1
|
||||
grep "modified" "${tmps}"/dotfiles/dirchildren/f2 && echo "dry update failed (5)" && exit 1
|
||||
|
||||
diff ${cfg} ${tmpa}/config.yaml || (echo "dry update failed (6)" && exit 1)
|
||||
diff "${cfg}" "${tmpa}"/config.yaml || (echo "dry update failed (6)" && exit 1)
|
||||
|
||||
# -----------------------------
|
||||
# test remove
|
||||
# -----------------------------
|
||||
# cleaning
|
||||
rm -rf ${tmps}/*
|
||||
mkdir -p ${tmps}/dotfiles
|
||||
rm -rf ${tmpw}/*
|
||||
rm -rf ${tmpd}/*
|
||||
rm -rf ${tmpa}/*
|
||||
rm -rf "${tmps:?}"/*
|
||||
mkdir -p "${tmps}"/dotfiles
|
||||
rm -rf "${tmpw:?}"/*
|
||||
rm -rf "${tmpd:?}"/*
|
||||
rm -rf "${tmpa:?}"/*
|
||||
|
||||
echo '{{@@ profile @@}}' > ${tmps}/dotfiles/file
|
||||
echo '{{@@ profile @@}}' > ${tmps}/dotfiles/link
|
||||
mkdir -p ${tmps}/dotfiles/dir
|
||||
echo "{{@@ profile @@}}" > ${tmps}/dotfiles/dir/f1
|
||||
mkdir -p ${tmps}/dotfiles/dirchildren
|
||||
echo "{{@@ profile @@}}" > ${tmps}/dotfiles/dirchildren/f1
|
||||
echo "{{@@ profile @@}}" > ${tmps}/dotfiles/dirchildren/f2
|
||||
echo '{{@@ profile @@}}' > "${tmps}"/dotfiles/file
|
||||
echo '{{@@ profile @@}}' > "${tmps}"/dotfiles/link
|
||||
mkdir -p "${tmps}"/dotfiles/dir
|
||||
echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/dir/f1
|
||||
mkdir -p "${tmps}"/dotfiles/dirchildren
|
||||
echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/dirchildren/f1
|
||||
echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/dirchildren/f2
|
||||
|
||||
cat > ${cfg} << _EOF
|
||||
cat > "${cfg}" << _EOF
|
||||
config:
|
||||
backup: true
|
||||
create: true
|
||||
@@ -302,21 +302,20 @@ profiles:
|
||||
- d_dir
|
||||
- d_dirchildren
|
||||
_EOF
|
||||
cp ${cfg} ${tmpa}/config.yaml
|
||||
cp "${cfg}" "${tmpa}"/config.yaml
|
||||
|
||||
echo "dry remove"
|
||||
dotfiles="${tmpd}/file ${tmpd}/link ${tmpd}/dir ${tmpd}/dirchildren"
|
||||
cd ${ddpath} | ${bin} remove -c ${cfg} -f -p p1 -V --dry ${dotfiles}
|
||||
cd "${ddpath}" | ${bin} remove -c "${cfg}" -f -p p1 -V --dry "${tmpd}"/file "${tmpd}"/link "${tmpd}"/dir "${tmpd}"/dirchildren
|
||||
|
||||
[ ! -e ${tmps}/dotfiles/file ] && echo "dry remove failed (1)" && exit 1
|
||||
[ ! -e ${tmps}/dotfiles/link ] && echo "dry remove failed (2)" && exit 1
|
||||
[ ! -d ${tmps}/dotfiles/dir ] && echo "dry remove failed (3)" && exit 1
|
||||
[ ! -e ${tmps}/dotfiles/dir/f1 ] && echo "dry remove failed (4)" && exit 1
|
||||
[ ! -d ${tmps}/dotfiles/dirchildren ] && echo "dry remove failed (5)" && exit 1
|
||||
[ ! -e ${tmps}/dotfiles/dirchildren/f1 ] && echo "dry remove failed (6)" && exit 1
|
||||
[ ! -e ${tmps}/dotfiles/dirchildren/f2 ] && echo "dry remove failed (7)" && exit 1
|
||||
[ ! -e "${tmps}"/dotfiles/file ] && echo "dry remove failed (1)" && exit 1
|
||||
[ ! -e "${tmps}"/dotfiles/link ] && echo "dry remove failed (2)" && exit 1
|
||||
[ ! -d "${tmps}"/dotfiles/dir ] && echo "dry remove failed (3)" && exit 1
|
||||
[ ! -e "${tmps}"/dotfiles/dir/f1 ] && echo "dry remove failed (4)" && exit 1
|
||||
[ ! -d "${tmps}"/dotfiles/dirchildren ] && echo "dry remove failed (5)" && exit 1
|
||||
[ ! -e "${tmps}"/dotfiles/dirchildren/f1 ] && echo "dry remove failed (6)" && exit 1
|
||||
[ ! -e "${tmps}"/dotfiles/dirchildren/f2 ] && echo "dry remove failed (7)" && exit 1
|
||||
|
||||
diff ${cfg} ${tmpa}/config.yaml || (echo "dry remove failed (8)" && exit 1)
|
||||
diff "${cfg}" "${tmpa}"/config.yaml || (echo "dry remove failed (8)" && exit 1)
|
||||
|
||||
echo "OK"
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user