From 2f1bbeaceea14a4c6ce8c0eb5538ac1cbb897fa9 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Fri, 27 Jan 2023 16:44:19 +0100 Subject: [PATCH] shellcheck fixes --- completion/generate.sh | 15 +- dotdrop.sh | 4 +- packages/genpkg.sh | 18 +- scripts/dotdrop-version-manager.sh | 1 + test-ng.sh | 8 +- test-syntax.sh | 31 ++- test-unittest.sh | 7 +- tests-ng/actions-args-template.sh | 47 +++-- tests-ng/actions-args.sh | 51 ++--- tests-ng/actions-default.sh | 61 +++--- tests-ng/actions-empty-dir.sh | 143 ++++++------- tests-ng/actions-pre.sh | 83 ++++---- tests-ng/actions-template.sh | 55 ++--- tests-ng/actions.sh | 65 +++--- tests-ng/bad-diff-cmd.sh | 25 ++- tests-ng/chmod-compare.sh | 73 +++---- tests-ng/chmod-import.sh | 143 ++++++------- tests-ng/chmod-install.sh | 132 ++++++------ tests-ng/chmod-more.sh | 44 ++-- tests-ng/chmod-preserve-install.sh | 138 ++++++------- tests-ng/chmod-preserve-update.sh | 85 ++++---- tests-ng/chmod-update.sh | 87 ++++---- tests-ng/clear-workdir.sh | 57 +++--- tests-ng/compare-ignore-missing.sh | 41 ++-- tests-ng/compare-ignore-relative.sh | 85 ++++---- tests-ng/compare-ignore.sh | 103 +++++----- tests-ng/compare-include.sh | 57 +++--- tests-ng/compare-negative-ignore-relative.sh | 94 ++++----- tests-ng/compare-negative-ignore.sh | 77 +++---- tests-ng/compare-profile-check.sh | 63 +++--- tests-ng/compare.sh | 75 +++---- tests-ng/corner-case.sh | 27 +-- tests-ng/deprecated-link.sh | 53 ++--- tests-ng/diff-cmd.sh | 43 ++-- tests-ng/dir-import-update.sh | 27 +-- tests-ng/dotdrop-variables.sh | 35 ++-- tests-ng/dotfile-no-src.sh | 27 +-- tests-ng/dotfile-sub-variables.sh | 51 ++--- tests-ng/dotfile-variables.sh | 41 ++-- tests-ng/dotfiles-all.sh | 41 ++-- tests-ng/dotfiles-dyn-paths.sh | 25 ++- tests-ng/double-config-import.sh | 19 +- tests-ng/dry.sh | 203 +++++++++---------- tests-ng/duplicate-key.sh | 51 ++--- tests-ng/dynactions.sh | 49 ++--- tests-ng/dyndotfilepaths.sh | 29 +-- tests-ng/dynextvariables.sh | 69 ++++--- tests-ng/dyninclude.sh | 35 ++-- tests-ng/dynvariables.sh | 51 ++--- tests-ng/env.sh | 65 +++--- tests-ng/ext-actions.sh | 43 ++-- tests-ng/extvariables.sh | 101 ++++----- tests-ng/filter_file.sh | 59 +++--- tests-ng/force-actions.sh | 59 +++--- tests-ng/func_file.sh | 81 ++++---- tests-ng/global-compare-ignore.sh | 43 ++-- tests-ng/global-compare-negative-ignore.sh | 76 +++---- tests-ng/global-update-ignore.sh | 43 ++-- tests-ng/global-update-negative-ignore.sh | 94 ++++----- tests-ng/globs.sh | 43 ++-- tests-ng/header.sh | 35 ++-- tests-ng/ignore-empty.sh | 41 ++-- tests-ng/import-as.sh | 83 ++++---- tests-ng/import-configs.sh | 117 +++++------ tests-ng/import-configs2.sh | 45 ++-- tests-ng/import-duplicate.sh | 51 ++--- tests-ng/import-ignore.sh | 41 ++-- tests-ng/import-include.sh | 35 ++-- tests-ng/import-link-children.sh | 56 ++--- tests-ng/import-negative-ignore.sh | 86 +++----- tests-ng/import-non-existing.sh | 59 +++--- tests-ng/import-profile-dotfiles.sh | 53 ++--- tests-ng/import-subfile.sh | 33 +-- tests-ng/import-to-no-profile.sh | 63 +++--- tests-ng/import-with-empty.sh | 29 +-- tests-ng/import-with-trans.sh | 105 +++++----- tests-ng/import.sh | 77 +++---- tests-ng/imported-configs-variables.sh | 63 +++--- tests-ng/imported-variables-from-config.sh | 29 +-- tests-ng/include-actions.sh | 121 +++++------ tests-ng/include-order.sh | 51 ++--- tests-ng/include-variables.sh | 35 ++-- tests-ng/include.sh | 51 ++--- tests-ng/inst-link-default.sh | 85 ++++---- tests-ng/install-empty.sh | 17 +- tests-ng/install-ignore.sh | 131 ++++++------ tests-ng/install-link-children.sh | 57 +++--- tests-ng/install-negative-ignore.sh | 78 +++---- tests-ng/install-to-temp.sh | 31 +-- tests-ng/install.sh | 36 ++-- tests-ng/jhelpers.sh | 57 +++--- tests-ng/key-prefix-sep.sh | 59 +++--- tests-ng/link-import-default.sh | 37 ++-- tests-ng/link-templates-dir-home.sh | 37 ++-- tests-ng/link-templates-dir.sh | 37 ++-- tests-ng/link-templates.sh | 31 +-- tests-ng/link-value-tests.sh | 22 +- tests-ng/macro-with-globals.sh | 33 +-- tests-ng/minversion.sh | 45 ++-- tests-ng/negative-ignore-no-match.sh | 73 +++---- tests-ng/notemplate.sh | 167 +++++++-------- tests-ng/profile-actions.sh | 55 ++--- tests-ng/profile-dyninclude.sh | 49 ++--- tests-ng/profile-dynvariables.sh | 67 +++--- tests-ng/profile-import-dotfiles.sh | 43 ++-- tests-ng/profile-undefined-variables.sh | 47 +++-- tests-ng/re-import.sh | 91 +++++---- tests-ng/recinclude.sh | 39 ++-- tests-ng/recvariables.sh | 38 ++-- tests-ng/remove.sh | 87 ++++---- tests-ng/symlink-relative.sh | 109 +++++----- tests-ng/symlink.sh | 83 ++++---- tests-ng/template-dotpath.sh | 33 +-- tests-ng/template-link-value.sh | 69 ++++--- tests-ng/toml.sh | 35 ++-- tests-ng/transformations-template.sh | 71 +++---- tests-ng/transformations-with-args.sh | 61 +++--- tests-ng/transformations.sh | 109 +++++----- tests-ng/update-ignore-missing.sh | 59 +++--- tests-ng/update-ignore-relative.sh | 41 ++-- tests-ng/update-ignore.sh | 39 ++-- tests-ng/update-negative-ignore-relative.sh | 96 ++++----- tests-ng/update-negative-ignore.sh | 94 ++++----- tests-ng/update-profile-check.sh | 77 +++---- tests-ng/update-rights.sh | 49 ++--- tests-ng/update-templates.sh | 47 +++-- tests-ng/update-with-key.sh | 51 ++--- tests-ng/update.sh | 85 ++++---- tests-ng/uservariables.sh | 55 ++--- tests-ng/variables-enrich.sh | 59 +++--- tests-ng/variables-include.sh | 47 +++-- tests-ng/variables.sh | 43 ++-- tests-ng/workdir-compare.sh | 69 ++++--- tests-ng/workdir.sh | 83 ++++---- tests.sh | 10 +- 135 files changed, 4083 insertions(+), 3950 deletions(-) diff --git a/completion/generate.sh b/completion/generate.sh index 5c1a984..d538643 100755 --- a/completion/generate.sh +++ b/completion/generate.sh @@ -34,11 +34,11 @@ dt_zsh="${compl}/_dotdrop-completion.zsh" dt_bash="${compl}/dotdrop-completion.bash" # generate for dotdrop.sh -cd ${cur}/.. +cd "${cur}"/.. docopt-completion ./dotdrop.sh --manual-zsh -mv ./_dotdrop.sh ${dtsh_zsh} +mv ./_dotdrop.sh "${dtsh_zsh}" docopt-completion ./dotdrop.sh --manual-bash -mv ./dotdrop.sh.sh ${dtsh_bash} +mv ./dotdrop.sh.sh "${dtsh_bash}" # generate for dotdrop vbin="virtualenv" @@ -46,18 +46,19 @@ if ! hash ${vbin}; then echo "\"${vbin}\" not found!" exit 1 fi -cd ${cur}/.. +cd "${cur}"/.. venv="/tmp/dotdrop-venv" ${vbin} -p python3 ${venv} +# shellcheck source=/dev/null source ${venv}/bin/activate python setup.py install cd /tmp docopt-completion dotdrop --manual-zsh -mv ./_dotdrop ${dt_zsh} +mv ./_dotdrop "${dt_zsh}" docopt-completion dotdrop --manual-bash -mv ./dotdrop.sh ${dt_bash} +mv ./dotdrop.sh "${dt_bash}" deactivate rm -rf ${venv} # pivot back -cd ${opwd} +cd "${opwd}" diff --git a/dotdrop.sh b/dotdrop.sh index 70eb9ba..9dc2a33 100755 --- a/dotdrop.sh +++ b/dotdrop.sh @@ -18,8 +18,6 @@ fi args=("$@") cur=$(dirname "$(${rl} "${0}")") opwd=$(pwd) -cfg="${cur}/config.yaml" -sub="dotdrop" # pivot cd "${cur}" || { echo "Directory \"${cur}\" doesn't exist, aborting." && exit 1; } @@ -33,7 +31,7 @@ fi # check python executable pybin="python3" hash ${pybin} 2>/dev/null || pybin="python" -[[ "`${pybin} -V 2>&1`" =~ "Python 3" ]] || { echo "install Python 3" && exit 1; } +[[ "$(${pybin} -V 2>&1)" =~ "Python 3" ]] || { echo "install Python 3" && exit 1; } # launch dotdrop PYTHONPATH=dotdrop:${PYTHONPATH} ${pybin} -m dotdrop.dotdrop "${args[@]}" diff --git a/packages/genpkg.sh b/packages/genpkg.sh index 080f0f3..b94dc8c 100755 --- a/packages/genpkg.sh +++ b/packages/genpkg.sh @@ -8,7 +8,7 @@ up() { # update pkgver - [ "${1}" != "" ] && sed -i "s/^pkgver=.*$/pkgver=${1}/g" ${pkgfile} + [ "${1}" != "" ] && sed -i "s/^pkgver=.*$/pkgver=${1}/g" "${pkgfile}" # create srcinfo rm -f .SRCINFO makepkg --printsrcinfo > .SRCINFO @@ -24,10 +24,10 @@ if ! ${rl} "${0}" >/dev/null 2>&1; then fi fi # cur -cur=`dirname $(${rl} "${0}")` -opwd=`pwd` +cur=$(dirname "$(${rl} "${0}")") +opwd=$(pwd) pkgfile="PKGBUILD" -cd ${cur} +cd "${cur}" || exit 1 ######################## # update arch package @@ -35,10 +35,10 @@ cd ${cur} ######################## dir="arch-dotdrop" echo "doing ${dir} ..." -cd ${dir} -version="`git describe --abbrev=0 --tags | sed 's/^v//g'`" -up ${version} -cd ${OLDPWD} +cd ${dir} || exit 1 +version="$(git describe --abbrev=0 --tags | sed 's/^v//g')" +up "${version}" +cd "${OLDPWD}" || exit 1 ######################### ## update arch package @@ -53,4 +53,4 @@ cd ${OLDPWD} #cd ${OLDPWD} # pivot back -cd ${opwd} +cd "${opwd}" || exit diff --git a/scripts/dotdrop-version-manager.sh b/scripts/dotdrop-version-manager.sh index d647821..9ee4819 100755 --- a/scripts/dotdrop-version-manager.sh +++ b/scripts/dotdrop-version-manager.sh @@ -104,6 +104,7 @@ need_update_stable() last=$(get_latest) cur=$(get_current_tag) # get short tag if on a lightweight tag + # shellcheck disable=SC2001 tag=$(echo "$cur" | sed 's/\(v.*\)-[0-9]*.-.*$/\1/g') if [ "${tag}" != "${last}" ]; then echo "new stable version available: ${last}" && exit 1 diff --git a/test-ng.sh b/test-ng.sh index f004a7c..3905d4e 100755 --- a/test-ng.sh +++ b/test-ng.sh @@ -13,13 +13,13 @@ if ! ${rl} "${0}" >/dev/null 2>&1; then echo "\"${rl}\" not found!" && exit 1 fi fi -cur=`dirname $(${rl} "${0}")` +cur=$(dirname "$(${rl} "${0}")") tmpworkdir="/tmp/dotdrop-tests-workdir" export DOTDROP_WORKDIR="${tmpworkdir}" workers=${DOTDROP_WORKERS} -if [ ! -z ${workers} ]; then +if [ -n "${workers}" ]; then DOTDROP_WORKERS=${workers} echo "ENABLE workers: ${workers}" fi @@ -28,8 +28,8 @@ fi export DOTDROP_DEBUG="yes" unset DOTDROP_FORCE_NODEBUG workdir_tmp_exists="no" -[ -d "~/.config/dotdrop/tmp" ] && workdir_tmp_exists="yes" -if [ -z ${GITHUB_WORKFLOW} ]; then +[ -d "${HOME}/.config/dotdrop/tmp" ] && workdir_tmp_exists="yes" +if [ -z "${GITHUB_WORKFLOW}" ]; then ## local export COVERAGE_FILE= tests-ng/tests-launcher.py diff --git a/test-syntax.sh b/test-syntax.sh index 1e99e0b..f3ef22d 100755 --- a/test-syntax.sh +++ b/test-syntax.sh @@ -6,7 +6,27 @@ #set -ev set -e -# versions +# test shell scripts +if ! which shellcheck >/dev/null 2>&1; then + echo "Install shellcheck" + exit 1 +fi +echo "shellcheck version:" +shellcheck --version +# SC2002: Useless cat +# SC2126: Consider using grep -c instead of grep|wc -l +# SC2129: Consider using { cmd1; cmd2; } >> file instead of individual redirects +# SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $? +find . -iname '*.sh' | while read -r script; do + shellcheck -x \ + -e SC2002 \ + -e SC2126 \ + -e SC2129 \ + -e SC2181 \ + "${script}" +done + +# python tools versions echo "pylint version:" pylint --version echo "pycodestyle version:" @@ -16,7 +36,10 @@ pyflakes --version # PEP8 tests which pycodestyle >/dev/null 2>&1 -[ "$?" != "0" ] && echo "Install pycodestyle" && exit 1 +if ! which pycodestyle >/dev/null 2>&1; then + echo "Install pycodestyle" + exit 1 +fi echo "testing with pycodestyle" # W503: Line break occurred before a binary operator # W504: Line break occurred after a binary operator @@ -68,8 +91,8 @@ pylint \ set +e exceptions="save_uservariables_name\|@@\|diff_cmd\|original,\|modified," # f-string errors and missing f literal -find dotdrop/ -iname '*.py' -exec grep --with-filename -n -v "f'" {} \; | grep -v "{'" | grep -v "${exceptions}" | grep "'.*}" && echo "bad string format (1): ${errs}" && exit 1 -find dotdrop/ -iname '*.py' -exec grep --with-filename -n -v 'f"' {} \; | grep -v "f'" | grep -v '{"' | grep -v "${exceptions}" | grep '".*}' && echo "bad string format (2): ${errs}" && exit 1 +find dotdrop/ -iname '*.py' -exec grep --with-filename -n -v "f'" {} \; | grep -v "{'" | grep -v "${exceptions}" | grep "'.*}" && echo "bad string format (1)" && exit 1 +find dotdrop/ -iname '*.py' -exec grep --with-filename -n -v 'f"' {} \; | grep -v "f'" | grep -v '{"' | grep -v "${exceptions}" | grep '".*}' && echo "bad string format (2)" && exit 1 set -e echo "syntax OK" \ No newline at end of file diff --git a/test-unittest.sh b/test-unittest.sh index bf37316..f942420 100755 --- a/test-unittest.sh +++ b/test-unittest.sh @@ -13,16 +13,15 @@ if ! ${rl} "${0}" >/dev/null 2>&1; then echo "\"${rl}\" not found!" && exit 1 fi fi -cur=`dirname $(${rl} "${0}")` +cur=$(dirname "$(${rl} "${0}")") -workers=${DOTDROP_WORKERS} -if [ ! -z ${workers} ]; then +if [ -n "${DOTDROP_WORKERS}" ]; then unset DOTDROP_WORKERS echo "DISABLE workers" fi # execute tests with coverage -if [ -z ${GITHUB_WORKFLOW} ]; then +if [ -z "${GITHUB_WORKFLOW}" ]; then ## local export COVERAGE_FILE= # do not print debugs when running tests (faster) diff --git a/tests-ng/actions-args-template.sh b/tests-ng/actions-args-template.sh index bec2560..0e9a003 100755 --- a/tests-ng/actions-args-template.sh +++ b/tests-ng/actions-args-template.sh @@ -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 @@ -61,12 +64,12 @@ should_grep() { } # 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}" @@ -75,7 +78,7 @@ clear_on_exit "${tmpa}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF actions: pre: preaction: "echo {0} > {1}" @@ -123,23 +126,23 @@ _EOF #cat ${cfg} # create the dotfile -echo 'test' > ${tmps}/dotfiles/abc +echo 'test' > "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V # checks action -[ ! -e ${tmpa}/pre ] && echo 'pre action not executed' && exit 1 -[ ! -e ${tmpa}/post ] && echo 'post action not executed' && exit 1 -[ ! -e ${tmpa}/naked ] && echo 'naked action not executed' && exit 1 -[ ! -e ${tmpa}/profile ] && echo 'profile action not executed' && exit 1 -[ ! -e ${tmpa}/dyn ] && echo 'dynamic acton action not executed' && exit 1 -should_grep pre_var ${tmpa}/pre -should_grep post_var ${tmpa}/post -should_grep naked_var ${tmpa}/naked -should_grep profile_var ${tmpa}/profile -should_grep profile_var_2 ${tmpa}/profile -should_grep "$USER" ${tmpa}/dyn +[ ! -e "${tmpa}"/pre ] && echo 'pre action not executed' && exit 1 +[ ! -e "${tmpa}"/post ] && echo 'post action not executed' && exit 1 +[ ! -e "${tmpa}"/naked ] && echo 'naked action not executed' && exit 1 +[ ! -e "${tmpa}"/profile ] && echo 'profile action not executed' && exit 1 +[ ! -e "${tmpa}"/dyn ] && echo 'dynamic acton action not executed' && exit 1 +should_grep pre_var "${tmpa}"/pre +should_grep post_var "${tmpa}"/post +should_grep naked_var "${tmpa}"/naked +should_grep profile_var "${tmpa}"/profile +should_grep profile_var_2 "${tmpa}"/profile +should_grep "$USER" "${tmpa}"/dyn echo "OK" exit 0 diff --git a/tests-ng/actions-args.sh b/tests-ng/actions-args.sh index 028586f..55b12a4 100755 --- a/tests-ng/actions-args.sh +++ b/tests-ng/actions-args.sh @@ -28,31 +28,34 @@ 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 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 "${tmpa}" clear_on_exit "${tmps}" @@ -61,7 +64,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF actions: pre: preaction: echo '{0} {1}' > ${tmpa}/pre @@ -92,29 +95,29 @@ _EOF #cat ${cfg} # create the dotfile -echo "test" > ${tmps}/dotfiles/abc +echo "test" > "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 --verbose +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 --verbose # checks -[ ! -e ${tmpa}/pre ] && echo "pre arg action not found" && exit 1 -grep test1 ${tmpa}/pre >/dev/null -grep test2 ${tmpa}/pre >/dev/null +[ ! -e "${tmpa}"/pre ] && echo "pre arg action not found" && exit 1 +grep test1 "${tmpa}"/pre >/dev/null +grep test2 "${tmpa}"/pre >/dev/null -[ ! -e ${tmpa}/post ] && echo "post arg action not found" && exit 1 -grep test3 ${tmpa}/post >/dev/null -grep test4 ${tmpa}/post >/dev/null -grep test5 ${tmpa}/post >/dev/null +[ ! -e "${tmpa}"/post ] && echo "post arg action not found" && exit 1 +grep test3 "${tmpa}"/post >/dev/null +grep test4 "${tmpa}"/post >/dev/null +grep test5 "${tmpa}"/post >/dev/null -[ ! -e ${tmpa}/naked ] && echo "naked arg action not found" && exit 1 -grep "test6 something" ${tmpa}/naked >/dev/null +[ ! -e "${tmpa}"/naked ] && echo "naked arg action not found" && exit 1 +grep "test6 something" "${tmpa}"/naked >/dev/null -[ ! -e ${tmpa}/empty ] && echo "empty arg action not found" && exit 1 -grep empty ${tmpa}/empty >/dev/null +[ ! -e "${tmpa}"/empty ] && echo "empty arg action not found" && exit 1 +grep empty "${tmpa}"/empty >/dev/null -[ ! -e ${tmpa}/tgt ] && echo "tgt arg action not found" && exit 1 -grep tgt ${tmpa}/tgt >/dev/null +[ ! -e "${tmpa}"/tgt ] && echo "tgt arg action not found" && exit 1 +grep tgt "${tmpa}"/tgt >/dev/null echo "OK" exit 0 diff --git a/tests-ng/actions-default.sh b/tests-ng/actions-default.sh index 7aed2ad..4e761d7 100755 --- a/tests-ng/actions-default.sh +++ b/tests-ng/actions-default.sh @@ -28,31 +28,34 @@ 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 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}" @@ -61,7 +64,7 @@ clear_on_exit "${tmpa}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF actions: pre: failpre: "false" @@ -99,37 +102,37 @@ _EOF #cat ${cfg} # create the dotfile -echo 'test' > ${tmps}/dotfiles/abc +echo 'test' > "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V # checks pre action -[ ! -e ${tmpa}/pre ] && echo 'pre action not executed' && exit 1 -[ ! -e ${tmpa}/preinside ] && echo 'pre action not executed' && exit 1 -grep pre ${tmpa}/pre >/dev/null -grep preinside ${tmpa}/preinside >/dev/null +[ ! -e "${tmpa}"/pre ] && echo 'pre action not executed' && exit 1 +[ ! -e "${tmpa}"/preinside ] && echo 'pre action not executed' && exit 1 +grep pre "${tmpa}"/pre >/dev/null +grep preinside "${tmpa}"/preinside >/dev/null # checks post action -[ ! -e ${tmpa}/post ] && echo 'post action not executed' && exit 1 -[ ! -e ${tmpa}/postinside ] && echo 'post action not executed' && exit 1 -grep post ${tmpa}/post >/dev/null -grep postinside ${tmpa}/postinside >/dev/null +[ ! -e "${tmpa}"/post ] && echo 'post action not executed' && exit 1 +[ ! -e "${tmpa}"/postinside ] && echo 'post action not executed' && exit 1 +grep post "${tmpa}"/post >/dev/null +grep postinside "${tmpa}"/postinside >/dev/null # checks naked action -[ ! -e ${tmpa}/naked ] && echo 'naked action not executed' && exit 1 -[ ! -e ${tmpa}/nakedinside ] && echo 'naked action not executed' && exit 1 -grep naked ${tmpa}/naked >/dev/null -grep nakedinside ${tmpa}/nakedinside >/dev/null +[ ! -e "${tmpa}"/naked ] && echo 'naked action not executed' && exit 1 +[ ! -e "${tmpa}"/nakedinside ] && echo 'naked action not executed' && exit 1 +grep naked "${tmpa}"/naked >/dev/null +grep nakedinside "${tmpa}"/nakedinside >/dev/null # test default action run -cd ${ddpath} | ${bin} install -fa -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -fa -c "${cfg}" -p p1 -V -cnt=`cat ${tmpa}/append | wc -l` +cnt=$(cat "${tmpa}"/append | wc -l) [ "${cnt}" != "2" ] && echo "default_actions not run on -a" && exit 1 # clear -rm -f ${tmpa}/naked* ${tmpa}/pre* ${tmpa}/post* ${tmpd}/abc +rm -f "${tmpa}"/naked* "${tmpa}"/pre* "${tmpa}"/post* "${tmpd}"/abc -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF actions: pre: failpre: "false" @@ -152,9 +155,9 @@ _EOF # ensure failing actions make the installation fail # install set +e -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V set -e -[ -e ${tmpd}/abc ] && exit 1 +[ -e "${tmpd}"/abc ] && exit 1 echo "OK" exit 0 diff --git a/tests-ng/actions-empty-dir.sh b/tests-ng/actions-empty-dir.sh index b19d3a6..3c89cd0 100755 --- a/tests-ng/actions-empty-dir.sh +++ b/tests-ng/actions-empty-dir.sh @@ -28,31 +28,34 @@ 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 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}" @@ -61,7 +64,7 @@ clear_on_exit "${tmpa}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF actions: clearemptydir: find -L '{0}' -empty -xtype d -delete config: @@ -105,87 +108,87 @@ _EOF #cat ${cfg} # create the dotfile -mkdir ${tmps}/dotfiles/dir1 -mkdir ${tmps}/dotfiles/dir1/empty -echo "to-ignore" > ${tmps}/dotfiles/dir1/empty/this.ignore -mkdir ${tmps}/dotfiles/dir1/not-empty -echo "file" > ${tmps}/dotfiles/dir1/not-empty/file -mkdir ${tmps}/dotfiles/dir1/sub -mkdir ${tmps}/dotfiles/dir1/sub/empty -echo "to-ignore-too" > ${tmps}/dotfiles/dir1/sub/empty/that.ignore +mkdir "${tmps}"/dotfiles/dir1 +mkdir "${tmps}"/dotfiles/dir1/empty +echo "to-ignore" > "${tmps}"/dotfiles/dir1/empty/this.ignore +mkdir "${tmps}"/dotfiles/dir1/not-empty +echo "file" > "${tmps}"/dotfiles/dir1/not-empty/file +mkdir "${tmps}"/dotfiles/dir1/sub +mkdir "${tmps}"/dotfiles/dir1/sub/empty +echo "to-ignore-too" > "${tmps}"/dotfiles/dir1/sub/empty/that.ignore # create the dotfile -mkdir ${tmps}/dotfiles/dir2 -mkdir ${tmps}/dotfiles/dir2/empty -echo "{{@@ profile @@}}" > ${tmps}/dotfiles/dir2/empty/this.ignore -mkdir ${tmps}/dotfiles/dir2/not-empty -echo "{{@@ profile @@}}" > ${tmps}/dotfiles/dir2/not-empty/file -mkdir ${tmps}/dotfiles/dir2/sub -mkdir ${tmps}/dotfiles/dir2/sub/empty -echo "{{@@ profile @@}}" > ${tmps}/dotfiles/dir2/sub/empty/that.ignore +mkdir "${tmps}"/dotfiles/dir2 +mkdir "${tmps}"/dotfiles/dir2/empty +echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/dir2/empty/this.ignore +mkdir "${tmps}"/dotfiles/dir2/not-empty +echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/dir2/not-empty/file +mkdir "${tmps}"/dotfiles/dir2/sub +mkdir "${tmps}"/dotfiles/dir2/sub/empty +echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/dir2/sub/empty/that.ignore # create the dotfile -mkdir ${tmps}/dotfiles/dir3 -mkdir ${tmps}/dotfiles/dir3/empty -echo "{{@@ profile @@}}" > ${tmps}/dotfiles/dir3/empty/this.ignore -mkdir ${tmps}/dotfiles/dir3/not-empty -echo "{{@@ profile @@}}" > ${tmps}/dotfiles/dir3/not-empty/file -mkdir ${tmps}/dotfiles/dir3/sub -mkdir ${tmps}/dotfiles/dir3/sub/empty -echo "{{@@ profile @@}}" > ${tmps}/dotfiles/dir3/sub/empty/that.ignore +mkdir "${tmps}"/dotfiles/dir3 +mkdir "${tmps}"/dotfiles/dir3/empty +echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/dir3/empty/this.ignore +mkdir "${tmps}"/dotfiles/dir3/not-empty +echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/dir3/not-empty/file +mkdir "${tmps}"/dotfiles/dir3/sub +mkdir "${tmps}"/dotfiles/dir3/sub/empty +echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/dir3/sub/empty/that.ignore # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V # checks normal -[ ! -d ${tmpd}/dir1 ] && exit 1 -[ -d ${tmpd}/dir1/empty ] && exit 1 -[ -e ${tmpd}/dir1/empty/this.ignore ] && exit 1 -[ ! -d ${tmpd}/dir1/not-empty ] && exit 1 -[ ! -e ${tmpd}/dir1/not-empty/file ] && exit 1 -[ -d ${tmpd}/dir1/sub ] && exit 1 -[ -d ${tmpd}/dir1/sub/empty ] && exit 1 -[ -e ${tmpd}/dir1/sub/empty/that.ignore ] && exit 1 -grep "file" ${tmpd}/dir1/not-empty/file +[ ! -d "${tmpd}"/dir1 ] && exit 1 +[ -d "${tmpd}"/dir1/empty ] && exit 1 +[ -e "${tmpd}"/dir1/empty/this.ignore ] && exit 1 +[ ! -d "${tmpd}"/dir1/not-empty ] && exit 1 +[ ! -e "${tmpd}"/dir1/not-empty/file ] && exit 1 +[ -d "${tmpd}"/dir1/sub ] && exit 1 +[ -d "${tmpd}"/dir1/sub/empty ] && exit 1 +[ -e "${tmpd}"/dir1/sub/empty/that.ignore ] && exit 1 +grep "file" "${tmpd}"/dir1/not-empty/file # checks link_children -[ ! -d ${tmpd}/dir2 ] && exit 1 -[ ! -h ${tmpd}/dir2/empty ] && exit 1 -[ -e ${tmpd}/dir2/empty/this.ignore ] && exit 1 -[ ! -d ${tmpd}/dir2/not-empty ] && exit 1 -[ ! -h ${tmpd}/dir2/not-empty ] && exit 1 -[ ! -e ${tmpd}/dir2/not-empty/file ] && exit 1 -[ -d ${tmpd}/dir2/sub ] && exit 1 -[ -d ${tmpd}/dir2/sub/empty ] && exit 1 -[ -e ${tmpd}/dir2/sub/empty/that.ignore ] && exit 1 -grep "p1" ${tmpd}/dir2/not-empty/file +[ ! -d "${tmpd}"/dir2 ] && exit 1 +[ ! -h "${tmpd}"/dir2/empty ] && exit 1 +[ -e "${tmpd}"/dir2/empty/this.ignore ] && exit 1 +[ ! -d "${tmpd}"/dir2/not-empty ] && exit 1 +[ ! -h "${tmpd}"/dir2/not-empty ] && exit 1 +[ ! -e "${tmpd}"/dir2/not-empty/file ] && exit 1 +[ -d "${tmpd}"/dir2/sub ] && exit 1 +[ -d "${tmpd}"/dir2/sub/empty ] && exit 1 +[ -e "${tmpd}"/dir2/sub/empty/that.ignore ] && exit 1 +grep "p1" "${tmpd}"/dir2/not-empty/file # checks link -[ ! -d ${tmpd}/dir3 ] && exit 1 -[ ! -h ${tmpd}/dir3 ] && exit 1 -[ -d ${tmpd}/dir3/empty ] && exit 1 -[ -e ${tmpd}/dir3/empty/this.ignore ] && exit 1 -[ ! -d ${tmpd}/dir3/not-empty ] && exit 1 -[ ! -e ${tmpd}/dir3/not-empty/file ] && exit 1 -[ -d ${tmpd}/dir3/sub ] && exit 1 -[ -d ${tmpd}/dir3/sub/empty ] && exit 1 -[ -e ${tmpd}/dir3/sub/empty/that.ignore ] && exit 1 -grep "p1" ${tmpd}/dir3/not-empty/file +[ ! -d "${tmpd}"/dir3 ] && exit 1 +[ ! -h "${tmpd}"/dir3 ] && exit 1 +[ -d "${tmpd}"/dir3/empty ] && exit 1 +[ -e "${tmpd}"/dir3/empty/this.ignore ] && exit 1 +[ ! -d "${tmpd}"/dir3/not-empty ] && exit 1 +[ ! -e "${tmpd}"/dir3/not-empty/file ] && exit 1 +[ -d "${tmpd}"/dir3/sub ] && exit 1 +[ -d "${tmpd}"/dir3/sub/empty ] && exit 1 +[ -e "${tmpd}"/dir3/sub/empty/that.ignore ] && exit 1 +grep "p1" "${tmpd}"/dir3/not-empty/file # second install won't trigger the action -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V # 2>&1 | tee ${tmpa}/log +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V # 2>&1 | tee ${tmpa}/log # check normal -[ -d ${tmpd}/dir1/empty ] && echo "empty directory not cleaned" && exit 1 -[ -d ${tmpd}/dir1/sub/empty ] && echo "empty directory not cleaned" && exit 1 +[ -d "${tmpd}"/dir1/empty ] && echo "empty directory not cleaned" && exit 1 +[ -d "${tmpd}"/dir1/sub/empty ] && echo "empty directory not cleaned" && exit 1 # check link_children -[ -d ${tmpd}/dir2/empty ] && echo "empty directory not cleaned" && exit 1 -[ -d ${tmpd}/dir2/sub/empty ] && echo "empty directory not cleaned" && exit 1 +[ -d "${tmpd}"/dir2/empty ] && echo "empty directory not cleaned" && exit 1 +[ -d "${tmpd}"/dir2/sub/empty ] && echo "empty directory not cleaned" && exit 1 # check link -[ -d ${tmpd}/dir3/empty ] && echo "empty directory not cleaned" && exit 1 -[ -d ${tmpd}/dir3/sub/empty ] && echo "empty directory not cleaned" && exit 1 +[ -d "${tmpd}"/dir3/empty ] && echo "empty directory not cleaned" && exit 1 +[ -d "${tmpd}"/dir3/sub/empty ] && echo "empty directory not cleaned" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/actions-pre.sh b/tests-ng/actions-pre.sh index ffbbdc4..65dd112 100755 --- a/tests-ng/actions-pre.sh +++ b/tests-ng/actions-pre.sh @@ -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 diff --git a/tests-ng/actions-template.sh b/tests-ng/actions-template.sh index ee27c5a..ddc0bd2 100755 --- a/tests-ng/actions-template.sh +++ b/tests-ng/actions-template.sh @@ -28,31 +28,34 @@ 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 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}" @@ -61,7 +64,7 @@ clear_on_exit "${tmpa}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF actions: pre: preaction: "echo {{@@ _dotfile_abs_src @@}} > {0}" @@ -88,23 +91,23 @@ _EOF #cat ${cfg} # create the dotfile -echo 'test' > ${tmps}/dotfiles/abc +echo 'test' > "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V # checks action -[ ! -e ${tmpa}/pre ] && echo 'pre action not executed' && exit 1 -[ ! -e ${tmpa}/post ] && echo 'post action not executed' && exit 1 -[ ! -e ${tmpa}/naked ] && echo 'naked action not executed' && exit 1 -grep abc ${tmpa}/pre >/dev/null -grep abc ${tmpa}/post >/dev/null -grep abc ${tmpa}/naked >/dev/null +[ ! -e "${tmpa}"/pre ] && echo 'pre action not executed' && exit 1 +[ ! -e "${tmpa}"/post ] && echo 'post action not executed' && exit 1 +[ ! -e "${tmpa}"/naked ] && echo 'naked action not executed' && exit 1 +grep abc "${tmpa}"/pre >/dev/null +grep abc "${tmpa}"/post >/dev/null +grep abc "${tmpa}"/naked >/dev/null # clear -rm -f ${tmpa}/naked* ${tmpa}/pre* ${tmpa}/post* ${tmpd}/abc +rm -f "${tmpa}"/naked* "${tmpa}"/pre* "${tmpa}"/post* "${tmpd}"/abc -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF actions: pre: preaction: "echo {{@@ _dotfile_abs_dst @@}} > ${tmpa}/pre" @@ -130,15 +133,15 @@ profiles: _EOF # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V # checks action -[ ! -e ${tmpa}/pre ] && echo 'pre action not executed' && exit 1 -[ ! -e ${tmpa}/post ] && echo 'post action not executed' && exit 1 -[ ! -e ${tmpa}/naked ] && echo 'naked action not executed' && exit 1 -grep "${tmpd}/abc" ${tmpa}/pre >/dev/null -grep "${tmpd}/abc" ${tmpa}/post >/dev/null -grep "${tmpd}/abc" ${tmpa}/naked >/dev/null +[ ! -e "${tmpa}"/pre ] && echo 'pre action not executed' && exit 1 +[ ! -e "${tmpa}"/post ] && echo 'post action not executed' && exit 1 +[ ! -e "${tmpa}"/naked ] && echo 'naked action not executed' && exit 1 +grep "${tmpd}/abc" "${tmpa}"/pre >/dev/null +grep "${tmpd}/abc" "${tmpa}"/post >/dev/null +grep "${tmpd}/abc" "${tmpa}"/naked >/dev/null echo "OK" exit 0 diff --git a/tests-ng/actions.sh b/tests-ng/actions.sh index 5f3abf2..1a84022 100755 --- a/tests-ng/actions.sh +++ b/tests-ng/actions.sh @@ -28,31 +28,34 @@ 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 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}" @@ -61,7 +64,7 @@ clear_on_exit "${tmpa}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF actions: pre: preaction: echo 'pre' > ${tmpa}/pre @@ -105,34 +108,34 @@ _EOF #cat ${cfg} # create the dotfile -echo "test" > ${tmps}/dotfiles/abc +echo "test" > "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V 2>&1 | tee ${tmpa}/log +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V 2>&1 | tee "${tmpa}"/log # checks -[ ! -e ${tmpa}/pre ] && exit 1 -grep pre ${tmpa}/pre >/dev/null -[ ! -e ${tmpa}/post ] && exit 1 -grep post ${tmpa}/post >/dev/null -[ ! -e ${tmpa}/naked ] && exit 1 -grep naked ${tmpa}/naked >/dev/null -[ ! -e ${tmpa}/pre2 ] && exit 1 -grep pre2 ${tmpa}/pre2 >/dev/null -[ ! -e ${tmpa}/post2 ] && exit 1 -grep post ${tmpa}/post2 >/dev/null -[ ! -e ${tmpa}/log ] && exit 1 -grep "executing \"echo 'naked' > ${tmpa}/naked" ${tmpa}/log >/dev/null -grep "executing \"echo 'silent'" ${tmpa}/log >/dev/null && false -grep "executing silent action \"_silentaction\"" ${tmpa}/log >/dev/null -[ ! -e ${tmpa}/expandvariable ] && exit 1 -grep xxx ${tmpa}/expandvariable >/dev/null +[ ! -e "${tmpa}"/pre ] && exit 1 +grep pre "${tmpa}"/pre >/dev/null +[ ! -e "${tmpa}"/post ] && exit 1 +grep post "${tmpa}"/post >/dev/null +[ ! -e "${tmpa}"/naked ] && exit 1 +grep naked "${tmpa}"/naked >/dev/null +[ ! -e "${tmpa}"/pre2 ] && exit 1 +grep pre2 "${tmpa}"/pre2 >/dev/null +[ ! -e "${tmpa}"/post2 ] && exit 1 +grep post "${tmpa}"/post2 >/dev/null +[ ! -e "${tmpa}"/log ] && exit 1 +grep "executing \"echo 'naked' > ${tmpa}/naked" "${tmpa}"/log >/dev/null +grep "executing \"echo 'silent'" "${tmpa}"/log >/dev/null && false +grep "executing silent action \"_silentaction\"" "${tmpa}"/log >/dev/null +[ ! -e "${tmpa}"/expandvariable ] && exit 1 +grep xxx "${tmpa}"/expandvariable >/dev/null # fake action -[ ! -e ${tmpa}/fake ] && echo 'fake post action not executed' && exit 1 -grep fake ${tmpa}/fake >/dev/null -[ ! -e ${tmpa}/fake_pre ] && echo 'fake pre action not executed' && exit 1 -grep 'fake pre' ${tmpa}/fake_pre >/dev/null +[ ! -e "${tmpa}"/fake ] && echo 'fake post action not executed' && exit 1 +grep fake "${tmpa}"/fake >/dev/null +[ ! -e "${tmpa}"/fake_pre ] && echo 'fake pre action not executed' && exit 1 +grep 'fake pre' "${tmpa}"/fake_pre >/dev/null echo "OK" exit 0 diff --git a/tests-ng/bad-diff-cmd.sh b/tests-ng/bad-diff-cmd.sh index 0422f1d..9a268f7 100755 --- a/tests-ng/bad-diff-cmd.sh +++ b/tests-ng/bad-diff-cmd.sh @@ -28,31 +28,34 @@ 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 ################################################################ -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "[+] dotdrop dir: ${basedir}" clear_on_exit "${basedir}" # create the config file cfg="${basedir}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -63,13 +66,13 @@ profiles: _EOF set +e -cd ${ddpath} | ${bin} compare -c ${cfg} +cd "${ddpath}" | ${bin} compare -c "${cfg}" [ "$?" = "0" ] && exit 1 -out=$(cd ${ddpath} | ${bin} compare -c ${cfg}) +out=$(cd "${ddpath}" | ${bin} compare -c "${cfg}") echo "${out}" | grep -i 'traceback' && exit 1 -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -80,10 +83,10 @@ profiles: _EOF set +e -cd ${ddpath} | ${bin} compare -c ${cfg} +cd "${ddpath}" | ${bin} compare -c "${cfg}" [ "$?" = "0" ] && exit 1 -out=$(cd ${ddpath} | ${bin} compare -c ${cfg}) +out=$(cd "${ddpath}" | ${bin} compare -c "${cfg}") echo "${out}" | grep -i 'traceback' && exit 1 echo "OK" diff --git a/tests-ng/chmod-compare.sh b/tests-ng/chmod-compare.sh index 6cf2ac3..597c90a 100755 --- a/tests-ng/chmod-compare.sh +++ b/tests-ng/chmod-compare.sh @@ -27,29 +27,32 @@ 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}" clear_on_exit "${tmps}" @@ -57,40 +60,40 @@ clear_on_exit "${tmpd}" # create the dotfile dnormal="${tmpd}/dir_normal" -mkdir -p ${dnormal} -echo "dir_normal/f1" > ${dnormal}/file1 -echo "dir_normal/f2" > ${dnormal}/file2 -chmod 777 ${dnormal} +mkdir -p "${dnormal}" +echo "dir_normal/f1" > "${dnormal}"/file1 +echo "dir_normal/f2" > "${dnormal}"/file2 +chmod 777 "${dnormal}" dlink="${tmpd}/dir_link" -mkdir -p ${dlink} -echo "dir_link/f1" > ${dlink}/file1 -echo "dir_link/f2" > ${dlink}/file2 -chmod 777 ${dlink} +mkdir -p "${dlink}" +echo "dir_link/f1" > "${dlink}"/file1 +echo "dir_link/f2" > "${dlink}"/file2 +chmod 777 "${dlink}" dlinkchildren="${tmpd}/dir_link_children" -mkdir -p ${dlinkchildren} -echo "dir_linkchildren/f1" > ${dlinkchildren}/file1 -echo "dir_linkchildren/f2" > ${dlinkchildren}/file2 -chmod 777 ${dlinkchildren} +mkdir -p "${dlinkchildren}" +echo "dir_linkchildren/f1" > "${dlinkchildren}"/file1 +echo "dir_linkchildren/f2" > "${dlinkchildren}"/file2 +chmod 777 "${dlinkchildren}" fnormal="${tmpd}/filenormal" -echo "filenormal" > ${fnormal} -chmod 777 ${fnormal} +echo "filenormal" > "${fnormal}" +chmod 777 "${fnormal}" flink="${tmpd}/filelink" -echo "filelink" > ${flink} -chmod 777 ${flink} +echo "filelink" > "${flink}" +chmod 777 "${flink}" -echo "f777" > ${tmps}/dotfiles/f777 -chmod 700 ${tmps}/dotfiles/f777 +echo "f777" > "${tmps}"/dotfiles/f777 +chmod 700 "${tmps}"/dotfiles/f777 toimport="${dnormal} ${dlink} ${dlinkchildren} ${fnormal} ${flink}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -108,27 +111,27 @@ _EOF #cat ${cfg} # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 # compare -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 # import for i in ${toimport}; do - cd ${ddpath} | ${bin} import -c ${cfg} -f -p p1 ${i} + cd "${ddpath}" | ${bin} import -c "${cfg}" -f -p p1 "${i}" done #cat ${cfg} # patch rights -chmod 700 ${dnormal} -chmod 700 ${dlink} -chmod 700 ${dlinkchildren} -chmod 700 ${fnormal} -chmod 700 ${flink} +chmod 700 "${dnormal}" +chmod 700 "${dlink}" +chmod 700 "${dlinkchildren}" +chmod 700 "${fnormal}" +chmod 700 "${flink}" set +e -out=`cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 2>&1` +out=$(cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 2>&1) cnt=$(echo "${out}" | grep 'modes differ' | wc -l) set -e [ "${cnt}" != "5" ] && echo "${out}" && echo "compare modes failed (${cnt}, expecting 5)" && exit 1 diff --git a/tests-ng/chmod-import.sh b/tests-ng/chmod-import.sh index 4cd652e..4ec980c 100755 --- a/tests-ng/chmod-import.sh +++ b/tests-ng/chmod-import.sh @@ -29,19 +29,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 @@ -50,21 +53,21 @@ echo -e "$(tput setaf 6)==> RUNNING $(basename $BASH_SOURCE) <==$(tput sgr0)" # $1 file chmod_to_umask() { - u=`umask` - u=`echo ${u} | sed 's/^0*//'` - if [ -d ${1} ]; then + u=$(umask) + u=$(echo "${u}" | sed 's/^0*//') + if [ -d "${1}" ]; then v=$((777 - u)) else v=$((666 - u)) fi - chmod ${v} ${1} + chmod ${v} "${1}" } # 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}" clear_on_exit "${tmps}" @@ -72,37 +75,37 @@ clear_on_exit "${tmpd}" # create the dotfiles dnormal="${tmpd}/dir_normal" -mkdir -p ${dnormal} -echo "dir_normal/f1" > ${dnormal}/file1 -echo "dir_normal/f2" > ${dnormal}/file2 -chmod 777 ${dnormal} +mkdir -p "${dnormal}" +echo "dir_normal/f1" > "${dnormal}"/file1 +echo "dir_normal/f2" > "${dnormal}"/file2 +chmod 777 "${dnormal}" dlink="${tmpd}/dir_link" -mkdir -p ${dlink} -echo "dir_link/f1" > ${dlink}/file1 -echo "dir_link/f2" > ${dlink}/file2 -chmod 777 ${dlink} +mkdir -p "${dlink}" +echo "dir_link/f1" > "${dlink}"/file1 +echo "dir_link/f2" > "${dlink}"/file2 +chmod 777 "${dlink}" dlinkchildren="${tmpd}/dir_link_children" -mkdir -p ${dlinkchildren} -echo "dir_linkchildren/f1" > ${dlinkchildren}/file1 -echo "dir_linkchildren/f2" > ${dlinkchildren}/file2 -chmod 777 ${dlinkchildren} +mkdir -p "${dlinkchildren}" +echo "dir_linkchildren/f1" > "${dlinkchildren}"/file1 +echo "dir_linkchildren/f2" > "${dlinkchildren}"/file2 +chmod 777 "${dlinkchildren}" fnormal="${tmpd}/filenormal" -echo "filenormal" > ${fnormal} -chmod 777 ${fnormal} +echo "filenormal" > "${fnormal}" +chmod 777 "${fnormal}" flink="${tmpd}/filelink" -echo "filelink" > ${flink} -chmod 777 ${flink} +echo "filelink" > "${flink}" +chmod 777 "${flink}" toimport="${dnormal} ${dlink} ${dlinkchildren} ${fnormal} ${flink}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -114,20 +117,20 @@ _EOF # import without --preserve-mode for i in ${toimport}; do - cd ${ddpath} | ${bin} import -c ${cfg} -f -p p1 -V ${i} + cd "${ddpath}" | ${bin} import -c "${cfg}" -f -p p1 -V "${i}" done -cat ${cfg} +cat "${cfg}" # list files -cd ${ddpath} | ${bin} detail -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} detail -c "${cfg}" -p p1 -V -tot=`echo ${toimport} | wc -w` -cnt=`cat ${cfg} | grep "chmod: '777'" | wc -l` +tot=$(echo "${toimport}" | wc -w) +cnt=$(cat "${cfg}" | grep "chmod: '777'" | wc -l) [ "${cnt}" != "${tot}" ] && echo "not all chmod inserted (1)" && exit 1 ## with link -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -137,29 +140,29 @@ profiles: _EOF # clean -rm -rf ${tmps}/dotfiles -mkdir -p ${tmps}/dotfiles +rm -rf "${tmps}"/dotfiles +mkdir -p "${tmps}"/dotfiles # import without --preserve-mode and link for i in ${toimport}; do - cd ${ddpath} | ${bin} import -c ${cfg} -l absolute -f -p p1 -V ${i} + cd "${ddpath}" | ${bin} import -c "${cfg}" -l absolute -f -p p1 -V "${i}" done -cat ${cfg} +cat "${cfg}" # list files -cd ${ddpath} | ${bin} detail -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} detail -c "${cfg}" -p p1 -V -tot=`echo ${toimport} | wc -w` -cnt=`cat ${cfg} | grep "chmod: '777'" | wc -l` +tot=$(echo "${toimport}" | wc -w) +cnt=$(cat "${cfg}" | grep "chmod: '777'" | wc -l) [ "${cnt}" != "${tot}" ] && echo "not all chmod inserted (2)" && exit 1 -tot=`echo ${toimport} | wc -w` -cnt=`cat ${cfg} | grep 'link: absolute' | wc -l` +tot=$(echo "${toimport}" | wc -w) +cnt=$(cat "${cfg}" | grep 'link: absolute' | wc -l) [ "${cnt}" != "${tot}" ] && echo "not all link inserted" && exit 1 ## --preserve-mode -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -169,26 +172,26 @@ profiles: _EOF # clean -rm -rf ${tmps}/dotfiles -mkdir -p ${tmps}/dotfiles +rm -rf "${tmps}"/dotfiles +mkdir -p "${tmps}"/dotfiles # import with --preserve-mode for i in ${toimport}; do - chmod_to_umask ${i} - cd ${ddpath} | ${bin} import -c ${cfg} -m -f -p p1 -V ${i} + chmod_to_umask "${i}" + cd "${ddpath}" | ${bin} import -c "${cfg}" -m -f -p p1 -V "${i}" done -cat ${cfg} +cat "${cfg}" # list files -cd ${ddpath} | ${bin} detail -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} detail -c "${cfg}" -p p1 -V -tot=`echo ${toimport} | wc -w` -cnt=`cat ${cfg} | grep "chmod: " | wc -l` +tot=$(echo "${toimport}" | wc -w) +cnt=$(cat "${cfg}" | grep "chmod: " | wc -l) [ "${cnt}" != "${tot}" ] && echo "not all chmod inserted (3)" && exit 1 ## import normal -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -198,25 +201,25 @@ profiles: _EOF # clean -rm -rf ${tmps}/dotfiles -mkdir -p ${tmps}/dotfiles +rm -rf "${tmps}"/dotfiles +mkdir -p "${tmps}"/dotfiles # import without --preserve-mode for i in ${toimport}; do - chmod_to_umask ${i} - cd ${ddpath} | ${bin} import -c ${cfg} -f -p p1 -V ${i} + chmod_to_umask "${i}" + cd "${ddpath}" | ${bin} import -c "${cfg}" -f -p p1 -V "${i}" done -cat ${cfg} +cat "${cfg}" # list files -cd ${ddpath} | ${bin} detail -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} detail -c "${cfg}" -p p1 -V -cnt=`cat ${cfg} | grep chmod | wc -l` +cnt=$(cat "${cfg}" | grep chmod | wc -l) [ "${cnt}" != "0" ] && echo "chmod inserted but not needed" && exit 1 ## with config option chmod_on_import -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -227,23 +230,23 @@ profiles: _EOF # clean -rm -rf ${tmps}/dotfiles -mkdir -p ${tmps}/dotfiles +rm -rf "${tmps}"/dotfiles +mkdir -p "${tmps}"/dotfiles # import for i in ${toimport}; do - chmod_to_umask ${i} - cd ${ddpath} | ${bin} import -c ${cfg} -f -p p1 -V ${i} + chmod_to_umask "${i}" + cd "${ddpath}" | ${bin} import -c "${cfg}" -f -p p1 -V "${i}" done -cat ${cfg} +cat "${cfg}" # list files -cd ${ddpath} | ${bin} detail -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} detail -c "${cfg}" -p p1 -V -cat ${cfg} -tot=`echo ${toimport} | wc -w` -cnt=`cat ${cfg} | grep "chmod: " | wc -l` +cat "${cfg}" +tot=$(echo "${toimport}" | wc -w) +cnt=$(cat "${cfg}" | grep "chmod: " | wc -l) [ "${cnt}" != "${tot}" ] && echo "not all chmod inserted (3)" && exit 1 echo "OK" diff --git a/tests-ng/chmod-install.sh b/tests-ng/chmod-install.sh index e635dc5..ad65417 100755 --- a/tests-ng/chmod-install.sh +++ b/tests-ng/chmod-install.sh @@ -33,7 +33,9 @@ ddpath="${cur}/../" 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}" @@ -41,7 +43,7 @@ echo "pythonpath: ${PYTHONPATH}" # get the 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,31 +56,31 @@ has_rights() echo "testing ${1} is ${2}" [ ! -e "$1" ] && echo "`basename $1` does not exist" && exit 1 local mode=`stat -L -c '%a' "$1"` - [ "${mode}" != "$2" ] && echo "bad mode for `basename $1` (${mode} VS expected ${2})" && exit 1 + [ "${mode}" != "$2" ] && echo "bad mode for `basename "$1"` (${mode} VS expected ${2})" && exit 1 true } get_file_mode() { - u=`umask` - u=`echo ${u} | sed 's/^0*//'` + u=$(umask) + u=$(echo "${u}" | sed 's/^0*//') v=$((666 - u)) echo "${v}" } get_dir_mode() { - u=`umask` - u=`echo ${u} | sed 's/^0*//'` + u=$(umask) + u=$(echo "${u}" | sed 's/^0*//') v=$((777 - u)) echo "${v}" } # 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}" clear_on_exit "${tmps}" @@ -87,42 +89,42 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -echo 'f777' > ${tmps}/dotfiles/f777 -chmod 700 ${tmps}/dotfiles/f777 -echo 'link' > ${tmps}/dotfiles/link -chmod 777 ${tmps}/dotfiles/link -mkdir -p ${tmps}/dotfiles/dir -echo "f1" > ${tmps}/dotfiles/dir/f1 +echo 'f777' > "${tmps}"/dotfiles/f777 +chmod 700 "${tmps}"/dotfiles/f777 +echo 'link' > "${tmps}"/dotfiles/link +chmod 777 "${tmps}"/dotfiles/link +mkdir -p "${tmps}"/dotfiles/dir +echo "f1" > "${tmps}"/dotfiles/dir/f1 -echo "exists" > ${tmps}/dotfiles/exists -chmod 644 ${tmps}/dotfiles/exists -echo "exists" > ${tmpd}/exists -chmod 644 ${tmpd}/exists +echo "exists" > "${tmps}"/dotfiles/exists +chmod 644 "${tmps}"/dotfiles/exists +echo "exists" > "${tmpd}"/exists +chmod 644 "${tmpd}"/exists -echo "existslink" > ${tmps}/dotfiles/existslink -chmod 777 ${tmps}/dotfiles/existslink -chmod 644 ${tmpd}/exists +echo "existslink" > "${tmps}"/dotfiles/existslink +chmod 777 "${tmps}"/dotfiles/existslink +chmod 644 "${tmpd}"/exists -mkdir -p ${tmps}/dotfiles/direxists -echo "f1" > ${tmps}/dotfiles/direxists/f1 -mkdir -p ${tmpd}/direxists -echo "f1" > ${tmpd}/direxists/f1 -chmod 644 ${tmpd}/direxists/f1 -chmod 744 ${tmpd}/direxists +mkdir -p "${tmps}"/dotfiles/direxists +echo "f1" > "${tmps}"/dotfiles/direxists/f1 +mkdir -p "${tmpd}"/direxists +echo "f1" > "${tmpd}"/direxists/f1 +chmod 644 "${tmpd}"/direxists/f1 +chmod 744 "${tmpd}"/direxists -mkdir -p ${tmps}/dotfiles/linkchildren -echo "f1" > ${tmps}/dotfiles/linkchildren/f1 -mkdir -p ${tmps}/dotfiles/linkchildren/d1 -echo "f2" > ${tmps}/dotfiles/linkchildren/d1/f2 +mkdir -p "${tmps}"/dotfiles/linkchildren +echo "f1" > "${tmps}"/dotfiles/linkchildren/f1 +mkdir -p "${tmps}"/dotfiles/linkchildren/d1 +echo "f2" > "${tmps}"/dotfiles/linkchildren/d1/f2 -echo '{{@@ profile @@}}' > ${tmps}/dotfiles/symlinktemplate +echo '{{@@ profile @@}}' > "${tmps}"/dotfiles/symlinktemplate -mkdir -p ${tmps}/dotfiles/symlinktemplatedir -echo "{{@@ profile @@}}" > ${tmps}/dotfiles/symlinktemplatedir/t +mkdir -p "${tmps}"/dotfiles/symlinktemplatedir +echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/symlinktemplatedir/t -echo 'nomode' > ${tmps}/dotfiles/nomode +echo 'nomode' > "${tmps}"/dotfiles/nomode -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -197,7 +199,7 @@ _EOF # install echo "first install round" -cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 -V +cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 -V echo "first install round" has_rights "${tmpd}/f777" "777" @@ -212,24 +214,24 @@ has_rights "${tmpd}/linkchildren/f1" "644" has_rights "${tmpd}/linkchildren/d1" "755" has_rights "${tmpd}/linkchildren/d1/f2" "644" has_rights "${tmpd}/symlinktemplate" "777" -m=`get_file_mode` +m=$(get_file_mode) has_rights "${tmpd}/nomode" "${m}" -grep 'p1' ${tmpd}/symlinktemplate -grep 'p1' ${tmpd}/symlinktemplatedir/t +grep 'p1' "${tmpd}"/symlinktemplate +grep 'p1' "${tmpd}"/symlinktemplatedir/t ## second round -echo "exists" > ${tmps}/dotfiles/exists -chmod 600 ${tmps}/dotfiles/exists -echo "exists" > ${tmpd}/exists -chmod 600 ${tmpd}/exists +echo "exists" > "${tmps}"/dotfiles/exists +chmod 600 "${tmps}"/dotfiles/exists +echo "exists" > "${tmpd}"/exists +chmod 600 "${tmpd}"/exists -chmod 700 ${tmpd}/linkchildren +chmod 700 "${tmpd}"/linkchildren -chmod 600 ${tmpd}/symlinktemplate +chmod 600 "${tmpd}"/symlinktemplate echo "second install round" -cd ${ddpath} | ${bin} install -c ${cfg} -p p2 -f -V +cd "${ddpath}" | ${bin} install -c "${cfg}" -p p2 -f -V echo "second install round" has_rights "${tmpd}/exists" "777" @@ -237,39 +239,39 @@ has_rights "${tmpd}/linkchildren/f1" "644" has_rights "${tmpd}/linkchildren/d1" "755" has_rights "${tmpd}/linkchildren/d1/f2" "644" has_rights "${tmpd}/symlinktemplate" "777" -m=`get_file_mode` +m=$(get_file_mode) has_rights "${tmpd}/nomode" "${m}" ## no user confirmation expected ## same mode echo "same mode" -echo "nomode" > ${tmps}/dotfiles/nomode -chmod 600 ${tmps}/dotfiles/nomode -echo "nomode" > ${tmpd}/nomode -chmod 600 ${tmpd}/nomode -cd ${ddpath} | ${bin} install -c ${cfg} -f -p p2 -V f_nomode +echo "nomode" > "${tmps}"/dotfiles/nomode +chmod 600 "${tmps}"/dotfiles/nomode +echo "nomode" > "${tmpd}"/nomode +chmod 600 "${tmpd}"/nomode +cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p2 -V f_nomode echo "same mode" has_rights "${tmpd}/nomode" "600" ## no user confirmation with force ## different mode echo "different mode" -echo "nomode" > ${tmps}/dotfiles/nomode -chmod 600 ${tmps}/dotfiles/nomode -echo "nomode" > ${tmpd}/nomode -chmod 700 ${tmpd}/nomode -cd ${ddpath} | ${bin} install -c ${cfg} -f -p p2 -V f_nomode +echo "nomode" > "${tmps}"/dotfiles/nomode +chmod 600 "${tmps}"/dotfiles/nomode +echo "nomode" > "${tmpd}"/nomode +chmod 700 "${tmpd}"/nomode +cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p2 -V f_nomode echo "different mode (1)" has_rights "${tmpd}/nomode" "600" ## user confirmation expected ## different mode echo "different mode" -echo "nomode" > ${tmps}/dotfiles/nomode -chmod 600 ${tmps}/dotfiles/nomode -echo "nomode" > ${tmpd}/nomode -chmod 700 ${tmpd}/nomode -cd ${ddpath} | printf 'y\ny\n' | ${bin} install -f -c ${cfg} -p p2 -V f_nomode +echo "nomode" > "${tmps}"/dotfiles/nomode +chmod 600 "${tmps}"/dotfiles/nomode +echo "nomode" > "${tmpd}"/nomode +chmod 700 "${tmpd}"/nomode +cd "${ddpath}" | printf 'y\ny\n' | ${bin} install -f -c "${cfg}" -p p2 -V f_nomode echo "different mode (2)" has_rights "${tmpd}/nomode" "600" diff --git a/tests-ng/chmod-more.sh b/tests-ng/chmod-more.sh index 001734a..955eb75 100755 --- a/tests-ng/chmod-more.sh +++ b/tests-ng/chmod-more.sh @@ -33,7 +33,9 @@ ddpath="${cur}/../" 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}" @@ -41,7 +43,7 @@ echo "pythonpath: ${PYTHONPATH}" # get the 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,28 +56,28 @@ has_rights() echo "testing ${1} is ${2}" [ ! -e "$1" ] && echo "`basename $1` does not exist" && exit 1 local mode=`stat -L -c '%a' "$1"` - [ "${mode}" != "$2" ] && echo "bad mode for `basename $1` (${mode} instead of ${2})" && exit 1 + [ "${mode}" != "$2" ] && echo "bad mode for `basename "$1"` (${mode} instead of ${2})" && exit 1 true } # $1 file chmod_to_umask() { - u=`umask` - u=`echo ${u} | sed 's/^0*//'` - if [ -d ${1} ]; then + u=$(umask) + u=$(echo "${u}" | sed 's/^0*//') + if [ -d "${1}" ]; then v=$((777 - u)) else v=$((666 - u)) fi - chmod ${v} ${1} + chmod ${v} "${1}" } # 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}" clear_on_exit "${tmps}" @@ -83,21 +85,21 @@ clear_on_exit "${tmpd}" # create the dotfiles f1="${tmpd}/f1" -touch ${f1} -chmod 777 ${f1} -stat -c '%a' ${f1} +touch "${f1}" +chmod 777 "${f1}" +stat -c '%a' "${f1}" f2="${tmpd}/f2" -touch ${f2} -chmod 644 ${f2} -stat -c '%a' ${f2} +touch "${f2}" +chmod 644 "${f2}" +stat -c '%a' "${f2}" toimport="${f1} ${f2}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -109,11 +111,11 @@ _EOF # import without --preserve-mode for i in ${toimport}; do - stat -c '%a' ${i} - cd ${ddpath} | ${bin} import -c ${cfg} -f -p p1 -V ${i} + stat -c '%a' "${i}" + cd "${ddpath}" | ${bin} import -c "${cfg}" -f -p p1 -V "${i}" done -cat ${cfg} +cat "${cfg}" has_rights "${tmpd}/f1" "777" has_rights "${tmps}/dotfiles/${tmpd}/f1" "777" @@ -121,7 +123,7 @@ has_rights "${tmpd}/f2" "644" has_rights "${tmps}/dotfiles/${tmpd}/f2" "644" # install -cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 -V | grep '0 dotfile(s) installed' || (echo "should not install" && exit 1) +cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 -V | grep '0 dotfile(s) installed' || (echo "should not install" && exit 1) echo "OK" exit 0 diff --git a/tests-ng/chmod-preserve-install.sh b/tests-ng/chmod-preserve-install.sh index 3ff2330..2e1fe50 100755 --- a/tests-ng/chmod-preserve-install.sh +++ b/tests-ng/chmod-preserve-install.sh @@ -31,7 +31,9 @@ ddpath="${cur}/../" 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}" @@ -39,7 +41,7 @@ echo "pythonpath: ${PYTHONPATH}" # get the 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 @@ -68,31 +70,31 @@ is_same_as() local mode2=`stat -L -c '%a' "$2"` echo "$2: ${mode2}" - [ "${mode1}" != "${mode2}" ] && echo "`basename $1` (${mode1}) does not have same mode as `basename $2` (${mode2})" && exit 1 + [ "${mode1}" != "${mode2}" ] && echo "`basename $1` (${mode1}) does not have same mode as `basename "$2"` (${mode2})" && exit 1 true } get_default_file_mode() { - u=`umask` - u=`echo ${u} | sed 's/^0*//'` + u=$(umask) + u=$(echo "${u}" | sed 's/^0*//') v=$((666 - u)) echo "${v}" } get_default_dir_mode() { - u=`umask` - u=`echo ${u} | sed 's/^0*//'` + u=$(umask) + u=$(echo "${u}" | sed 's/^0*//') v=$((777 - u)) echo "${v}" } # 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}" clear_on_exit "${tmps}" @@ -106,70 +108,70 @@ cfg="${tmps}/config.yaml" ## # file -echo 'f777' > ${tmps}/dotfiles/f777 -chmod 700 ${tmps}/dotfiles/f777 +echo 'f777' > "${tmps}"/dotfiles/f777 +chmod 700 "${tmps}"/dotfiles/f777 # link -echo 'link' > ${tmps}/dotfiles/link -chmod 700 ${tmps}/dotfiles/link +echo 'link' > "${tmps}"/dotfiles/link +chmod 700 "${tmps}"/dotfiles/link # directory -mkdir -p ${tmps}/dotfiles/dir -echo "f1" > ${tmps}/dotfiles/dir/f1 -chmod 700 ${tmps}/dotfiles/dir -chmod 700 ${tmps}/dotfiles/dir/f1 +mkdir -p "${tmps}"/dotfiles/dir +echo "f1" > "${tmps}"/dotfiles/dir/f1 +chmod 700 "${tmps}"/dotfiles/dir +chmod 700 "${tmps}"/dotfiles/dir/f1 # template -echo '{{@@ profile @@}}' > ${tmps}/dotfiles/template -chmod 700 ${tmps}/dotfiles/template +echo '{{@@ profile @@}}' > "${tmps}"/dotfiles/template +chmod 700 "${tmps}"/dotfiles/template # link template -echo '{{@@ profile @@}}' > ${tmps}/dotfiles/link-template -chmod 700 ${tmps}/dotfiles/link-template +echo '{{@@ profile @@}}' > "${tmps}"/dotfiles/link-template +chmod 700 "${tmps}"/dotfiles/link-template ## # existing files ## # file -echo "exists-original" > ${tmps}/dotfiles/exists -chmod 644 ${tmps}/dotfiles/exists -echo "exists" > ${tmpd}/exists -chmod 700 ${tmpd}/exists +echo "exists-original" > "${tmps}"/dotfiles/exists +chmod 644 "${tmps}"/dotfiles/exists +echo "exists" > "${tmpd}"/exists +chmod 700 "${tmpd}"/exists # link -echo "existslink" > ${tmps}/dotfiles/existslink -chmod 700 ${tmps}/dotfiles/existslink -ln -s ${tmps}/dotfiles/existslink ${tmpd}/existslink +echo "existslink" > "${tmps}"/dotfiles/existslink +chmod 700 "${tmps}"/dotfiles/existslink +ln -s "${tmps}"/dotfiles/existslink "${tmpd}"/existslink # directory -mkdir -p ${tmps}/dotfiles/direxists -echo "f1-original" > ${tmps}/dotfiles/direxists/f1 -mkdir -p ${tmpd}/direxists -echo "f1" > ${tmpd}/direxists/f1 -chmod 700 ${tmpd}/direxists/f1 -chmod 700 ${tmpd}/direxists +mkdir -p "${tmps}"/dotfiles/direxists +echo "f1-original" > "${tmps}"/dotfiles/direxists/f1 +mkdir -p "${tmpd}"/direxists +echo "f1" > "${tmpd}"/direxists/f1 +chmod 700 "${tmpd}"/direxists/f1 +chmod 700 "${tmpd}"/direxists # link children -mkdir -p ${tmps}/dotfiles/linkchildren -echo "f1-original" > ${tmps}/dotfiles/linkchildren/f1 -chmod 700 ${tmps}/dotfiles/linkchildren/f1 -mkdir -p ${tmps}/dotfiles/linkchildren/d1 -chmod 700 ${tmps}/dotfiles/linkchildren/d1 -echo "f2-original" > ${tmps}/dotfiles/linkchildren/d1/f2 -chmod 700 ${tmps}/dotfiles/linkchildren/d1/f2 +mkdir -p "${tmps}"/dotfiles/linkchildren +echo "f1-original" > "${tmps}"/dotfiles/linkchildren/f1 +chmod 700 "${tmps}"/dotfiles/linkchildren/f1 +mkdir -p "${tmps}"/dotfiles/linkchildren/d1 +chmod 700 "${tmps}"/dotfiles/linkchildren/d1 +echo "f2-original" > "${tmps}"/dotfiles/linkchildren/d1/f2 +chmod 700 "${tmps}"/dotfiles/linkchildren/d1/f2 -mkdir -p ${tmpd}/linkchildren -chmod 700 ${tmpd}/linkchildren -echo "f1" > ${tmpd}/linkchildren/f1 -mkdir -p ${tmpd}/linkchildren/d1 -echo "f2" > ${tmpd}/linkchildren/d1/f2 +mkdir -p "${tmpd}"/linkchildren +chmod 700 "${tmpd}"/linkchildren +echo "f1" > "${tmpd}"/linkchildren/f1 +mkdir -p "${tmpd}"/linkchildren/d1 +echo "f2" > "${tmpd}"/linkchildren/d1/f2 # no mode -echo 'nomode-original' > ${tmps}/dotfiles/nomode -echo 'nomode' > ${tmpd}/nomode +echo 'nomode-original' > "${tmps}"/dotfiles/nomode +echo 'nomode' > "${tmpd}"/nomode -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -235,23 +237,23 @@ profiles: _EOF #cat ${cfg} -exists_before=`stat -L -c '%a' "${tmpd}/exists"` -direxists_before=`stat -L -c '%a' "${tmpd}/direxists"` -direxists_f1_before=`stat -L -c '%a' "${tmpd}/direxists/f1"` +exists_before=$(stat -L -c '%a' "${tmpd}/exists") +direxists_before=$(stat -L -c '%a' "${tmpd}/direxists") +direxists_f1_before=$(stat -L -c '%a' "${tmpd}/direxists/f1") # install echo "first round" -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V echo "first round" # non-existing but will create with "default" rights on preserve # 644 for file # 755 for directory # link will get the rights of the file it points to -has_rights "${tmpd}/f777" "`get_default_file_mode`" +has_rights "${tmpd}/f777" "$(get_default_file_mode)" has_rights "${tmpd}/link" "700" -has_rights "${tmpd}/dir" "`get_default_dir_mode`" -has_rights "${tmpd}/template" "`get_default_file_mode`" +has_rights "${tmpd}/dir" "$(get_default_dir_mode)" +has_rights "${tmpd}/template" "$(get_default_file_mode)" # first install to workdir (def rights) and then symlink has_rights "${tmpd}/link-template" "644" [ -L "${tmpd}/link-template" ] && echo "link-template is not a symlink" && exit 1 @@ -275,20 +277,20 @@ has_rights "${tmpd}/linkchildren/d1" "700" # points back to dotpath has_rights "${tmpd}/linkchildren/d1/f2" "700" # modify -echo 'f777-2' >> ${tmps}/dotfiles/f777 -chmod 701 ${tmps}/dotfiles/f777 -echo 'link-2' >> ${tmps}/dotfiles/link -chmod 701 ${tmps}/dotfiles/link -echo "f1-2" >> ${tmps}/dotfiles/dir/f1 -chmod 701 ${tmps}/dotfiles/dir -chmod 701 ${tmps}/dotfiles/dir/f1 +echo 'f777-2' >> "${tmps}"/dotfiles/f777 +chmod 701 "${tmps}"/dotfiles/f777 +echo 'link-2' >> "${tmps}"/dotfiles/link +chmod 701 "${tmps}"/dotfiles/link +echo "f1-2" >> "${tmps}"/dotfiles/dir/f1 +chmod 701 "${tmps}"/dotfiles/dir +chmod 701 "${tmps}"/dotfiles/dir/f1 -f777_before=`stat -L -c '%a' "${tmpd}/f777"` -link_before=`stat -L -c '%a' "${tmpd}/link"` -dir_before=`stat -L -c '%a' "${tmpd}/dir"` +f777_before=$(stat -L -c '%a' "${tmpd}/f777") +link_before=$(stat -L -c '%a' "${tmpd}/link") +dir_before=$(stat -L -c '%a' "${tmpd}/dir") echo "second round" -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V echo "second round" # existing diff --git a/tests-ng/chmod-preserve-update.sh b/tests-ng/chmod-preserve-update.sh index ab9c5d7..8b0a413 100755 --- a/tests-ng/chmod-preserve-update.sh +++ b/tests-ng/chmod-preserve-update.sh @@ -27,29 +27,32 @@ 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}" clear_on_exit "${tmps}" @@ -60,46 +63,46 @@ clear_on_exit "${tmpd}" ## # file -echo "exists-original" > ${tmps}/dotfiles/exists -chmod 644 ${tmps}/dotfiles/exists -echo "exists" > ${tmpd}/exists -chmod 700 ${tmpd}/exists +echo "exists-original" > "${tmps}"/dotfiles/exists +chmod 644 "${tmps}"/dotfiles/exists +echo "exists" > "${tmpd}"/exists +chmod 700 "${tmpd}"/exists # link -echo "existslink" > ${tmps}/dotfiles/existslink -chmod 700 ${tmps}/dotfiles/existslink -ln -s ${tmps}/dotfiles/existslink ${tmpd}/existslink +echo "existslink" > "${tmps}"/dotfiles/existslink +chmod 700 "${tmps}"/dotfiles/existslink +ln -s "${tmps}"/dotfiles/existslink "${tmpd}"/existslink # directory -mkdir -p ${tmps}/dotfiles/direxists -echo "f1-original" > ${tmps}/dotfiles/direxists/f1 -mkdir -p ${tmpd}/direxists -echo "f1" > ${tmpd}/direxists/f1 -chmod 700 ${tmpd}/direxists/f1 -chmod 700 ${tmpd}/direxists +mkdir -p "${tmps}"/dotfiles/direxists +echo "f1-original" > "${tmps}"/dotfiles/direxists/f1 +mkdir -p "${tmpd}"/direxists +echo "f1" > "${tmpd}"/direxists/f1 +chmod 700 "${tmpd}"/direxists/f1 +chmod 700 "${tmpd}"/direxists # link children -mkdir -p ${tmps}/dotfiles/linkchildren -echo "f1-original" > ${tmps}/dotfiles/linkchildren/f1 -chmod 700 ${tmps}/dotfiles/linkchildren/f1 -mkdir -p ${tmps}/dotfiles/linkchildren/d1 -chmod 700 ${tmps}/dotfiles/linkchildren/d1 -echo "f2-original" > ${tmps}/dotfiles/linkchildren/d1/f2 -chmod 700 ${tmps}/dotfiles/linkchildren/d1/f2 +mkdir -p "${tmps}"/dotfiles/linkchildren +echo "f1-original" > "${tmps}"/dotfiles/linkchildren/f1 +chmod 700 "${tmps}"/dotfiles/linkchildren/f1 +mkdir -p "${tmps}"/dotfiles/linkchildren/d1 +chmod 700 "${tmps}"/dotfiles/linkchildren/d1 +echo "f2-original" > "${tmps}"/dotfiles/linkchildren/d1/f2 +chmod 700 "${tmps}"/dotfiles/linkchildren/d1/f2 -mkdir -p ${tmpd}/linkchildren -chmod 700 ${tmpd}/linkchildren -echo "f1" > ${tmpd}/linkchildren/f1 -mkdir -p ${tmpd}/linkchildren/d1 -echo "f2" > ${tmpd}/linkchildren/d1/f2 +mkdir -p "${tmpd}"/linkchildren +chmod 700 "${tmpd}"/linkchildren +echo "f1" > "${tmpd}"/linkchildren/f1 +mkdir -p "${tmpd}"/linkchildren/d1 +echo "f2" > "${tmpd}"/linkchildren/d1/f2 # no mode -echo 'nomode-original' > ${tmps}/dotfiles/nomode -echo 'nomode' > ${tmpd}/nomode +echo 'nomode-original' > "${tmps}"/dotfiles/nomode +echo 'nomode' > "${tmpd}"/nomode # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -140,13 +143,13 @@ _EOF #cat ${cfg} echo "update" -cd ${ddpath} | ${bin} update -f -c ${cfg} -p p1 -V ${tmpd}/exists -cd ${ddpath} | ${bin} update -f -c ${cfg} -p p1 -V ${tmpd}/existslink -cd ${ddpath} | ${bin} update -f -c ${cfg} -p p1 -V ${tmpd}/direxists -cd ${ddpath} | ${bin} update -f -c ${cfg} -p p1 -V ${tmpd}/linkchildren -cd ${ddpath} | ${bin} update -f -c ${cfg} -p p1 -V ${tmpd}/nomode +cd "${ddpath}" | ${bin} update -f -c "${cfg}" -p p1 -V "${tmpd}"/exists +cd "${ddpath}" | ${bin} update -f -c "${cfg}" -p p1 -V "${tmpd}"/existslink +cd "${ddpath}" | ${bin} update -f -c "${cfg}" -p p1 -V "${tmpd}"/direxists +cd "${ddpath}" | ${bin} update -f -c "${cfg}" -p p1 -V "${tmpd}"/linkchildren +cd "${ddpath}" | ${bin} update -f -c "${cfg}" -p p1 -V "${tmpd}"/nomode -count=$(cat ${cfg} | grep chmod | grep -v 'chmod: preserve\|force_chmod' | wc -l) +count=$(cat "${cfg}" | grep chmod | grep -v 'chmod: preserve\|force_chmod' | wc -l) echo "${count}" [ "${count}" != "0" ] && echo "chmod altered" && exit 1 diff --git a/tests-ng/chmod-update.sh b/tests-ng/chmod-update.sh index 5e38fbd..bb452d8 100755 --- a/tests-ng/chmod-update.sh +++ b/tests-ng/chmod-update.sh @@ -27,29 +27,32 @@ 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}" clear_on_exit "${tmps}" @@ -57,32 +60,32 @@ clear_on_exit "${tmpd}" # create the dotfile dnormal="${tmpd}/dir_normal" -mkdir -p ${dnormal} -echo "dir_normal/f1" > ${dnormal}/file1 -echo "dir_normal/f2" > ${dnormal}/file2 +mkdir -p "${dnormal}" +echo "dir_normal/f1" > "${dnormal}"/file1 +echo "dir_normal/f2" > "${dnormal}"/file2 dlink="${tmpd}/dir_link" -mkdir -p ${dlink} -echo "dir_link/f1" > ${dlink}/file1 -echo "dir_link/f2" > ${dlink}/file2 +mkdir -p "${dlink}" +echo "dir_link/f1" > "${dlink}"/file1 +echo "dir_link/f2" > "${dlink}"/file2 dlinkchildren="${tmpd}/dir_link_children" -mkdir -p ${dlinkchildren} -echo "dir_linkchildren/f1" > ${dlinkchildren}/file1 -echo "dir_linkchildren/f2" > ${dlinkchildren}/file2 +mkdir -p "${dlinkchildren}" +echo "dir_linkchildren/f1" > "${dlinkchildren}"/file1 +echo "dir_linkchildren/f2" > "${dlinkchildren}"/file2 fnormal="${tmpd}/filenormal" -echo "filenormal" > ${fnormal} +echo "filenormal" > "${fnormal}" flink="${tmpd}/filelink" -echo "filelink" > ${flink} +echo "filelink" > "${flink}" toimport="${dnormal} ${dlink} ${dlinkchildren} ${fnormal} ${flink}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -93,64 +96,64 @@ _EOF # import for i in ${toimport}; do - cd ${ddpath} | ${bin} import -c ${cfg} -f -p p1 -V ${i} + cd "${ddpath}" | ${bin} import -c "${cfg}" -f -p p1 -V "${i}" done -cat ${cfg} +cat "${cfg}" # test no chmod -cnt=`cat ${cfg} | grep chmod | wc -l` +cnt=$(cat "${cfg}" | grep chmod | wc -l) [ "${cnt}" != "0" ] && echo "chmod wrongly inserted" && exit 1 ###################### # update dnormal -chmod 777 ${dnormal} -cd ${ddpath} | ${bin} update -c ${cfg} -f -p p1 -V ${dnormal} +chmod 777 "${dnormal}" +cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 -V "${dnormal}" # check rights updated -[ "`stat -c '%a' ${tmps}/dotfiles/${tmpd}/$(basename ${dnormal})`" != "777" ] && echo "rights not updated (1)" && exit 1 +[ "$(stat -c '%a' "${tmps}"/dotfiles/"${tmpd}"/$(basename "${dnormal}"))" != "777" ] && echo "rights not updated (1)" && exit 1 -cnt=`cat ${cfg} | grep "chmod: '777'" | wc -l` +cnt=$(cat "${cfg}" | grep "chmod: '777'" | wc -l) [ "${cnt}" != "1" ] && echo "chmod not updated (1)" && exit 1 ###################### # update dlink -chmod 777 ${dlink} -cd ${ddpath} | ${bin} update -c ${cfg} -f -p p1 -V ${dlink} +chmod 777 "${dlink}" +cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 -V "${dlink}" # check rights updated -[ "`stat -c '%a' ${tmps}/dotfiles/${tmpd}/$(basename ${dlink})`" != "777" ] && echo "rights not updated (2)" && exit 1 -cnt=`cat ${cfg} | grep "chmod: '777'" | wc -l` +[ "$(stat -c '%a' "${tmps}"/dotfiles/"${tmpd}"/$(basename "${dlink}"))" != "777" ] && echo "rights not updated (2)" && exit 1 +cnt=$(cat "${cfg}" | grep "chmod: '777'" | wc -l) [ "${cnt}" != "2" ] && echo "chmod not updated (2)" && exit 1 ###################### # update dlinkchildren -chmod 777 ${dlinkchildren} -cd ${ddpath} | ${bin} update -c ${cfg} -f -p p1 -V ${dlinkchildren} +chmod 777 "${dlinkchildren}" +cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 -V "${dlinkchildren}" # check rights updated -[ "`stat -c '%a' ${tmps}/dotfiles/${tmpd}/$(basename ${dlinkchildren})`" != "777" ] && echo "rights not updated (3)" && exit 1 -cnt=`cat ${cfg} | grep "chmod: '777'" | wc -l` +[ "$(stat -c '%a' "${tmps}"/dotfiles/"${tmpd}"/$(basename "${dlinkchildren}"))" != "777" ] && echo "rights not updated (3)" && exit 1 +cnt=$(cat "${cfg}" | grep "chmod: '777'" | wc -l) [ "${cnt}" != "3" ] && echo "chmod not updated (3)" && exit 1 ###################### # update fnormal -chmod 777 ${fnormal} -cd ${ddpath} | ${bin} update -c ${cfg} -f -p p1 -V ${fnormal} +chmod 777 "${fnormal}" +cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 -V "${fnormal}" # check rights updated -[ "`stat -c '%a' ${tmps}/dotfiles/${tmpd}/$(basename ${fnormal})`" != "777" ] && echo "rights not updated (4)" && exit 1 -cnt=`cat ${cfg} | grep "chmod: '777'" | wc -l` +[ "$(stat -c '%a' "${tmps}"/dotfiles/"${tmpd}"/$(basename "${fnormal}"))" != "777" ] && echo "rights not updated (4)" && exit 1 +cnt=$(cat "${cfg}" | grep "chmod: '777'" | wc -l) [ "${cnt}" != "4" ] && echo "chmod not updated (4)" && exit 1 ###################### # update flink -chmod 777 ${flink} -cd ${ddpath} | ${bin} update -c ${cfg} -f -p p1 -V ${flink} +chmod 777 "${flink}" +cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 -V "${flink}" # check rights updated -[ "`stat -c '%a' ${tmps}/dotfiles/${tmpd}/$(basename ${flink})`" != "777" ] && echo "rights not updated (5)" && exit 1 -cnt=`cat ${cfg} | grep "chmod: '777'" | wc -l` +[ "$(stat -c '%a' "${tmps}"/dotfiles/"${tmpd}"/$(basename "${flink}"))" != "777" ] && echo "rights not updated (5)" && exit 1 +cnt=$(cat "${cfg}" | grep "chmod: '777'" | wc -l) [ "${cnt}" != "5" ] && echo "chmod not updated (5)" && exit 1 echo "OK" diff --git a/tests-ng/clear-workdir.sh b/tests-ng/clear-workdir.sh index 89a4f30..89632c7 100755 --- a/tests-ng/clear-workdir.sh +++ b/tests-ng/clear-workdir.sh @@ -28,32 +28,35 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` -mkdir -p ${basedir}/dotfiles +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${basedir}"/dotfiles echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) if [ -z "${DOTDROP_WORKDIR}" ]; then - tmpw=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` + tmpw=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) export DOTDROP_WORKDIR="${tmpw}" clear_on_exit "${tmpw}" fi @@ -61,11 +64,11 @@ fi clear_on_exit "${basedir}" clear_on_exit "${tmpd}" -echo "{{@@ profile @@}}" > ${basedir}/dotfiles/x +echo "{{@@ profile @@}}" > "${basedir}"/dotfiles/x # create the config file cfg="${basedir}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -82,30 +85,30 @@ profiles: _EOF echo "[+] install (1)" -cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 --verbose | grep '^1 dotfile(s) installed.$' +cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 --verbose | grep '^1 dotfile(s) installed.$' [ "$?" != "0" ] && exit 1 -[ ! -e ${tmpd}/x ] && echo "f_x not installed" && exit 1 -[ ! -h ${tmpd}/x ] && echo "f_x not symlink" && exit 1 -[ ! -e ${DOTDROP_WORKDIR}/${tmpd}/x ] && echo "f_x not in workdir (${DOTDROP_WORKDIR}/${tmpd})" && exit 1 +[ ! -e "${tmpd}"/x ] && echo "f_x not installed" && exit 1 +[ ! -h "${tmpd}"/x ] && echo "f_x not symlink" && exit 1 +[ ! -e "${DOTDROP_WORKDIR}"/"${tmpd}"/x ] && echo "f_x not in workdir (${DOTDROP_WORKDIR}/${tmpd})" && exit 1 # add file -touch ${DOTDROP_WORKDIR}/new +touch "${DOTDROP_WORKDIR}"/new echo "[+] re-install with clear-workdir in cli" -cd ${ddpath} | printf "y\n" | ${bin} install -W -c ${cfg} -p p1 --verbose +cd "${ddpath}" | printf "y\n" | ${bin} install -W -c "${cfg}" -p p1 --verbose [ "$?" != "0" ] && exit 1 -[ ! -e ${tmpd}/x ] && echo "f_x not installed" && exit 1 -[ ! -h ${tmpd}/x ] && echo "f_x not symlink" && exit 1 -[ ! -e ${DOTDROP_WORKDIR}/${tmpd}/x ] && echo "f_x not in workdir (${DOTDROP_WORKDIR}/${tmpd})" && exit 1 -[ -e ${DOTDROP_WORKDIR}/new ] && echo "workdir not cleared (1)" && exit 1 +[ ! -e "${tmpd}"/x ] && echo "f_x not installed" && exit 1 +[ ! -h "${tmpd}"/x ] && echo "f_x not symlink" && exit 1 +[ ! -e "${DOTDROP_WORKDIR}"/"${tmpd}"/x ] && echo "f_x not in workdir (${DOTDROP_WORKDIR}/${tmpd})" && exit 1 +[ -e "${DOTDROP_WORKDIR}"/new ] && echo "workdir not cleared (1)" && exit 1 # add file -touch ${DOTDROP_WORKDIR}/new +touch "${DOTDROP_WORKDIR}"/new echo "[+] re-install with config clear-workdir in config" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -121,13 +124,13 @@ profiles: dotfiles: - f_x _EOF -cd ${ddpath} | printf "y\n" | ${bin} install -W -c ${cfg} -p p1 --verbose +cd "${ddpath}" | printf "y\n" | ${bin} install -W -c "${cfg}" -p p1 --verbose [ "$?" != "0" ] && exit 1 -[ ! -e ${tmpd}/x ] && echo "f_x not installed" && exit 1 -[ ! -h ${tmpd}/x ] && echo "f_x not symlink" && exit 1 -[ ! -e ${DOTDROP_WORKDIR}/${tmpd}/x ] && echo "f_x not in workdir (${DOTDROP_WORKDIR}/${tmpd})" && exit 1 -[ -e ${DOTDROP_WORKDIR}/new ] && echo "workdir not cleared (2)" && exit 1 +[ ! -e "${tmpd}"/x ] && echo "f_x not installed" && exit 1 +[ ! -h "${tmpd}"/x ] && echo "f_x not symlink" && exit 1 +[ ! -e "${DOTDROP_WORKDIR}"/"${tmpd}"/x ] && echo "f_x not in workdir (${DOTDROP_WORKDIR}/${tmpd})" && exit 1 +[ -e "${DOTDROP_WORKDIR}"/new ] && echo "workdir not cleared (2)" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/compare-ignore-missing.sh b/tests-ng/compare-ignore-missing.sh index c055f49..ff0c09c 100755 --- a/tests-ng/compare-ignore-missing.sh +++ b/tests-ng/compare-ignore-missing.sh @@ -23,47 +23,50 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" dt="${basedir}/dotfiles" -mkdir -p ${dt}/folder -touch ${dt}/folder/a +mkdir -p "${dt}"/folder +touch "${dt}"/folder/a # the dotfile to be imported -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # some files -cp -r ${dt}/folder ${tmpd}/ -mkdir -p ${tmpd}/folder -touch ${tmpd}/folder/b -mkdir ${tmpd}/folder/c +cp -r "${dt}"/folder "${tmpd}"/ +mkdir -p "${tmpd}"/folder +touch "${tmpd}"/folder/b +mkdir "${tmpd}"/folder/c # create the config file cfg="${basedir}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: false create: true @@ -85,7 +88,7 @@ _EOF # Expect diff echo "[+] test with no ignore-missing setting" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose --profile=p1 +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose --profile=p1 [ "$?" = "0" ] && exit 1 set -e @@ -96,7 +99,7 @@ set -e # Expect no diff echo "[+] test with command-line flag" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose --profile=p1 --ignore-missing +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose --profile=p1 --ignore-missing [ "$?" != "0" ] && exit 1 set -e @@ -104,7 +107,7 @@ set -e # Test with global option # -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: false create: true @@ -123,7 +126,7 @@ _EOF # Expect no diff echo "[+] test global option" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose --profile=p1 +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose --profile=p1 [ "$?" != "0" ] && exit 1 set -e @@ -131,7 +134,7 @@ set -e # Test with dotfile option # -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: false create: true @@ -150,7 +153,7 @@ _EOF # Expect no diff echo "[+] test dotfile option" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose --profile=p1 +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose --profile=p1 [ "$?" != "0" ] && exit 1 set -e diff --git a/tests-ng/compare-ignore-relative.sh b/tests-ng/compare-ignore-relative.sh index dea2790..76df05d 100755 --- a/tests-ng/compare-ignore-relative.sh +++ b/tests-ng/compare-ignore-relative.sh @@ -28,61 +28,64 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" # the dotfile to be imported -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # some files -mkdir -p ${tmpd}/{program,config,vscode} -touch ${tmpd}/program/a -touch ${tmpd}/config/a -touch ${tmpd}/vscode/extensions.txt -touch ${tmpd}/vscode/keybindings.json +mkdir -p "${tmpd}"/{program,config,vscode} +touch "${tmpd}"/program/a +touch "${tmpd}"/config/a +touch "${tmpd}"/vscode/extensions.txt +touch "${tmpd}"/vscode/keybindings.json # create the config file cfg="${basedir}/config.yaml" -create_conf ${cfg} # sets token +create_conf "${cfg}" # sets token # import echo "[+] import" -cd ${ddpath} | ${bin} import -f --verbose -c ${cfg} ${tmpd}/program || exit 1 -cd ${ddpath} | ${bin} import -f --verbose -c ${cfg} ${tmpd}/config || exit 1 -cd ${ddpath} | ${bin} import -f --verbose -c ${cfg} ${tmpd}/vscode || exit 1 +cd "${ddpath}" | ${bin} import -f --verbose -c "${cfg}" "${tmpd}"/program || exit 1 +cd "${ddpath}" | ${bin} import -f --verbose -c "${cfg}" "${tmpd}"/config || exit 1 +cd "${ddpath}" | ${bin} import -f --verbose -c "${cfg}" "${tmpd}"/vscode || exit 1 # add files on filesystem echo "[+] add files" -touch ${tmpd}/program/b -touch ${tmpd}/config/b +touch "${tmpd}"/program/b +touch "${tmpd}"/config/b # expects diff echo "[+] comparing normal - diffs expected" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose ret="$?" echo ${ret} [ "${ret}" = "0" ] && exit 1 @@ -92,78 +95,78 @@ set -e patt="b" echo "[+] comparing with ignore (pattern: ${patt}) - no diff expected" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose --ignore=${patt} +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose --ignore=${patt} [ "$?" != "0" ] && exit 1 set -e # adding ignore in dotfile cfg2="${basedir}/config2.yaml" -sed '/d_config:/a \ \ \ \ cmpignore:\n\ \ \ \ - "b"' ${cfg} > ${cfg2} +sed '/d_config:/a \ \ \ \ cmpignore:\n\ \ \ \ - "b"' "${cfg}" > "${cfg2}" #cat ${cfg2} # expects one diff echo "[+] comparing with ignore in dotfile - diff expected" set +e -cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose +cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose [ "$?" = "0" ] && exit 1 set -e # adding ignore in dotfile cfg2="${basedir}/config2.yaml" -sed '/d_config:/a \ \ \ \ cmpignore:\n\ \ \ \ - "b"' ${cfg} > ${cfg2} -sed -i '/d_program:/a \ \ \ \ cmpignore:\n\ \ \ \ - "b"' ${cfg2} +sed '/d_config:/a \ \ \ \ cmpignore:\n\ \ \ \ - "b"' "${cfg}" > "${cfg2}" +sed -i '/d_program:/a \ \ \ \ cmpignore:\n\ \ \ \ - "b"' "${cfg2}" #cat ${cfg2} # expects no diff echo "[+] comparing with ignore in dotfile - no diff expected" set +e -cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose +cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose [ "$?" != "0" ] && exit 1 set -e # update files -echo touched > ${tmpd}/vscode/extensions.txt -echo touched > ${tmpd}/vscode/keybindings.json +echo touched > "${tmpd}"/vscode/extensions.txt +echo touched > "${tmpd}"/vscode/keybindings.json # expect two diffs echo "[+] comparing - diff expected" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -C ${tmpd}/vscode +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose -C "${tmpd}"/vscode [ "$?" = "0" ] && exit 1 set -e # expects no diff echo "[+] comparing with ignore in dotfile - no diff expected" -sed '/d_vscode:/a \ \ \ \ cmpignore:\n\ \ \ \ - "extensions.txt"\n\ \ \ \ - "keybindings.json"' ${cfg} > ${cfg2} +sed '/d_vscode:/a \ \ \ \ cmpignore:\n\ \ \ \ - "extensions.txt"\n\ \ \ \ - "keybindings.json"' "${cfg}" > "${cfg2}" set +e -cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose -C ${tmpd}/vscode +cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose -C "${tmpd}"/vscode [ "$?" != "0" ] && exit 1 set -e #################### # test for #149 #################### -mkdir -p ${tmpd}/.zsh -touch ${tmpd}/.zsh/somefile -mkdir -p ${tmpd}/.zsh/plugins -touch ${tmpd}/.zsh/plugins/someplugin +mkdir -p "${tmpd}"/.zsh +touch "${tmpd}"/.zsh/somefile +mkdir -p "${tmpd}"/.zsh/plugins +touch "${tmpd}"/.zsh/plugins/someplugin echo "[+] import .zsh" -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/.zsh +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/.zsh # no diff expected echo "[+] comparing .zsh" -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -C ${tmpd}/.zsh --ignore=${patt} +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose -C "${tmpd}"/.zsh --ignore=${patt} [ "$?" != "0" ] && exit 1 # add some files -touch ${tmpd}/.zsh/plugins/ignore-1.zsh -touch ${tmpd}/.zsh/plugins/ignore-2.zsh +touch "${tmpd}"/.zsh/plugins/ignore-1.zsh +touch "${tmpd}"/.zsh/plugins/ignore-2.zsh # expects diff echo "[+] comparing .zsh with new files" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -C ${tmpd}/.zsh +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose -C "${tmpd}"/.zsh ret="$?" echo ${ret} [ "${ret}" = "0" ] && exit 1 @@ -173,15 +176,15 @@ set -e patt="plugins/ignore-*.zsh" echo "[+] comparing with ignore (pattern: ${patt}) - no diff expected" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -C ${tmpd}/.zsh --ignore=${patt} +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose -C "${tmpd}"/.zsh --ignore="${patt}" [ "$?" != "0" ] && exit 1 set -e # expects no diff echo "[+] comparing with ignore in dotfile - no diff expected" -sed '/d_zsh:/a \ \ \ \ cmpignore:\n\ \ \ \ - "plugins/ignore-*.zsh"' ${cfg} > ${cfg2} +sed '/d_zsh:/a \ \ \ \ cmpignore:\n\ \ \ \ - "plugins/ignore-*.zsh"' "${cfg}" > "${cfg2}" set +e -cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose -C ${tmpd}/.zsh +cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose -C "${tmpd}"/.zsh [ "$?" != "0" ] && exit 1 set -e diff --git a/tests-ng/compare-ignore.sh b/tests-ng/compare-ignore.sh index 28da8e7..5fb7487 100755 --- a/tests-ng/compare-ignore.sh +++ b/tests-ng/compare-ignore.sh @@ -28,62 +28,65 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" # the dotfile to be imported -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # some files -mkdir -p ${tmpd}/{program,config} -touch ${tmpd}/program/a -touch ${tmpd}/config/a -mkdir ${tmpd}/vscode -touch ${tmpd}/vscode/extensions.txt -touch ${tmpd}/vscode/keybindings.json +mkdir -p "${tmpd}"/{program,config} +touch "${tmpd}"/program/a +touch "${tmpd}"/config/a +mkdir "${tmpd}"/vscode +touch "${tmpd}"/vscode/extensions.txt +touch "${tmpd}"/vscode/keybindings.json # create the config file cfg="${basedir}/config.yaml" -create_conf ${cfg} # sets token +create_conf "${cfg}" # sets token # import echo "[+] import" -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/program -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/config -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/vscode +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/program +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/config +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/vscode # add files echo "[+] add files" -touch ${tmpd}/program/b -touch ${tmpd}/config/b +touch "${tmpd}"/program/b +touch "${tmpd}"/config/b # expects diff echo "[+] comparing normal - 2 diffs" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose [ "$?" = "0" ] && exit 1 set -e @@ -91,7 +94,7 @@ set -e patt="${tmpd}/config/b" echo "[+] comparing with ignore (pattern: ${patt}) - 1 diff" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose --ignore=${patt} +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose --ignore="${patt}" [ "$?" = "0" ] && exit 1 set -e @@ -99,7 +102,7 @@ set -e patt="*b" echo "[+] comparing with ignore (pattern: ${patt}) - 0 diff" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose --ignore=${patt} +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose --ignore="${patt}" [ "$?" != "0" ] && exit 1 set -e @@ -107,7 +110,7 @@ set -e patt="*/config/*b" echo "[+] comparing with ignore (pattern: ${patt}) - 1 diff" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose --ignore=${patt} +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose --ignore="${patt}" [ "$?" = "0" ] && exit 1 set -e @@ -115,86 +118,86 @@ set -e # adding ignore in dotfile cfg2="${basedir}/config2.yaml" -sed '/d_config:/a \ \ \ \ cmpignore:\n\ \ \ \ - "*/config/b"' ${cfg} > ${cfg2} +sed '/d_config:/a \ \ \ \ cmpignore:\n\ \ \ \ - "*/config/b"' "${cfg}" > "${cfg2}" #cat ${cfg2} # expects one diff echo "[+] comparing with ignore in dotfile - 1 diff" set +e -cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose +cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose [ "$?" = "0" ] && exit 1 set -e # adding ignore in dotfile cfg2="${basedir}/config2.yaml" -sed '/d_config:/a \ \ \ \ cmpignore:\n\ \ \ \ - "*b"' ${cfg} > ${cfg2} -sed -i '/d_program:/a \ \ \ \ cmpignore:\n\ \ \ \ - "*b"' ${cfg2} +sed '/d_config:/a \ \ \ \ cmpignore:\n\ \ \ \ - "*b"' "${cfg}" > "${cfg2}" +sed -i '/d_program:/a \ \ \ \ cmpignore:\n\ \ \ \ - "*b"' "${cfg2}" #cat ${cfg2} # expects no diff patt="*b" echo "[+] comparing with ignore in dotfile - 0 diff" set +e -cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose +cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose [ "$?" != "0" ] && exit 1 set -e # update files -echo touched > ${tmpd}/vscode/extensions.txt -echo touched > ${tmpd}/vscode/keybindings.json +echo touched > "${tmpd}"/vscode/extensions.txt +echo touched > "${tmpd}"/vscode/keybindings.json # expect two diffs set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -C ${tmpd}/vscode +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose -C "${tmpd}"/vscode [ "$?" = "0" ] && exit 1 set -e # expects no diff -sed '/d_vscode:/a \ \ \ \ cmpignore:\n\ \ \ \ - "*extensions.txt"\n\ \ \ \ - "*keybindings.json"' ${cfg} > ${cfg2} +sed '/d_vscode:/a \ \ \ \ cmpignore:\n\ \ \ \ - "*extensions.txt"\n\ \ \ \ - "*keybindings.json"' "${cfg}" > "${cfg2}" set +e -cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose -C ${tmpd}/vscode +cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose -C "${tmpd}"/vscode [ "$?" != "0" ] && exit 1 set -e # clean -rm -rf ${basedir}/dotfiles -mkdir -p ${basedir}/dotfiles +rm -rf "${basedir}"/dotfiles +mkdir -p "${basedir}"/dotfiles # create dotfiles/dirs -mkdir -p ${tmpd}/{program,config,vscode} -touch ${tmpd}/program/a -touch ${tmpd}/config/a -touch ${tmpd}/vscode/extensions.txt -touch ${tmpd}/vscode/keybindings.json -touch ${tmpd}/vscode/keybindings.json +mkdir -p "${tmpd}"/{program,config,vscode} +touch "${tmpd}"/program/a +touch "${tmpd}"/config/a +touch "${tmpd}"/vscode/extensions.txt +touch "${tmpd}"/vscode/keybindings.json +touch "${tmpd}"/vscode/keybindings.json # create the config file cfg="${basedir}/config3.yaml" -create_conf ${cfg} # sets token +create_conf "${cfg}" # sets token # import echo "[+] import" -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/program ${tmpd}/config ${tmpd}/vscode +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/program "${tmpd}"/config "${tmpd}"/vscode # create the files to ignore -touch ${tmpd}/program/.DS_Store -touch ${tmpd}/config/.DS_Store -touch ${tmpd}/vscode/.DS_Store +touch "${tmpd}"/program/.DS_Store +touch "${tmpd}"/config/.DS_Store +touch "${tmpd}"/vscode/.DS_Store # ensure not imported -found=`find ${basedir}/dotfiles/ -iname '.DS_Store'` +found=$(find "${basedir}"/dotfiles/ -iname '.DS_Store') [ "${found}" != "" ] && echo "imported ???" && exit 1 # general ignore echo "[+] comparing ..." -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -i '*/.DS_Store' +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose -i '*/.DS_Store' [ "$?" != "0" ] && exit 1 # general ignore echo "[+] comparing2 ..." -sed '/^config:$/a\ \ cmpignore:\n\ \ - "*/.DS_Store"' ${cfg} > ${cfg2} -cat ${cfg2} -cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose +sed '/^config:$/a\ \ cmpignore:\n\ \ - "*/.DS_Store"' "${cfg}" > "${cfg2}" +cat "${cfg2}" +cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose [ "$?" != "0" ] && exit 1 echo "OK" diff --git a/tests-ng/compare-include.sh b/tests-ng/compare-include.sh index 43832e3..718acbe 100755 --- a/tests-ng/compare-include.sh +++ b/tests-ng/compare-include.sh @@ -27,41 +27,44 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" # create the dotfiles already imported -echo "already in" > ${tmps}/dotfiles/abc -cp ${tmps}/dotfiles/abc ${tmpd}/abc +echo "already in" > "${tmps}"/dotfiles/abc +cp "${tmps}"/dotfiles/abc "${tmpd}"/abc # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -84,36 +87,36 @@ profiles: dotfiles: - f_abc _EOF -cat ${cfg} +cat "${cfg}" -cd ${ddpath} | ${bin} files -c ${cfg} -p p0 +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p0 -cnt=`cd ${ddpath} | ${bin} files -c ${cfg} -p p0 | grep '^f_' | wc -l` +cnt=$(cd "${ddpath}" | ${bin} files -c "${cfg}" -p p0 | grep '^f_' | wc -l) [ "${cnt}" != "1" ] && echo "this is bad" && exit 1 # compare -cd ${ddpath} | ${bin} compare -c ${cfg} -p p0 +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p0 echo "modifying" -echo 'modified' > ${tmpd}/abc +echo 'modified' > "${tmpd}"/abc # compare set +e -cd ${ddpath} | ${bin} compare -c ${cfg} -p p0 +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p0 ret=$? [ "${ret}" = "0" ] && echo "compare should fail (returned ${ret})" && exit 1 set -e # count -cnt=`cd ${ddpath} | ${bin} files -c ${cfg} -p p0 -b | grep '^f_' | wc -l` +cnt=$(cd "${ddpath}" | ${bin} files -c "${cfg}" -p p0 -b | grep '^f_' | wc -l) [ "${cnt}" != "2" ] && echo "not enough dotfile" exit 1 ## without dotfiles: entry # reset dotfile content -echo "already in" > ${tmps}/dotfiles/abc -cp ${tmps}/dotfiles/abc ${tmpd}/abc +echo "already in" > "${tmps}"/dotfiles/abc +cp "${tmps}"/dotfiles/abc "${tmpd}"/abc -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -134,28 +137,28 @@ profiles: dotfiles: - f_abc _EOF -cat ${cfg} +cat "${cfg}" -cd ${ddpath} | ${bin} files -c ${cfg} -p p0 +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p0 -cnt=`cd ${ddpath} | ${bin} files -c ${cfg} -p p0 | grep '^f_' | wc -l` +cnt=$(cd "${ddpath}" | ${bin} files -c "${cfg}" -p p0 | grep '^f_' | wc -l) [ "${cnt}" != "1" ] && echo "this is bad" && exit 1 # compare -cd ${ddpath} | ${bin} compare -c ${cfg} -p p0 +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p0 echo "modifying" -echo 'modified' > ${tmpd}/abc +echo 'modified' > "${tmpd}"/abc # compare set +e -cd ${ddpath} | ${bin} compare -c ${cfg} -p p0 +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p0 ret=$? [ "${ret}" = "0" ] && echo "compare should fail (returned ${ret})" && exit 1 set -e # count -cnt=`cd ${ddpath} | ${bin} files -c ${cfg} -p p0 -b | grep '^f_' | wc -l` +cnt=$(cd "${ddpath}" | ${bin} files -c "${cfg}" -p p0 -b | grep '^f_' | wc -l) [ "${cnt}" != "2" ] && echo "not enough dotfile" exit 1 echo "OK" diff --git a/tests-ng/compare-negative-ignore-relative.sh b/tests-ng/compare-negative-ignore-relative.sh index b78ee7d..5502a06 100755 --- a/tests-ng/compare-negative-ignore-relative.sh +++ b/tests-ng/compare-negative-ignore-relative.sh @@ -9,41 +9,12 @@ set -e # all this crap to get current path -if [ $(uname) = Darwin ]; then - # Unfortunately, readlink works differently on macOS than it does on GNU/Linux - # (the -f option behaves differently) and the realpath command does not exist. - # Workarounds I find on the Internet suggest just using Homebrew to install coreutils - # so you can get the GNU coreutils on your Mac. But, I don't want this script to - # assume (a) users have Homebrew installed and (b) if they have Homebrew installed, that - # they then installed the GNU coreutils. - readlink() { - TARGET_FILE=$1 +rl="readlink -f" +if ! ${rl} "${0}" >/dev/null 2>&1; then + rl="realpath" - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - - # Iterate down a (possible) chain of symlinks - while [ -L "$TARGET_FILE" ]; do - TARGET_FILE=`readlink $TARGET_FILE` - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - done - - # Compute the canonicalized name by finding the physical path - # for the directory we're in and appending the target file. - PHYS_DIR=`pwd -P` - RESULT=$PHYS_DIR/$TARGET_FILE - echo $RESULT - } - rl="readlink" -else - rl="readlink -f" - if ! ${rl} "${0}" >/dev/null 2>&1; then - rl="realpath" - - if ! hash ${rl}; then - echo "\"${rl}\" not found !" && exit 1 - fi + if ! hash ${rl}; then + echo "\"${rl}\" not found !" && exit 1 fi fi cur=$(dirname "$(${rl} "${0}")") @@ -51,60 +22,63 @@ cur=$(dirname "$(${rl} "${0}")") # dotdrop path can be pass as argument ddpath="${cur}/../" [ -n "${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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" # the dotfile to be imported -tmpd=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # some files -mkdir -p ${tmpd}/program/ignore_me -echo "some data" > ${tmpd}/program/a -echo "some data" > ${tmpd}/program/ignore_me/b -echo "some data" > ${tmpd}/program/ignore_me/c +mkdir -p "${tmpd}"/program/ignore_me +echo "some data" > "${tmpd}"/program/a +echo "some data" > "${tmpd}"/program/ignore_me/b +echo "some data" > "${tmpd}"/program/ignore_me/c # create the config file cfg="${basedir}/config.yaml" -create_conf ${cfg} # sets token +create_conf "${cfg}" # sets token # import echo "[+] import" -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/program +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/program # make some changes to generate a diff -echo "some other data" > ${tmpd}/program/a -echo "some other data" > ${tmpd}/program/ignore_me/b -echo "some other data" > ${tmpd}/program/ignore_me/c +echo "some other data" > "${tmpd}"/program/a +echo "some other data" > "${tmpd}"/program/ignore_me/b +echo "some other data" > "${tmpd}"/program/ignore_me/c # expects two diffs (no need to test comparing normal - 3 diffs, as that is taken care of in compare-negative-ignore.sh) patt0="ignore_me/*" patt1="!ignore_me/c" echo "[+] comparing with ignore (patterns: ${patt0} and ${patt1}) - 2 diffs" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose --ignore=${patt0} --ignore=${patt1} +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose --ignore="${patt0}" --ignore=${patt1} [ "$?" = "0" ] && exit 1 set -e @@ -112,16 +86,16 @@ set -e # Test ignores specified in config.yaml ######################################## # add some files -mkdir -p ${tmpd}/.zsh -echo "some data" > ${tmpd}/.zsh/somefile -mkdir -p ${tmpd}/.zsh/plugins -echo "some data" > ${tmpd}/.zsh/plugins/someplugin +mkdir -p "${tmpd}"/.zsh +echo "some data" > "${tmpd}"/.zsh/somefile +mkdir -p "${tmpd}"/.zsh/plugins +echo "some data" > "${tmpd}"/.zsh/plugins/someplugin echo "[+] import .zsh" -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/.zsh +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/.zsh -touch ${tmpd}/.zsh/plugins/ignore-1.zsh -touch ${tmpd}/.zsh/plugins/ignore-2.zsh +touch "${tmpd}"/.zsh/plugins/ignore-1.zsh +touch "${tmpd}"/.zsh/plugins/ignore-2.zsh # adding ignore in config.yaml cfg2="${basedir}/config2.yaml" @@ -129,21 +103,21 @@ sed '/d_zsh:/a\ \ \ \ \ cmpignore:\ \ \ \ \ - "plugins/ignore-?.zsh"\ \ \ \ \ - "!plugins/ignore-2.zsh" -' ${cfg} > ${cfg2} +' "${cfg}" > "${cfg2}" # expects one diff patt0="plugins/ignore-?.zsh" patt1="!plugins/ignore-2.zsh" echo "[+] comparing with ignore (patterns: ${patt0} and ${patt1}) - 1 diff" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -C ${tmpd}/.zsh --ignore=${patt0} --ignore=${patt1} +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose -C "${tmpd}"/.zsh --ignore="${patt0}" --ignore=${patt1} [ "$?" = "0" ] && exit 1 set -e # expects one diff echo "[+] comparing .zsh with ignore in dotfile - 1 diff expected" set +e -cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose -C ${tmpd}/.zsh +cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose -C "${tmpd}"/.zsh ret="$?" echo ${ret} [ "${ret}" = "0" ] && exit 1 diff --git a/tests-ng/compare-negative-ignore.sh b/tests-ng/compare-negative-ignore.sh index 2b79f7b..4ee3955 100755 --- a/tests-ng/compare-negative-ignore.sh +++ b/tests-ng/compare-negative-ignore.sh @@ -9,41 +9,12 @@ #set -e # all this crap to get current path -if [ $(uname) = Darwin ]; then - # Unfortunately, readlink works differently on macOS than it does on GNU/Linux - # (the -f option behaves differently) and the realpath command does not exist. - # Workarounds I find on the Internet suggest just using Homebrew to install coreutils - # so you can get the GNU coreutils on your Mac. But, I don't want this script to - # assume (a) users have Homebrew installed and (b) if they have Homebrew installed, that - # they then installed the GNU coreutils. - readlink() { - TARGET_FILE=$1 +rl="readlink -f" +if ! ${rl} "${0}" >/dev/null 2>&1; then + rl="realpath" - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - - # Iterate down a (possible) chain of symlinks - while [ -L "$TARGET_FILE" ]; do - TARGET_FILE=`readlink $TARGET_FILE` - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - done - - # Compute the canonicalized name by finding the physical path - # for the directory we're in and appending the target file. - PHYS_DIR=`pwd -P` - RESULT=$PHYS_DIR/$TARGET_FILE - echo $RESULT - } - rl="readlink" -else - rl="readlink -f" - if ! ${rl} "${0}" >/dev/null 2>&1; then - rl="realpath" - - if ! hash ${rl}; then - echo "\"${rl}\" not found !" && exit 1 - fi + if ! hash ${rl}; then + echo "\"${rl}\" not found !" && exit 1 fi fi cur=$(dirname "$(${rl} "${0}")") @@ -51,7 +22,7 @@ cur=$(dirname "$(${rl} "${0}")") # dotdrop path can be pass as argument ddpath="${cur}/../" [ -n "${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" @@ -60,47 +31,48 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" # the dotfile to be imported -tmpd=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # some files -mkdir -p ${tmpd}/program/ignore_me -echo "some data" > ${tmpd}/program/a -echo "some data" > ${tmpd}/program/ignore_me/b -echo "some data" > ${tmpd}/program/ignore_me/c +mkdir -p "${tmpd}"/program/ignore_me +echo "some data" > "${tmpd}"/program/a +echo "some data" > "${tmpd}"/program/ignore_me/b +echo "some data" > "${tmpd}"/program/ignore_me/c # create the config file cfg="${basedir}/config.yaml" -create_conf ${cfg} # sets token +create_conf "${cfg}" # sets token # import echo "[+] import" -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/program +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/program # make some changes to generate a diff -echo "some other data" > ${tmpd}/program/a -echo "some other data" > ${tmpd}/program/ignore_me/b -echo "some other data" > ${tmpd}/program/ignore_me/c +echo "some other data" > "${tmpd}"/program/a +echo "some other data" > "${tmpd}"/program/ignore_me/b +echo "some other data" > "${tmpd}"/program/ignore_me/c echo "[+] comparing normal - 3 diffs" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose [ "$?" = 0 ] && exit 1 # We don't want an exit status of 0 set -e @@ -109,22 +81,23 @@ patt0="*/ignore_me/*" patt1="!*/ignore_me/c" echo "[+] comparing with ignore (patterns: ${patt0} and ${patt1}) - 2 diffs" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose --ignore=${patt0} --ignore=${patt1} +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose --ignore="${patt0}" --ignore="${patt1}" [ "$?" = "0" ] && exit 1 set -e # Adding ignore in dotfile cfg2="${basedir}/config2.yaml" +# shellcheck disable=SC1004 sed '/d_program:/a\ \ \ \ \ cmpignore:\ \ \ \ \ - "*/ignore_me/*"\ \ \ \ \ - "!*/ignore_me/c" -' ${cfg} > ${cfg2} +' "${cfg}" > "${cfg2}" # still expects two diffs echo "[+] comparing with ignore in dotfile - 2 diffs" set +e -cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose +cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose [ "$?" = "0" ] && exit 1 set -e diff --git a/tests-ng/compare-profile-check.sh b/tests-ng/compare-profile-check.sh index b71f043..c8c33f2 100755 --- a/tests-ng/compare-profile-check.sh +++ b/tests-ng/compare-profile-check.sh @@ -23,19 +23,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 @@ -43,25 +46,25 @@ echo -e "$(tput setaf 6)==> RUNNING $(basename $BASH_SOURCE) <==$(tput sgr0)" # dotdrop directory -tmps=`mktemp -d --suffix='-dotdrop-tests-source' || mktemp -d` +tmps=$(mktemp -d --suffix='-dotdrop-tests-source' || mktemp -d) dt="${tmps}/dotfiles" -mkdir -p ${dt} +mkdir -p "${dt}" xori="profile x" xori="profile y" -echo "${xori}" > ${dt}/file_x -echo "${yori}" > ${dt}/file_y +echo "${xori}" > "${dt}"/file_x +echo "${yori}" > "${dt}"/file_y # fs dotfiles -tmpd=`mktemp -d --suffix='-dotdrop-tests-dest' || mktemp -d` -touch ${tmpd}/file +tmpd=$(mktemp -d --suffix='-dotdrop-tests-dest' || mktemp -d) +touch "${tmpd}"/file clear_on_exit "${tmps}" clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: false create: true @@ -81,65 +84,65 @@ profiles: dotfiles: - f_file_y _EOF -cat ${cfg} +cat "${cfg}" # reset -echo "${xori}" > ${dt}/file_x -echo "${yori}" > ${dt}/file_y +echo "${xori}" > "${dt}"/file_x +echo "${yori}" > "${dt}"/file_y echo "test compare profile x (ok)" -echo "${xori}" > ${tmpd}/file +echo "${xori}" > "${tmpd}"/file set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -p x -C ${tmpd}/file +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose -p x -C "${tmpd}"/file [ "$?" != "0" ] && exit 1 set -e echo "test compare profile x (not ok)" -echo "${yori}" > ${tmpd}/file +echo "${yori}" > "${tmpd}"/file set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -p x -C ${tmpd}/file +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose -p x -C "${tmpd}"/file [ "$?" = "0" ] && exit 1 set -e echo "test compare profile y (ok)" -echo "${yori}" > ${tmpd}/file +echo "${yori}" > "${tmpd}"/file set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -p y -C ${tmpd}/file +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose -p y -C "${tmpd}"/file [ "$?" != "0" ] && exit 1 set -e echo "test compare profile y (not ok)" -echo "${xori}" > ${tmpd}/file +echo "${xori}" > "${tmpd}"/file set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -p y -C ${tmpd}/file +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose -p y -C "${tmpd}"/file [ "$?" = "0" ] && exit 1 set -e echo "test compare profile x generic (ok)" -echo "${xori}" > ${tmpd}/file +echo "${xori}" > "${tmpd}"/file set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -p x +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose -p x [ "$?" != "0" ] && exit 1 set -e echo "test compare profile x generic (not ok)" -echo "${yori}" > ${tmpd}/file +echo "${yori}" > "${tmpd}"/file set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -p x +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose -p x [ "$?" = "0" ] && exit 1 set -e echo "test compare profile y generic (ok)" -echo "${yori}" > ${tmpd}/file +echo "${yori}" > "${tmpd}"/file set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -p y +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose -p y [ "$?" != "0" ] && exit 1 set -e echo "test compare profile y generic (not ok)" -echo "${xori}" > ${tmpd}/file +echo "${xori}" > "${tmpd}"/file set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -p y +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose -p y [ "$?" = "0" ] && exit 1 set -e diff --git a/tests-ng/compare.sh b/tests-ng/compare.sh index 0fdd0a5..7a825f4 100755 --- a/tests-ng/compare.sh +++ b/tests-ng/compare.sh @@ -28,99 +28,102 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" # the dotfile to be imported -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # single file -echo 'unique' > ${tmpd}/uniquefile +echo 'unique' > "${tmpd}"/uniquefile # hierarchy from https://pymotw.com/2/filecmp/ # create the hierarchy # for dir1 (originally imported directory)))) -mkdir ${tmpd}/dir1 -touch ${tmpd}/dir1/file_only_in_dir1 -mkdir -p ${tmpd}/dir1/dir_only_in_dir1 -mkdir -p ${tmpd}/dir1/common_dir -echo 'this file is the same' > ${tmpd}/dir1/common_file -echo 'in dir1' > ${tmpd}/dir1/not_the_same -echo 'This is a file in dir1' > ${tmpd}/dir1/file_in_dir1 -mkdir -p ${tmpd}/dir1/sub/sub2 -mkdir -p ${tmpd}/dir1/notindir2/notindir2 -echo 'first' > ${tmpd}/dir1/sub/sub2/different +mkdir "${tmpd}"/dir1 +touch "${tmpd}"/dir1/file_only_in_dir1 +mkdir -p "${tmpd}"/dir1/dir_only_in_dir1 +mkdir -p "${tmpd}"/dir1/common_dir +echo 'this file is the same' > "${tmpd}"/dir1/common_file +echo 'in dir1' > "${tmpd}"/dir1/not_the_same +echo 'This is a file in dir1' > "${tmpd}"/dir1/file_in_dir1 +mkdir -p "${tmpd}"/dir1/sub/sub2 +mkdir -p "${tmpd}"/dir1/notindir2/notindir2 +echo 'first' > "${tmpd}"/dir1/sub/sub2/different #tree ${tmpd}/dir1 # create the hierarchy # for dir2 (modified original for update) -mkdir ${tmpd}/dir2 -touch ${tmpd}/dir2/file_only_in_dir2 -mkdir -p ${tmpd}/dir2/dir_only_in_dir2 -mkdir -p ${tmpd}/dir2/common_dir -echo 'this file is the same' > ${tmpd}/dir2/common_file -echo 'in dir2' > ${tmpd}/dir2/not_the_same -mkdir -p ${tmpd}/dir2/file_in_dir1 -mkdir -p ${tmpd}/dir2/sub/sub2 -echo 'modified' > ${tmpd}/dir2/sub/sub2/different -mkdir -p ${tmpd}/dir2/new/new2 +mkdir "${tmpd}"/dir2 +touch "${tmpd}"/dir2/file_only_in_dir2 +mkdir -p "${tmpd}"/dir2/dir_only_in_dir2 +mkdir -p "${tmpd}"/dir2/common_dir +echo 'this file is the same' > "${tmpd}"/dir2/common_file +echo 'in dir2' > "${tmpd}"/dir2/not_the_same +mkdir -p "${tmpd}"/dir2/file_in_dir1 +mkdir -p "${tmpd}"/dir2/sub/sub2 +echo 'modified' > "${tmpd}"/dir2/sub/sub2/different +mkdir -p "${tmpd}"/dir2/new/new2 #tree ${tmpd}/dir2 # create the config file cfg="${basedir}/config.yaml" -create_conf ${cfg} # sets token +create_conf "${cfg}" # sets token # import dir1 echo "[+] import" -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/dir1 -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/uniquefile -cat ${cfg} +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/dir1 +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/uniquefile +cat "${cfg}" # let's see the dotpath #tree ${basedir}/dotfiles # change dir1 to dir2 in deployed echo "[+] change dir" -rm -rf ${tmpd}/dir1 -mv ${tmpd}/dir2 ${tmpd}/dir1 +rm -rf "${tmpd}"/dir1 +mv "${tmpd}"/dir2 "${tmpd}"/dir1 #tree ${tmpd}/dir1 # change unique file -echo 'changed' > ${tmpd}/uniquefile +echo 'changed' > "${tmpd}"/uniquefile # compare echo "[+] comparing" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} --verbose +cd "${ddpath}" | ${bin} compare -c "${cfg}" --verbose [ "$?" = "0" ] && exit 1 set -e echo "[+] comparing with file-only" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} -L +cd "${ddpath}" | ${bin} compare -c "${cfg}" -L [ "$?" = "0" ] && exit 1 set -e diff --git a/tests-ng/corner-case.sh b/tests-ng/corner-case.sh index b74ab22..ede959b 100755 --- a/tests-ng/corner-case.sh +++ b/tests-ng/corner-case.sh @@ -33,26 +33,29 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" @@ -62,7 +65,7 @@ export DOTDROP_WORKERS=1 # create the config file cfg="${basedir}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -83,24 +86,24 @@ profiles: _EOF echo "[+] test install dry" -cd ${ddpath} | ${bin} install -c ${cfg} --dry -p p1 --verbose f_x +cd "${ddpath}" | ${bin} install -c "${cfg}" --dry -p p1 --verbose f_x [ "$?" != "0" ] && exit 1 echo "[+] test install show-diff" -cd ${ddpath} | ${bin} install -c ${cfg} -p p1 --verbose f_x +cd "${ddpath}" | ${bin} install -c "${cfg}" -p p1 --verbose f_x [ "$?" != "0" ] && exit 1 -cd ${ddpath} | ${bin} install -D -c ${cfg} -p p1 --verbose f_x +cd "${ddpath}" | ${bin} install -D -c "${cfg}" -p p1 --verbose f_x [ "$?" != "0" ] && exit 1 echo "[+] test install not existing src" -cd ${ddpath} | ${bin} install -c ${cfg} -f --dry -p p1 --verbose f_y +cd "${ddpath}" | ${bin} install -c "${cfg}" -f --dry -p p1 --verbose f_y echo "[+] test install to temp" -cd ${ddpath} | ${bin} install -t -c ${cfg} -p p1 --verbose f_x > ${basedir}/log 2>&1 +cd "${ddpath}" | ${bin} install -t -c "${cfg}" -p p1 --verbose f_x > "${basedir}"/log 2>&1 [ "$?" != "0" ] && echo "install to tmp failed" && exit 1 # cleaning -tmpfile=`cat ${basedir}/log | grep 'installed to tmp ' | sed 's/^.*to tmp "\(.*\)"./\1/'` +tmpfile=$(cat "${basedir}"/log | grep 'installed to tmp ' | sed 's/^.*to tmp "\(.*\)"./\1/') echo "tmpfile: ${tmpfile}" rm -rf "${tmpfile}" diff --git a/tests-ng/deprecated-link.sh b/tests-ng/deprecated-link.sh index edf67e2..74d8ebc 100755 --- a/tests-ng/deprecated-link.sh +++ b/tests-ng/deprecated-link.sh @@ -28,29 +28,32 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -58,7 +61,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: false create: true @@ -103,38 +106,38 @@ profiles: - f_children2 - f_children3 _EOF -cat ${cfg} +cat "${cfg}" # create the dotfiles -echo "test" > ${tmps}/dotfiles/abc -echo "test" > ${tmpd}/abc +echo "test" > "${tmps}"/dotfiles/abc +echo "test" > "${tmpd}"/abc # compare -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 # install #cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V -cat ${cfg} +cat "${cfg}" # fail if find some of these entries echo "========> test for bad entries" set +e -grep 'link_children: true' ${cfg} >/dev/null && exit 1 -grep 'link_children: false' ${cfg} >/dev/null && exit 1 -grep 'link: true' ${cfg} >/dev/null && exit 1 -grep 'link: false' ${cfg} >/dev/null && exit 1 -grep 'link_by_default: true' ${cfg} >/dev/null && exit 1 -grep 'link_by_default: false' ${cfg} >/dev/null && exit 1 +grep 'link_children: true' "${cfg}" >/dev/null && exit 1 +grep 'link_children: false' "${cfg}" >/dev/null && exit 1 +grep 'link: true' "${cfg}" >/dev/null && exit 1 +grep 'link: false' "${cfg}" >/dev/null && exit 1 +grep 'link_by_default: true' "${cfg}" >/dev/null && exit 1 +grep 'link_by_default: false' "${cfg}" >/dev/null && exit 1 set -e # test values have been correctly updated echo "========> test for updated entries" -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_link' | head -1 | grep ',link:absolute,' -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_nolink' | head -1 | grep ',link:nolink,' -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_nolink1' | head -1 | grep ',link:nolink,' -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_children' | head -1 | grep ',link:link_children,' -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_children2' | head -1 | grep ',link:link_children,' -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_children3' | head -1 | grep ',link:nolink,' +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -G | grep '^f_link' | head -1 | grep ',link:absolute,' +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -G | grep '^f_nolink' | head -1 | grep ',link:nolink,' +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -G | grep '^f_nolink1' | head -1 | grep ',link:nolink,' +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -G | grep '^f_children' | head -1 | grep ',link:link_children,' +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -G | grep '^f_children2' | head -1 | grep ',link:link_children,' +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -G | grep '^f_children3' | head -1 | grep ',link:nolink,' echo "OK" exit 0 diff --git a/tests-ng/diff-cmd.sh b/tests-ng/diff-cmd.sh index 604d9f9..0ad99a9 100755 --- a/tests-ng/diff-cmd.sh +++ b/tests-ng/diff-cmd.sh @@ -28,41 +28,44 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" # the dotfile to be imported -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # some files -echo "original" > ${tmpd}/singlefile +echo "original" > "${tmpd}"/singlefile # create the config file cfg="${basedir}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -73,52 +76,52 @@ _EOF # import echo "[+] import" -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/singlefile +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/singlefile # modify the file -echo "modified" > ${tmpd}/singlefile +echo "modified" > "${tmpd}"/singlefile # default diff (unified) echo "[+] comparing with default diff (unified)" set +e -cd ${ddpath} | ${bin} compare -b -c ${cfg} 2>/dev/null | grep -v '=>' | grep -v '\->' | grep -v 'dotfile(s) compared' | sed '$d' | grep -v '^+++\|^---' > ${tmpd}/normal -diff -u -r ${tmpd}/singlefile ${basedir}/dotfiles/${tmpd}/singlefile | grep -v '^+++\|^---' > ${tmpd}/real +cd "${ddpath}" | ${bin} compare -b -c "${cfg}" 2>/dev/null | grep -v '=>' | grep -v '\->' | grep -v 'dotfile(s) compared' | sed '$d' | grep -v '^+++\|^---' > "${tmpd}"/normal +diff -u -r "${tmpd}"/singlefile "${basedir}"/dotfiles/"${tmpd}"/singlefile | grep -v '^+++\|^---' > "${tmpd}"/real set -e # verify -diff ${tmpd}/normal ${tmpd}/real || exit 1 +diff "${tmpd}"/normal "${tmpd}"/real || exit 1 # adding normal diff cfg2="${basedir}/config2.yaml" -sed '/dotpath: dotfiles/a \ \ diff_command: "diff -r {0} {1}"' ${cfg} > ${cfg2} +sed '/dotpath: dotfiles/a \ \ diff_command: "diff -r {0} {1}"' "${cfg}" > "${cfg2}" #cat ${cfg2} # normal diff echo "[+] comparing with normal diff" set +e -cd ${ddpath} | ${bin} compare -b -c ${cfg2} 2>/dev/null | grep -v '=>' | grep -v '\->' | grep -v 'dotfile(s) compared' | sed '$d' > ${tmpd}/unified -diff -r ${tmpd}/singlefile ${basedir}/dotfiles/${tmpd}/singlefile > ${tmpd}/real +cd "${ddpath}" | ${bin} compare -b -c "${cfg2}" 2>/dev/null | grep -v '=>' | grep -v '\->' | grep -v 'dotfile(s) compared' | sed '$d' > "${tmpd}"/unified +diff -r "${tmpd}"/singlefile "${basedir}"/dotfiles/"${tmpd}"/singlefile > "${tmpd}"/real set -e # verify #cat ${tmpd}/unified #cat ${tmpd}/real -diff ${tmpd}/unified ${tmpd}/real || exit 1 +diff "${tmpd}"/unified "${tmpd}"/real || exit 1 # adding fake diff cfg3="${basedir}/config3.yaml" -sed '/dotpath: dotfiles/a \ \ diff_command: "echo fakediff"' ${cfg} > ${cfg3} +sed '/dotpath: dotfiles/a \ \ diff_command: "echo fakediff"' "${cfg}" > "${cfg3}" #cat ${cfg3} # fake diff echo "[+] comparing with fake diff" set +e -cd ${ddpath} | ${bin} compare -b -c ${cfg3} 2>/dev/null | grep -v '=>' | grep -v '\->' | grep -v 'dotfile(s) compared' | sed '$d' > ${tmpd}/fake +cd "${ddpath}" | ${bin} compare -b -c "${cfg3}" 2>/dev/null | grep -v '=>' | grep -v '\->' | grep -v 'dotfile(s) compared' | sed '$d' > "${tmpd}"/fake set -e # verify #cat ${tmpd}/fake -grep fakediff ${tmpd}/fake &> /dev/null || exit 1 +grep fakediff "${tmpd}"/fake &> /dev/null || exit 1 echo "OK" exit 0 diff --git a/tests-ng/dir-import-update.sh b/tests-ng/dir-import-update.sh index 39c7908..c35f7de 100755 --- a/tests-ng/dir-import-update.sh +++ b/tests-ng/dir-import-update.sh @@ -28,49 +28,52 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) dotfiles="${basedir}/dotfiles" echo "dotdrop dir: ${basedir}" # the dotfile -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` -create_dir ${tmpd} +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +create_dir "${tmpd}" clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # create the config file cfg="${basedir}/config.yaml" -create_conf ${cfg} # sets token +create_conf "${cfg}" # sets token # import the dir -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd} +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}" # change token -echo "changed" > ${token} +echo "changed" > "${token}" # update -cd ${ddpath} | ${bin} update -f -c ${cfg} ${tmpd} --verbose +cd "${ddpath}" | ${bin} update -f -c "${cfg}" "${tmpd}" --verbose -grep 'changed' ${token} >/dev/null 2>&1 +grep 'changed' "${token}" >/dev/null 2>&1 echo "OK" exit 0 diff --git a/tests-ng/dotdrop-variables.sh b/tests-ng/dotdrop-variables.sh index 2561747..6d9f3e4 100755 --- a/tests-ng/dotdrop-variables.sh +++ b/tests-ng/dotdrop-variables.sh @@ -28,30 +28,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 +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmps}"/dotfiles #echo "dotfile source: ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) #echo "dotfile destination: ${tmpd}" clear_on_exit "${tmps}" @@ -60,7 +63,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -78,18 +81,18 @@ _EOF #cat ${cfg} # create the dotfile -echo "dotpath: {{@@ _dotdrop_dotpath @@}}" > ${tmps}/dotfiles/abc -echo "cfgpath: {{@@ _dotdrop_cfgpath @@}}" >> ${tmps}/dotfiles/abc -echo "workdir: {{@@ _dotdrop_workdir @@}}" >> ${tmps}/dotfiles/abc +echo "dotpath: {{@@ _dotdrop_dotpath @@}}" > "${tmps}"/dotfiles/abc +echo "cfgpath: {{@@ _dotdrop_cfgpath @@}}" >> "${tmps}"/dotfiles/abc +echo "workdir: {{@@ _dotdrop_workdir @@}}" >> "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V -cat ${tmpd}/abc +cat "${tmpd}"/abc -grep "^dotpath: ${tmps}/dotfiles$" ${tmpd}/abc >/dev/null -grep "^cfgpath: ${tmps}/config.yaml$" ${tmpd}/abc >/dev/null -grep "^workdir: /tmp/xxx$" ${tmpd}/abc >/dev/null +grep "^dotpath: ${tmps}/dotfiles$" "${tmpd}"/abc >/dev/null +grep "^cfgpath: ${tmps}/config.yaml$" "${tmpd}"/abc >/dev/null +grep "^workdir: /tmp/xxx$" "${tmpd}"/abc >/dev/null echo "OK" exit 0 diff --git a/tests-ng/dotfile-no-src.sh b/tests-ng/dotfile-no-src.sh index fea77de..63bc47e 100755 --- a/tests-ng/dotfile-no-src.sh +++ b/tests-ng/dotfile-no-src.sh @@ -29,30 +29,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 +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmps}"/dotfiles echo "dotfiles source (dotpath): ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" clear_on_exit "${tmps}" @@ -61,7 +64,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -77,19 +80,19 @@ _EOF #cat ${cfg} # create the dotfiles -echo "abc" > ${tmps}/dotfiles/abc +echo "abc" > "${tmps}"/dotfiles/abc ########################### # test install and compare ########################### # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V [ "$?" != "0" ] && exit 1 # checks -[ ! -e ${tmpd}/abc ] && exit 1 -grep 'abc' ${tmpd}/abc +[ ! -e "${tmpd}"/abc ] && exit 1 +grep 'abc' "${tmpd}"/abc echo "OK" exit 0 diff --git a/tests-ng/dotfile-sub-variables.sh b/tests-ng/dotfile-sub-variables.sh index d223772..27ee428 100755 --- a/tests-ng/dotfile-sub-variables.sh +++ b/tests-ng/dotfile-sub-variables.sh @@ -28,29 +28,32 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -58,7 +61,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -75,32 +78,32 @@ _EOF #cat ${cfg} # create the dotfile -mkdir -p ${tmps}/dotfiles/abc +mkdir -p "${tmps}"/dotfiles/abc # file1 -echo 'src:{{@@ _dotfile_sub_abs_src @@}}' > ${tmps}/dotfiles/abc/file1 -echo 'dst:{{@@ _dotfile_sub_abs_dst @@}}' >> ${tmps}/dotfiles/abc/file1 +echo 'src:{{@@ _dotfile_sub_abs_src @@}}' > "${tmps}"/dotfiles/abc/file1 +echo 'dst:{{@@ _dotfile_sub_abs_dst @@}}' >> "${tmps}"/dotfiles/abc/file1 # file2 -mkdir -p ${tmps}/dotfiles/abc/subdir -echo 'src:{{@@ _dotfile_sub_abs_src @@}}' > ${tmps}/dotfiles/abc/subdir/file2 -echo 'dst:{{@@ _dotfile_sub_abs_dst @@}}' >> ${tmps}/dotfiles/abc/subdir/file2 +mkdir -p "${tmps}"/dotfiles/abc/subdir +echo 'src:{{@@ _dotfile_sub_abs_src @@}}' > "${tmps}"/dotfiles/abc/subdir/file2 +echo 'dst:{{@@ _dotfile_sub_abs_dst @@}}' >> "${tmps}"/dotfiles/abc/subdir/file2 # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V # checks -[ ! -d ${tmpd}/abc ] && echo 'dotfile not installed' && exit 1 -[ ! -e ${tmpd}/abc/file1 ] && echo 'dotfile sub src not installed' && exit 1 -[ ! -e ${tmpd}/abc/subdir/file2 ] && echo 'dotfile sub dst not installed' && exit 1 +[ ! -d "${tmpd}"/abc ] && echo 'dotfile not installed' && exit 1 +[ ! -e "${tmpd}"/abc/file1 ] && echo 'dotfile sub src not installed' && exit 1 +[ ! -e "${tmpd}"/abc/subdir/file2 ] && echo 'dotfile sub dst not installed' && exit 1 -cat ${tmpd}/abc/file1 -cat ${tmpd}/abc/subdir/file2 +cat "${tmpd}"/abc/file1 +cat "${tmpd}"/abc/subdir/file2 -grep "src:${tmps}/dotfiles/abc/file1" ${tmpd}/abc/file1 >/dev/null -grep "dst:${tmpd}/abc/file1" ${tmpd}/abc/file1>/dev/null +grep "src:${tmps}/dotfiles/abc/file1" "${tmpd}"/abc/file1 >/dev/null +grep "dst:${tmpd}/abc/file1" "${tmpd}"/abc/file1>/dev/null -grep "src:${tmps}/dotfiles/abc/subdir/file2" ${tmpd}/abc/subdir/file2 >/dev/null -grep "dst:${tmpd}/abc/subdir/file2" ${tmpd}/abc/subdir/file2 >/dev/null +grep "src:${tmps}/dotfiles/abc/subdir/file2" "${tmpd}"/abc/subdir/file2 >/dev/null +grep "dst:${tmpd}/abc/subdir/file2" "${tmpd}"/abc/subdir/file2 >/dev/null echo "OK" exit 0 diff --git a/tests-ng/dotfile-variables.sh b/tests-ng/dotfile-variables.sh index f96f215..125798c 100755 --- a/tests-ng/dotfile-variables.sh +++ b/tests-ng/dotfile-variables.sh @@ -28,29 +28,32 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -58,7 +61,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -75,21 +78,21 @@ _EOF #cat ${cfg} # create the dotfile -echo 'src:{{@@ _dotfile_abs_src @@}}' > ${tmps}/dotfiles/abc -echo 'dst:{{@@ _dotfile_abs_dst @@}}' >> ${tmps}/dotfiles/abc -echo 'key:{{@@ _dotfile_key @@}}' >> ${tmps}/dotfiles/abc -echo 'link:{{@@ _dotfile_link @@}}' >> ${tmps}/dotfiles/abc +echo 'src:{{@@ _dotfile_abs_src @@}}' > "${tmps}"/dotfiles/abc +echo 'dst:{{@@ _dotfile_abs_dst @@}}' >> "${tmps}"/dotfiles/abc +echo 'key:{{@@ _dotfile_key @@}}' >> "${tmps}"/dotfiles/abc +echo 'link:{{@@ _dotfile_link @@}}' >> "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V # checks -[ ! -e ${tmpd}/abc ] && echo 'dotfile not installed' && exit 1 -cat ${tmpd}/abc -grep "src:${tmps}/dotfiles/abc" ${tmpd}/abc >/dev/null -grep "dst:${tmpd}/abc" ${tmpd}/abc >/dev/null -grep "key:f_abc" ${tmpd}/abc >/dev/null -grep "link:nolink" ${tmpd}/abc >/dev/null +[ ! -e "${tmpd}"/abc ] && echo 'dotfile not installed' && exit 1 +cat "${tmpd}"/abc +grep "src:${tmps}/dotfiles/abc" "${tmpd}"/abc >/dev/null +grep "dst:${tmpd}/abc" "${tmpd}"/abc >/dev/null +grep "key:f_abc" "${tmpd}"/abc >/dev/null +grep "link:nolink" "${tmpd}"/abc >/dev/null echo "OK" exit 0 diff --git a/tests-ng/dotfiles-all.sh b/tests-ng/dotfiles-all.sh index 72c42e2..238b3fe 100755 --- a/tests-ng/dotfiles-all.sh +++ b/tests-ng/dotfiles-all.sh @@ -29,30 +29,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 +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmps}"/dotfiles echo "dotfiles source (dotpath): ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" clear_on_exit "${tmps}" @@ -61,7 +64,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -84,31 +87,31 @@ _EOF #cat ${cfg} # create the dotfiles -echo "abc" > ${tmps}/dotfiles/abc -echo "def" > ${tmps}/dotfiles/def -echo "ghi" > ${tmps}/dotfiles/ghi +echo "abc" > "${tmps}"/dotfiles/abc +echo "def" > "${tmps}"/dotfiles/def +echo "ghi" > "${tmps}"/dotfiles/ghi ########################### # test install and compare ########################### # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V [ "$?" != "0" ] && exit 1 # checks -[ ! -e ${tmpd}/abc ] && exit 1 -[ ! -e ${tmpd}/def ] && exit 1 -[ ! -e ${tmpd}/ghi ] && exit 1 +[ ! -e "${tmpd}"/abc ] && exit 1 +[ ! -e "${tmpd}"/def ] && exit 1 +[ ! -e "${tmpd}"/ghi ] && exit 1 # modify the dotfiles -echo "abc-modified" > ${tmps}/dotfiles/abc -echo "def-modified" > ${tmps}/dotfiles/def -echo "ghi-modified" > ${tmps}/dotfiles/ghi +echo "abc-modified" > "${tmps}"/dotfiles/abc +echo "def-modified" > "${tmps}"/dotfiles/def +echo "ghi-modified" > "${tmps}"/dotfiles/ghi # compare set +e -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 -b -V ret="$?" set -e [ "$ret" = "0" ] && exit 1 diff --git a/tests-ng/dotfiles-dyn-paths.sh b/tests-ng/dotfiles-dyn-paths.sh index d91c1e2..cd7a551 100755 --- a/tests-ng/dotfiles-dyn-paths.sh +++ b/tests-ng/dotfiles-dyn-paths.sh @@ -29,30 +29,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 +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmps}"/dotfiles echo "dotfiles source (dotpath): ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" clear_on_exit "${tmps}" @@ -61,7 +64,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -82,18 +85,18 @@ _EOF #cat ${cfg} # create the dotfiles -echo "abc" > ${tmps}/dotfiles/abc +echo "abc" > "${tmps}"/dotfiles/abc ########################### # test install and compare ########################### # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V [ "$?" != "0" ] && exit 1 # checks -[ ! -e ${tmpd}/abc ] && exit 1 +[ ! -e "${tmpd}"/abc ] && exit 1 echo "OK" exit 0 diff --git a/tests-ng/double-config-import.sh b/tests-ng/double-config-import.sh index 7987351..650a814 100755 --- a/tests-ng/double-config-import.sh +++ b/tests-ng/double-config-import.sh @@ -27,19 +27,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 @@ -57,7 +60,7 @@ error_log="${dst}/error.log" # bottom-level bottom_level_cfg="${src}/bottom-level.yaml" -cat > ${bottom_level_cfg} << _EOF +cat > "${bottom_level_cfg}" << _EOF config: backup: true create: true @@ -70,7 +73,7 @@ touch "${src}/dotfiles/bottom" # mid-level mid_level_cfg="${src}/mid-level.yaml" -cat > ${mid_level_cfg} << _EOF +cat > "${mid_level_cfg}" << _EOF config: backup: true create: true @@ -85,7 +88,7 @@ _EOF # top-level top_level_cfg="${src}/top-level.yaml" -cat > ${top_level_cfg} << _EOF +cat > "${top_level_cfg}" << _EOF config: backup: true create: true @@ -101,7 +104,7 @@ _EOF # install set +e -cd ${ddpath} | ${bin} install -f -c ${top_level_cfg} -p top-level 2> "${error_log}" +cd "${ddpath}" | ${bin} install -f -c "${top_level_cfg}" -p top-level 2> "${error_log}" set -e # checks diff --git a/tests-ng/dry.sh b/tests-ng/dry.sh index 1ae188d..e794590 100755 --- a/tests-ng/dry.sh +++ b/tests-ng/dry.sh @@ -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 diff --git a/tests-ng/duplicate-key.sh b/tests-ng/duplicate-key.sh index f40f798..dede032 100755 --- a/tests-ng/duplicate-key.sh +++ b/tests-ng/duplicate-key.sh @@ -28,29 +28,32 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -58,7 +61,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -75,30 +78,30 @@ _EOF #cat ${cfg} # create the imported one -mkdir -p ${tmps}/dotfiles/${tmpd} -echo "test" > ${tmps}/dotfiles/${tmpd}/abc -echo "test" > ${tmpd}/abc +mkdir -p "${tmps}"/dotfiles/"${tmpd}" +echo "test" > "${tmps}"/dotfiles/"${tmpd}"/abc +echo "test" > "${tmpd}"/abc # create the to-be-imported -mkdir -p ${tmpd}/sub -echo "test2" > ${tmpd}/sub/abc +mkdir -p "${tmpd}"/sub +echo "test2" > "${tmpd}"/sub/abc -mkdir -p ${tmpd}/sub/sub2 -echo "test2" > ${tmpd}/sub/sub2/abc +mkdir -p "${tmpd}"/sub/sub2 +echo "test2" > "${tmpd}"/sub/sub2/abc -mkdir -p ${tmpd}/sub/sub -echo "test2" > ${tmpd}/sub/sub/abc +mkdir -p "${tmpd}"/sub/sub +echo "test2" > "${tmpd}"/sub/sub/abc # import -cd ${ddpath} | ${bin} import -f --verbose -c ${cfg} -p p2 \ - ${tmpd}/abc \ - ${tmpd}/sub/abc \ - ${tmpd}/sub/abc \ - ${tmpd}/sub/sub/abc \ - ${tmpd}/sub/sub2/abc +cd "${ddpath}" | ${bin} import -f --verbose -c "${cfg}" -p p2 \ + "${tmpd}"/abc \ + "${tmpd}"/sub/abc \ + "${tmpd}"/sub/abc \ + "${tmpd}"/sub/sub/abc \ + "${tmpd}"/sub/sub2/abc # count dotfiles for p2 -cnt=`cd ${ddpath} | ${bin} files --verbose -c ${cfg} -p p2 -b | grep '^f_' | wc -l` +cnt=$(cd "${ddpath}" | ${bin} files --verbose -c "${cfg}" -p p2 -b | grep '^f_' | wc -l) [ "${cnt}" != "4" ] && echo "bad count for p2: ${cnt} != 4" && exit 1 echo "OK" diff --git a/tests-ng/dynactions.sh b/tests-ng/dynactions.sh index a9f50fa..973a27d 100755 --- a/tests-ng/dynactions.sh +++ b/tests-ng/dynactions.sh @@ -28,31 +28,34 @@ 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 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}" @@ -61,7 +64,7 @@ clear_on_exit "${tmpa}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF variables: var1: "var1" var2: "{{@@ var1 @@}} var2" @@ -104,25 +107,25 @@ _EOF #cat ${cfg} # create the dotfile -echo "test" > ${tmps}/dotfiles/abc +echo "test" > "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 --verbose +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 --verbose # checks -[ ! -e ${tmpa}/preaction1 ] && exit 1 -[ ! -e ${tmpa}/preaction2 ] && exit 1 -[ ! -e ${tmpa}/postaction1 ] && exit 1 -[ ! -e ${tmpa}/postaction2 ] && exit 1 -[ ! -e ${tmpa}/naked1 ] && exit 1 -[ ! -e ${tmpa}/naked2 ] && exit 1 +[ ! -e "${tmpa}"/preaction1 ] && exit 1 +[ ! -e "${tmpa}"/preaction2 ] && exit 1 +[ ! -e "${tmpa}"/postaction1 ] && exit 1 +[ ! -e "${tmpa}"/postaction2 ] && exit 1 +[ ! -e "${tmpa}"/naked1 ] && exit 1 +[ ! -e "${tmpa}"/naked2 ] && exit 1 -grep 'var1 var2 var3' ${tmpa}/preaction1 >/dev/null -grep 'dvar1 dvar2 dvar3' ${tmpa}/preaction2 >/dev/null -grep 'var1 var2 var3' ${tmpa}/postaction1 >/dev/null -grep 'dvar1 dvar2 dvar3' ${tmpa}/postaction2 >/dev/null -grep 'var1 var2 var3' ${tmpa}/naked1 >/dev/null -grep 'dvar1 dvar2 dvar3' ${tmpa}/naked2 >/dev/null +grep 'var1 var2 var3' "${tmpa}"/preaction1 >/dev/null +grep 'dvar1 dvar2 dvar3' "${tmpa}"/preaction2 >/dev/null +grep 'var1 var2 var3' "${tmpa}"/postaction1 >/dev/null +grep 'dvar1 dvar2 dvar3' "${tmpa}"/postaction2 >/dev/null +grep 'var1 var2 var3' "${tmpa}"/naked1 >/dev/null +grep 'dvar1 dvar2 dvar3' "${tmpa}"/naked2 >/dev/null echo "OK" exit 0 diff --git a/tests-ng/dyndotfilepaths.sh b/tests-ng/dyndotfilepaths.sh index 8696d63..db38dab 100755 --- a/tests-ng/dyndotfilepaths.sh +++ b/tests-ng/dyndotfilepaths.sh @@ -28,29 +28,32 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -58,9 +61,9 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -dst=`echo ${tmpd} | rev` +dst=$(echo "${tmpd}" | rev) -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -79,15 +82,15 @@ _EOF #cat ${cfg} # create the dotfile -echo "{{@@ dpath @@}}" > ${tmps}/dotfiles/abc +echo "{{@@ dpath @@}}" > "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V #cat ${tmpd}/abc -[ ! -e ${tmpd}/abc ] && echo "abc not installed dynamically" && exit 1 -grep "^${tmpd}" ${tmpd}/abc >/dev/null +[ ! -e "${tmpd}"/abc ] && echo "abc not installed dynamically" && exit 1 +grep "^${tmpd}" "${tmpd}"/abc >/dev/null #cat ${tmpd}/abc diff --git a/tests-ng/dynextvariables.sh b/tests-ng/dynextvariables.sh index 4b06c3c..4c8846f 100755 --- a/tests-ng/dynextvariables.sh +++ b/tests-ng/dynextvariables.sh @@ -28,29 +28,32 @@ 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}" clear_on_exit "${tmps}" @@ -63,7 +66,7 @@ pvars="${tmps}/p1_vars.yaml" pvarin="${tmps}/inprofile_vars.yaml" pvarout="${tmps}/outprofile_vars.yaml" cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -92,64 +95,64 @@ _EOF #cat ${cfg} # create the external variables file -cat > ${extvars} << _EOF +cat > "${extvars}" << _EOF variables: vara: "extvar1" dynvariables: dvara: "echo extdvar1" _EOF -cat > ${extdvars} << _EOF +cat > "${extdvars}" << _EOF variables: varb: "extvar2" dynvariables: dvarb: "echo extdvar2" _EOF -cat > ${pvars} << _EOF +cat > "${pvars}" << _EOF variables: pvar: "pvar1" dynvariables: pdvar: "echo pdvar1" _EOF -cat > ${pvarin} << _EOF +cat > "${pvarin}" << _EOF variables: test: profileok _EOF -cat > ${pvarout} << _EOF +cat > "${pvarout}" << _EOF variables: test: profilenotok _EOF # create the dotfile -echo "var1: {{@@ var1 @@}}" > ${tmps}/dotfiles/abc -echo "dvar1: {{@@ dvar1 @@}}" >> ${tmps}/dotfiles/abc +echo "var1: {{@@ var1 @@}}" > "${tmps}"/dotfiles/abc +echo "dvar1: {{@@ dvar1 @@}}" >> "${tmps}"/dotfiles/abc # from var file 1 -echo "vara: {{@@ vara @@}}" >> ${tmps}/dotfiles/abc -echo "dvara: {{@@ dvara @@}}" >> ${tmps}/dotfiles/abc +echo "vara: {{@@ vara @@}}" >> "${tmps}"/dotfiles/abc +echo "dvara: {{@@ dvara @@}}" >> "${tmps}"/dotfiles/abc # from var file 2 -echo "varb: {{@@ varb @@}}" >> ${tmps}/dotfiles/abc -echo "dvarb: {{@@ dvarb @@}}" >> ${tmps}/dotfiles/abc +echo "varb: {{@@ varb @@}}" >> "${tmps}"/dotfiles/abc +echo "dvarb: {{@@ dvarb @@}}" >> "${tmps}"/dotfiles/abc # from var file 3 -echo "pvar: {{@@ pvar @@}}" >> ${tmps}/dotfiles/abc -echo "pdvar: {{@@ pdvar @@}}" >> ${tmps}/dotfiles/abc +echo "pvar: {{@@ pvar @@}}" >> "${tmps}"/dotfiles/abc +echo "pdvar: {{@@ pdvar @@}}" >> "${tmps}"/dotfiles/abc # from profile variable -echo "test: {{@@ test @@}}" >> ${tmps}/dotfiles/abc +echo "test: {{@@ test @@}}" >> "${tmps}"/dotfiles/abc #cat ${tmps}/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V -cat ${tmpd}/abc +cat "${tmpd}"/abc -grep '^var1: var' ${tmpd}/abc >/dev/null -grep '^dvar1: dynvar' ${tmpd}/abc >/dev/null -grep '^vara: extvar1' ${tmpd}/abc >/dev/null -grep '^dvara: extdvar1' ${tmpd}/abc >/dev/null -grep '^varb: extvar2' ${tmpd}/abc >/dev/null -grep '^dvarb: extdvar2' ${tmpd}/abc >/dev/null -grep '^pvar: pvar1' ${tmpd}/abc >/dev/null -grep '^pdvar: pdvar1' ${tmpd}/abc >/dev/null -grep '^test: profileok' ${tmpd}/abc >/dev/null +grep '^var1: var' "${tmpd}"/abc >/dev/null +grep '^dvar1: dynvar' "${tmpd}"/abc >/dev/null +grep '^vara: extvar1' "${tmpd}"/abc >/dev/null +grep '^dvara: extdvar1' "${tmpd}"/abc >/dev/null +grep '^varb: extvar2' "${tmpd}"/abc >/dev/null +grep '^dvarb: extdvar2' "${tmpd}"/abc >/dev/null +grep '^pvar: pvar1' "${tmpd}"/abc >/dev/null +grep '^pdvar: pdvar1' "${tmpd}"/abc >/dev/null +grep '^test: profileok' "${tmpd}"/abc >/dev/null echo "OK" exit 0 diff --git a/tests-ng/dyninclude.sh b/tests-ng/dyninclude.sh index 8d147c5..5758f27 100755 --- a/tests-ng/dyninclude.sh +++ b/tests-ng/dyninclude.sh @@ -28,29 +28,32 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -58,7 +61,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF variables: var1: "_1" dynvariables: @@ -92,25 +95,25 @@ _EOF # create the dotfile c1="content:abc" -echo "${c1}" > ${tmps}/dotfiles/abc +echo "${c1}" > "${tmps}"/dotfiles/abc c2="content:def" -echo "${c2}" > ${tmps}/dotfiles/def +echo "${c2}" > "${tmps}"/dotfiles/def # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p profile_3 --verbose +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p profile_3 --verbose # check dotfile exists -[ ! -e ${tmpd}/abc ] && exit 1 +[ ! -e "${tmpd}"/abc ] && exit 1 #cat ${tmpd}/abc -grep ${c1} ${tmpd}/abc >/dev/null || exit 1 +grep ${c1} "${tmpd}"/abc >/dev/null || exit 1 # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p profile_4 --verbose +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p profile_4 --verbose # check dotfile exists -[ ! -e ${tmpd}/def ] && exit 1 +[ ! -e "${tmpd}"/def ] && exit 1 #cat ${tmpd}/def -grep ${c2} ${tmpd}/def >/dev/null || exit 1 +grep ${c2} "${tmpd}"/def >/dev/null || exit 1 echo "OK" exit 0 diff --git a/tests-ng/dynvariables.sh b/tests-ng/dynvariables.sh index dfb5e45..c4ef62c 100755 --- a/tests-ng/dynvariables.sh +++ b/tests-ng/dynvariables.sh @@ -28,29 +28,32 @@ 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}" clear_on_exit "${tmps}" @@ -58,15 +61,15 @@ clear_on_exit "${tmpd}" # create a shell script export TESTENV="this is my testenv" -scr=`mktemp --suffix='-dotdrop-tests' || mktemp -d` -chmod +x ${scr} -echo -e "#!/bin/bash\necho $TESTENV\n" >> ${scr} +scr=$(mktemp --suffix='-dotdrop-tests' || mktemp -d) +chmod +x "${scr}" +echo -e "#!/bin/bash\necho $TESTENV\n" >> "${scr}" clear_on_exit "${scr}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -91,25 +94,25 @@ _EOF #cat ${cfg} # create the dotfile -echo "{{@@ var1 @@}}" > ${tmps}/dotfiles/abc -echo "{{@@ dvar1 @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ dvar2 @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ dvar3 @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ dvar4 @@}}" >> ${tmps}/dotfiles/abc -echo "test" >> ${tmps}/dotfiles/abc +echo "{{@@ var1 @@}}" > "${tmps}"/dotfiles/abc +echo "{{@@ dvar1 @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ dvar2 @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ dvar3 @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ dvar4 @@}}" >> "${tmps}"/dotfiles/abc +echo "test" >> "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V echo "-----" -cat ${tmpd}/abc +cat "${tmpd}"/abc echo "-----" -grep '^this is some test' ${tmpd}/abc >/dev/null -grep '^# author: deadc0de6' ${tmpd}/abc >/dev/null -grep '^tset,emos,si,siht' ${tmpd}/abc >/dev/null -grep "^${TESTENV}" ${tmpd}/abc > /dev/null -grep '^4ravd_eht' ${tmpd}/abc >/dev/null +grep '^this is some test' "${tmpd}"/abc >/dev/null +grep '^# author: deadc0de6' "${tmpd}"/abc >/dev/null +grep '^tset,emos,si,siht' "${tmpd}"/abc >/dev/null +grep "^${TESTENV}" "${tmpd}"/abc > /dev/null +grep '^4ravd_eht' "${tmpd}"/abc >/dev/null #cat ${tmpd}/abc diff --git a/tests-ng/env.sh b/tests-ng/env.sh index 41ef0e1..790b400 100755 --- a/tests-ng/env.sh +++ b/tests-ng/env.sh @@ -27,32 +27,35 @@ 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}" -tmpx=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` -tmpy=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpx=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +tmpy=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -60,15 +63,15 @@ clear_on_exit "${tmpx}" clear_on_exit "${tmpy}" # create the dotfile -mkdir -p ${tmpd}/adir -echo "adir/file1" > ${tmpd}/adir/file1 -echo "adir/fil2" > ${tmpd}/adir/file2 -echo "file3" > ${tmpd}/file3 +mkdir -p "${tmpd}"/adir +echo "adir/file1" > "${tmpd}"/adir/file1 +echo "adir/fil2" > "${tmpd}"/adir/file2 +echo "file3" > "${tmpd}"/file3 # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -88,40 +91,40 @@ export DOTDROP_WORKDIR="${tmpy}" export DOTDROP_WORKERS="1" # import -cd ${ddpath} | ${bin} import -f ${tmpd}/adir -cd ${ddpath} | ${bin} import -f ${tmpd}/file3 +cd "${ddpath}" | ${bin} import -f "${tmpd}"/adir +cd "${ddpath}" | ${bin} import -f "${tmpd}"/file3 -cat ${cfg} +cat "${cfg}" # ensure exists and is not link -[ ! -d ${tmps}/dotfiles/${tmpd}/adir ] && echo "not a directory" && exit 1 -[ ! -e ${tmps}/dotfiles/${tmpd}/adir/file1 ] && echo "not exist" && exit 1 -[ ! -e ${tmps}/dotfiles/${tmpd}/adir/file2 ] && echo "not exist" && exit 1 -[ ! -e ${tmps}/dotfiles/${tmpd}/file3 ] && echo "not a file" && exit 1 +[ ! -d "${tmps}"/dotfiles/"${tmpd}"/adir ] && echo "not a directory" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/adir/file1 ] && echo "not exist" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/adir/file2 ] && echo "not exist" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/file3 ] && echo "not a file" && exit 1 -cat ${cfg} | grep ${tmpd}/adir >/dev/null 2>&1 -cat ${cfg} | grep ${tmpd}/file3 >/dev/null 2>&1 +cat "${cfg}" | grep "${tmpd}"/adir >/dev/null 2>&1 +cat "${cfg}" | grep "${tmpd}"/file3 >/dev/null 2>&1 -nb=`cat ${cfg} | grep d_adir | wc -l` +nb=$(cat "${cfg}" | grep d_adir | wc -l) [ "${nb}" != "2" ] && echo 'bad config1' && exit 1 -nb=`cat ${cfg} | grep f_file3 | wc -l` +nb=$(cat "${cfg}" | grep f_file3 | wc -l) [ "${nb}" != "2" ] && echo 'bad config2' && exit 1 -cntpre=`find ${tmps}/dotfiles -type f | wc -l` +cntpre=$(find "${tmps}"/dotfiles -type f | wc -l) export DOTDROP_FORCE_NODEBUG= # compare -cd ${ddpath} | ${bin} compare +cd "${ddpath}" | ${bin} compare # install -cd ${ddpath} | ${bin} install -f +cd "${ddpath}" | ${bin} install -f # reimport -cd ${ddpath} | ${bin} import -f ${tmpd}/adir -cd ${ddpath} | ${bin} import -f ${tmpd}/file3 +cd "${ddpath}" | ${bin} import -f "${tmpd}"/adir +cd "${ddpath}" | ${bin} import -f "${tmpd}"/file3 -cntpost=`find ${tmps}/dotfiles -type f | wc -l` +cntpost=$(find "${tmps}"/dotfiles -type f | wc -l) [ "${cntpost}" != "${cntpre}" ] && echo "import failed" && exit 1 diff --git a/tests-ng/ext-actions.sh b/tests-ng/ext-actions.sh index 7dc168f..d4f914e 100755 --- a/tests-ng/ext-actions.sh +++ b/tests-ng/ext-actions.sh @@ -28,38 +28,41 @@ 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 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}" clear_on_exit "${tmpa}" act="${tmps}/actions.yaml" -cat > ${act} << _EOF +cat > "${act}" << _EOF actions: pre: preaction: echo 'pre' > ${tmpa}/pre @@ -72,7 +75,7 @@ _EOF # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -98,26 +101,26 @@ _EOF #cat ${cfg} # create the dotfile -echo "test" > ${tmps}/dotfiles/abc +echo "test" > "${tmps}"/dotfiles/abc # 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 ] && exit 1 -grep pre ${tmpa}/pre >/dev/null +[ ! -e "${tmpa}"/pre ] && exit 1 +grep pre "${tmpa}"/pre >/dev/null echo "pre is ok" -[ ! -e ${tmpa}/post ] && exit 1 -grep post ${tmpa}/post >/dev/null +[ ! -e "${tmpa}"/post ] && exit 1 +grep post "${tmpa}"/post >/dev/null echo "post is ok" -[ ! -e ${tmpa}/naked ] && exit 1 -grep naked ${tmpa}/naked >/dev/null +[ ! -e "${tmpa}"/naked ] && exit 1 +grep naked "${tmpa}"/naked >/dev/null echo "naked is ok" -[ ! -e ${tmpa}/write ] && exit 1 -grep over ${tmpa}/write >/dev/null +[ ! -e "${tmpa}"/write ] && exit 1 +grep over "${tmpa}"/write >/dev/null echo "write is ok" echo "OK" diff --git a/tests-ng/extvariables.sh b/tests-ng/extvariables.sh index a432afd..7324f93 100755 --- a/tests-ng/extvariables.sh +++ b/tests-ng/extvariables.sh @@ -28,29 +28,32 @@ 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}" clear_on_exit "${tmps}" @@ -59,13 +62,13 @@ clear_on_exit "${tmpd}" # create the config file extvars="${tmps}/variables.yaml" cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true dotpath: dotfiles import_variables: - - $(basename ${extvars}) + - $(basename "${extvars}") variables: var1: "var1" var2: "{{@@ var1 @@}} var2" @@ -97,7 +100,7 @@ _EOF #cat ${cfg} # create the external variables file -cat > ${extvars} << _EOF +cat > "${extvars}" << _EOF variables: varx: "exttest" dynvariables: @@ -106,47 +109,47 @@ dynvariables: _EOF # create the dotfile -echo "var3: {{@@ var3 @@}}" > ${tmps}/dotfiles/abc -echo "dvar3: {{@@ dvar3 @@}}" >> ${tmps}/dotfiles/abc -echo "var4: {{@@ var4 @@}}" >> ${tmps}/dotfiles/abc -echo "dvar4: {{@@ dvar4 @@}}" >> ${tmps}/dotfiles/abc -echo "varx: {{@@ varx @@}}" >> ${tmps}/dotfiles/abc -echo "evar1: {{@@ evar1 @@}}" >> ${tmps}/dotfiles/abc -echo "provar: {{@@ provar @@}}" >> ${tmps}/dotfiles/abc -echo "theprofile: {{@@ theprofile @@}}" >> ${tmps}/dotfiles/abc +echo "var3: {{@@ var3 @@}}" > "${tmps}"/dotfiles/abc +echo "dvar3: {{@@ dvar3 @@}}" >> "${tmps}"/dotfiles/abc +echo "var4: {{@@ var4 @@}}" >> "${tmps}"/dotfiles/abc +echo "dvar4: {{@@ dvar4 @@}}" >> "${tmps}"/dotfiles/abc +echo "varx: {{@@ varx @@}}" >> "${tmps}"/dotfiles/abc +echo "evar1: {{@@ evar1 @@}}" >> "${tmps}"/dotfiles/abc +echo "provar: {{@@ provar @@}}" >> "${tmps}"/dotfiles/abc +echo "theprofile: {{@@ theprofile @@}}" >> "${tmps}"/dotfiles/abc -echo "theprofile: {{@@ theprofile @@}}" > ${tmps}/dotfiles/def +echo "theprofile: {{@@ theprofile @@}}" > "${tmps}"/dotfiles/def #cat ${tmps}/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V echo "check1" -cat ${tmpd}/abc -grep '^var3: var1 var2 var3' ${tmpd}/abc >/dev/null -grep '^dvar3: dvar1 dvar2 dvar3' ${tmpd}/abc >/dev/null -grep '^var4: echo var1 var2 var3' ${tmpd}/abc >/dev/null -grep '^dvar4: var1 var2 var3' ${tmpd}/abc >/dev/null -grep '^varx: profvarx' ${tmpd}/abc >/dev/null -grep '^evar1: extevar1' ${tmpd}/abc >/dev/null -grep '^provar: provar' ${tmpd}/abc >/dev/null -grep '^theprofile: p1' ${tmpd}/abc >/dev/null +cat "${tmpd}"/abc +grep '^var3: var1 var2 var3' "${tmpd}"/abc >/dev/null +grep '^dvar3: dvar1 dvar2 dvar3' "${tmpd}"/abc >/dev/null +grep '^var4: echo var1 var2 var3' "${tmpd}"/abc >/dev/null +grep '^dvar4: var1 var2 var3' "${tmpd}"/abc >/dev/null +grep '^varx: profvarx' "${tmpd}"/abc >/dev/null +grep '^evar1: extevar1' "${tmpd}"/abc >/dev/null +grep '^provar: provar' "${tmpd}"/abc >/dev/null +grep '^theprofile: p1' "${tmpd}"/abc >/dev/null # check def -[ ! -e ${tmpd}/p1 ] && echo "def not created" && exit 1 -grep '^theprofile: p1' ${tmpd}/p1 >/dev/null +[ ! -e "${tmpd}"/p1 ] && echo "def not created" && exit 1 +grep '^theprofile: p1' "${tmpd}"/p1 >/dev/null -rm -f ${tmpd}/abc +rm -f "${tmpd}"/abc #cat ${tmpd}/abc -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true dotpath: dotfiles import_variables: - - $(basename ${extvars}) + - $(basename "${extvars}") dotfiles: f_abc: dst: ${tmpd}/abc @@ -162,7 +165,7 @@ _EOF #cat ${cfg} # create the external variables file -cat > ${extvars} << _EOF +cat > "${extvars}" << _EOF variables: var1: "extvar1" varx: "exttest" @@ -177,26 +180,26 @@ dynvariables: _EOF # create the dotfile -echo "var3: {{@@ var3 @@}}" > ${tmps}/dotfiles/abc -echo "dvar3: {{@@ dvar3 @@}}" >> ${tmps}/dotfiles/abc -echo "var4: {{@@ var4 @@}}" >> ${tmps}/dotfiles/abc -echo "dvar4: {{@@ dvar4 @@}}" >> ${tmps}/dotfiles/abc -echo "varx: {{@@ varx @@}}" >> ${tmps}/dotfiles/abc -echo "vary: {{@@ vary @@}}" >> ${tmps}/dotfiles/abc +echo "var3: {{@@ var3 @@}}" > "${tmps}"/dotfiles/abc +echo "dvar3: {{@@ dvar3 @@}}" >> "${tmps}"/dotfiles/abc +echo "var4: {{@@ var4 @@}}" >> "${tmps}"/dotfiles/abc +echo "dvar4: {{@@ dvar4 @@}}" >> "${tmps}"/dotfiles/abc +echo "varx: {{@@ varx @@}}" >> "${tmps}"/dotfiles/abc +echo "vary: {{@@ vary @@}}" >> "${tmps}"/dotfiles/abc #cat ${tmps}/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V echo "test2" -cat ${tmpd}/abc -grep '^var3: extvar1 var2 var3' ${tmpd}/abc >/dev/null -grep '^dvar3: extdvar1 dvar2 dvar3' ${tmpd}/abc >/dev/null -grep '^var4: echo extvar1 var2 var3' ${tmpd}/abc >/dev/null -grep '^dvar4: extvar1 var2 var3' ${tmpd}/abc >/dev/null -grep '^varx: profvarx' ${tmpd}/abc >/dev/null -grep '^vary: profvary' ${tmpd}/abc >/dev/null +cat "${tmpd}"/abc +grep '^var3: extvar1 var2 var3' "${tmpd}"/abc >/dev/null +grep '^dvar3: extdvar1 dvar2 dvar3' "${tmpd}"/abc >/dev/null +grep '^var4: echo extvar1 var2 var3' "${tmpd}"/abc >/dev/null +grep '^dvar4: extvar1 var2 var3' "${tmpd}"/abc >/dev/null +grep '^varx: profvarx' "${tmpd}"/abc >/dev/null +grep '^vary: profvary' "${tmpd}"/abc >/dev/null echo "OK" exit 0 diff --git a/tests-ng/filter_file.sh b/tests-ng/filter_file.sh index 933a34c..41725f6 100755 --- a/tests-ng/filter_file.sh +++ b/tests-ng/filter_file.sh @@ -28,33 +28,36 @@ 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}" -filter_file=`mktemp` -filter_file2=`mktemp` -filter_file3=`mktemp` +filter_file=$(mktemp) +filter_file2=$(mktemp) +filter_file3=$(mktemp) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -66,7 +69,7 @@ clear_on_exit "${filter_file3}" cfg="${tmps}/config.yaml" cfgext="${tmps}/ext.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -89,7 +92,7 @@ variables: _EOF #cat ${cfg} -cat > ${cfgext} << _EOF +cat > "${cfgext}" << _EOF config: backup: true create: true @@ -100,46 +103,46 @@ profiles: dotfiles: _EOF -cat << _EOF > ${filter_file} +cat << _EOF > "${filter_file}" def filter1(arg1): return "filtered" def filter2(arg1, arg2=''): return arg2 _EOF -cat << _EOF > ${filter_file2} +cat << _EOF > "${filter_file2}" def filter3(integer): return str(int(integer) - 10) _EOF -cat << _EOF > ${filter_file3} +cat << _EOF > "${filter_file3}" def filter_ext(arg1): return "external" _EOF # create the dotfile -echo "this is the test dotfile" > ${tmps}/dotfiles/abc +echo "this is the test dotfile" > "${tmps}"/dotfiles/abc # test imported function -echo "{{@@ "abc" | filter1 @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ "arg1" | filter2('arg2') @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ "13" | filter3() @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ "something" | filter_ext() @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ filt @@}}variable" >> ${tmps}/dotfiles/abc +echo "{{@@ "abc" | filter1 @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ "arg1" | filter2('arg2') @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ "13" | filter3() @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ "something" | filter_ext() @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ filt @@}}variable" >> "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V #cat ${tmpd}/abc -grep '^filtered$' ${tmpd}/abc >/dev/null -grep '^arg2$' ${tmpd}/abc >/dev/null -grep '^3$' ${tmpd}/abc >/dev/null -grep '^external$' ${tmpd}/abc >/dev/null +grep '^filtered$' "${tmpd}"/abc >/dev/null +grep '^arg2$' "${tmpd}"/abc >/dev/null +grep '^3$' "${tmpd}"/abc >/dev/null +grep '^external$' "${tmpd}"/abc >/dev/null set +e -grep '^something$' ${tmpd}/abc >/dev/null && exit 1 +grep '^something$' "${tmpd}"/abc >/dev/null && exit 1 set -e -grep '^filteredvariable$' ${tmpd}/abc > /dev/null +grep '^filteredvariable$' "${tmpd}"/abc > /dev/null echo "OK" exit 0 diff --git a/tests-ng/force-actions.sh b/tests-ng/force-actions.sh index 78d08ac..c293bb0 100755 --- a/tests-ng/force-actions.sh +++ b/tests-ng/force-actions.sh @@ -28,31 +28,34 @@ 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 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}" @@ -61,7 +64,7 @@ clear_on_exit "${tmpa}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF actions: pre: preaction: echo 'pre' > ${tmpa}/pre @@ -92,34 +95,34 @@ _EOF #cat ${cfg} # create the dotfile -echo "test" > ${tmps}/dotfiles/abc +echo "test" > "${tmps}"/dotfiles/abc # deploy the dotfile -cp ${tmps}/dotfiles/abc ${tmpd}/abc +cp "${tmps}"/dotfiles/abc "${tmpd}"/abc # 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 ] && exit 1 -[ -e ${tmpa}/post ] && exit 1 -[ -e ${tmpa}/naked ] && exit 1 -[ -e ${tmpa}/pre2 ] && exit 1 -[ -e ${tmpa}/post2 ] && exit 1 +[ -e "${tmpa}"/pre ] && exit 1 +[ -e "${tmpa}"/post ] && exit 1 +[ -e "${tmpa}"/naked ] && exit 1 +[ -e "${tmpa}"/pre2 ] && exit 1 +[ -e "${tmpa}"/post2 ] && exit 1 # install and force -cd ${ddpath} | ${bin} install -f -a -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -a -c "${cfg}" -p p1 -V # checks -[ ! -e ${tmpa}/pre ] && exit 1 -grep pre ${tmpa}/pre >/dev/null -[ ! -e ${tmpa}/post ] && exit 1 -grep post ${tmpa}/post >/dev/null -[ ! -e ${tmpa}/naked ] && exit 1 -grep naked ${tmpa}/naked >/dev/null -[ ! -e ${tmpa}/pre2 ] && exit 1 -grep pre2 ${tmpa}/pre2 >/dev/null -[ ! -e ${tmpa}/post2 ] && exit 1 -grep post2 ${tmpa}/post2 >/dev/null +[ ! -e "${tmpa}"/pre ] && exit 1 +grep pre "${tmpa}"/pre >/dev/null +[ ! -e "${tmpa}"/post ] && exit 1 +grep post "${tmpa}"/post >/dev/null +[ ! -e "${tmpa}"/naked ] && exit 1 +grep naked "${tmpa}"/naked >/dev/null +[ ! -e "${tmpa}"/pre2 ] && exit 1 +grep pre2 "${tmpa}"/pre2 >/dev/null +[ ! -e "${tmpa}"/post2 ] && exit 1 +grep post2 "${tmpa}"/post2 >/dev/null echo "OK" exit 0 diff --git a/tests-ng/func_file.sh b/tests-ng/func_file.sh index 65f5ca6..d1b2afc 100755 --- a/tests-ng/func_file.sh +++ b/tests-ng/func_file.sh @@ -28,33 +28,36 @@ 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}" -func_file=`mktemp` -func_file2=`mktemp` -func_file3=`mktemp` +func_file=$(mktemp) +func_file2=$(mktemp) +func_file3=$(mktemp) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -66,7 +69,7 @@ clear_on_exit "${func_file3}" cfg="${tmps}/config.yaml" cfgext="${tmps}/ext.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -89,7 +92,7 @@ variables: _EOF #cat ${cfg} -cat > ${cfgext} << _EOF +cat > "${cfgext}" << _EOF config: backup: true create: true @@ -100,62 +103,62 @@ dotfiles: profiles: _EOF -cat << _EOF > ${func_file} +cat << _EOF > "${func_file}" def func1(something): if something: return True return False _EOF -cat << _EOF > ${func_file2} +cat << _EOF > "${func_file2}" def func2(inp): return not inp _EOF -cat << _EOF > ${func_file3} +cat << _EOF > "${func_file3}" def func3(inp): return 42 _EOF # create the dotfile -echo "this is the test dotfile" > ${tmps}/dotfiles/abc +echo "this is the test dotfile" > "${tmps}"/dotfiles/abc # test imported function -echo "{%@@ if func1(True) @@%}" >> ${tmps}/dotfiles/abc -echo "this should exist" >> ${tmps}/dotfiles/abc -echo "{%@@ endif @@%}" >> ${tmps}/dotfiles/abc +echo "{%@@ if func1(True) @@%}" >> "${tmps}"/dotfiles/abc +echo "this should exist" >> "${tmps}"/dotfiles/abc +echo "{%@@ endif @@%}" >> "${tmps}"/dotfiles/abc -echo "{%@@ if not func1(False) @@%}" >> ${tmps}/dotfiles/abc -echo "this should exist too" >> ${tmps}/dotfiles/abc -echo "{%@@ endif @@%}" >> ${tmps}/dotfiles/abc +echo "{%@@ if not func1(False) @@%}" >> "${tmps}"/dotfiles/abc +echo "this should exist too" >> "${tmps}"/dotfiles/abc +echo "{%@@ endif @@%}" >> "${tmps}"/dotfiles/abc -echo "{%@@ if func2(True) @@%}" >> ${tmps}/dotfiles/abc -echo "nope" >> ${tmps}/dotfiles/abc -echo "{%@@ endif @@%}" >> ${tmps}/dotfiles/abc +echo "{%@@ if func2(True) @@%}" >> "${tmps}"/dotfiles/abc +echo "nope" >> "${tmps}"/dotfiles/abc +echo "{%@@ endif @@%}" >> "${tmps}"/dotfiles/abc -echo "{%@@ if func2(False) @@%}" >> ${tmps}/dotfiles/abc -echo "yes" >> ${tmps}/dotfiles/abc -echo "{%@@ endif @@%}" >> ${tmps}/dotfiles/abc +echo "{%@@ if func2(False) @@%}" >> "${tmps}"/dotfiles/abc +echo "yes" >> "${tmps}"/dotfiles/abc +echo "{%@@ endif @@%}" >> "${tmps}"/dotfiles/abc -echo "{%@@ if func3("whatever") == 42 @@%}" >> ${tmps}/dotfiles/abc -echo "externalok" >> ${tmps}/dotfiles/abc -echo "{%@@ endif @@%}" >> ${tmps}/dotfiles/abc +echo "{%@@ if func3(\"whatever\") == 42 @@%}" >> "${tmps}"/dotfiles/abc +echo "externalok" >> "${tmps}"/dotfiles/abc +echo "{%@@ endif @@%}" >> "${tmps}"/dotfiles/abc -echo "{{@@ func @@}}added" >> ${tmps}/dotfiles/abc +echo "{{@@ func @@}}added" >> "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V #cat ${tmpd}/abc -grep '^this should exist$' ${tmpd}/abc >/dev/null -grep '^this should exist too$' ${tmpd}/abc >/dev/null -grep '^yes$' ${tmpd}/abc >/dev/null -grep '^externalok$' ${tmpd}/abc >/dev/null +grep '^this should exist$' "${tmpd}"/abc >/dev/null +grep '^this should exist too$' "${tmpd}"/abc >/dev/null +grep '^yes$' "${tmpd}"/abc >/dev/null +grep '^externalok$' "${tmpd}"/abc >/dev/null set +e -grep '^nope$' ${tmpd}/abc >/dev/null && exit 1 +grep '^nope$' "${tmpd}"/abc >/dev/null && exit 1 set -e -grep '^Falseadded$' ${tmpd}/abc >/dev/null +grep '^Falseadded$' "${tmpd}"/abc >/dev/null echo "OK" exit 0 diff --git a/tests-ng/global-compare-ignore.sh b/tests-ng/global-compare-ignore.sh index 7b3da57..e101293 100755 --- a/tests-ng/global-compare-ignore.sh +++ b/tests-ng/global-compare-ignore.sh @@ -28,43 +28,46 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" # the dotfile to be imported -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # some files -mkdir -p ${tmpd}/{program,config} -touch ${tmpd}/program/a -touch ${tmpd}/config/a +mkdir -p "${tmpd}"/{program,config} +touch "${tmpd}"/program/a +touch "${tmpd}"/config/a # create the config file cfg="${basedir}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -75,36 +78,36 @@ _EOF # import echo "[+] import" -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/program -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/config +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/program +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/config # add files echo "[+] add files" -touch ${tmpd}/program/b -touch ${tmpd}/config/b +touch "${tmpd}"/program/b +touch "${tmpd}"/config/b # adding ignore in dotfile cfg2="${basedir}/config2.yaml" -sed '/dotpath: dotfiles/a \ \ cmpignore:\n\ \ \ \ - "*/config/b"' ${cfg} > ${cfg2} -cat ${cfg2} +sed '/dotpath: dotfiles/a \ \ cmpignore:\n\ \ \ \ - "*/config/b"' "${cfg}" > "${cfg2}" +cat "${cfg2}" # expects one diff echo "[+] comparing with ignore in dotfile - 1 diff" set +e -cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose +cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose [ "$?" = "0" ] && exit 1 set -e # adding ignore in dotfile cfg2="${basedir}/config2.yaml" -sed '/dotpath: dotfiles/a \ \ cmpignore:\n\ \ \ \ - "*b"' ${cfg} > ${cfg2} -cat ${cfg2} +sed '/dotpath: dotfiles/a \ \ cmpignore:\n\ \ \ \ - "*b"' "${cfg}" > "${cfg2}" +cat "${cfg2}" # expects no diff patt="*b" echo "[+] comparing with ignore in dotfile - 0 diff" set +e -cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose +cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose [ "$?" != "0" ] && exit 1 set -e diff --git a/tests-ng/global-compare-negative-ignore.sh b/tests-ng/global-compare-negative-ignore.sh index 00cf4a7..c5fef6d 100755 --- a/tests-ng/global-compare-negative-ignore.sh +++ b/tests-ng/global-compare-negative-ignore.sh @@ -9,41 +9,12 @@ set -e # all this crap to get current path -if [ $(uname) = Darwin ]; then - # Unfortunately, readlink works differently on macOS than it does on GNU/Linux - # (the -f option behaves differently) and the realpath command does not exist. - # Workarounds I find on the Internet suggest just using Homebrew to install coreutils - # so you can get the GNU coreutils on your Mac. But, I don't want this script to - # assume (a) users have Homebrew installed and (b) if they have Homebrew installed, that - # they then installed the GNU coreutils. - readlink() { - TARGET_FILE=$1 +rl="readlink -f" +if ! ${rl} "${0}" >/dev/null 2>&1; then + rl="realpath" - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - - # Iterate down a (possible) chain of symlinks - while [ -L "$TARGET_FILE" ]; do - TARGET_FILE=`readlink $TARGET_FILE` - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - done - - # Compute the canonicalized name by finding the physical path - # for the directory we're in and appending the target file. - PHYS_DIR=`pwd -P` - RESULT=$PHYS_DIR/$TARGET_FILE - echo $RESULT - } - rl="readlink" -else - rl="readlink -f" - if ! ${rl} "${0}" >/dev/null 2>&1; then - rl="realpath" - - if ! hash ${rl}; then - echo "\"${rl}\" not found !" && exit 1 - fi + if ! hash ${rl}; then + echo "\"${rl}\" not found !" && exit 1 fi fi cur=$(dirname "$(${rl} "${0}")") @@ -51,53 +22,56 @@ cur=$(dirname "$(${rl} "${0}")") # dotdrop path can be pass as argument ddpath="${cur}/../" [ -n "${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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" # the dotfile to be imported -tmpd=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # some files -mkdir -p ${tmpd}/{program,config} -touch ${tmpd}/program/a -touch ${tmpd}/config/a +mkdir -p "${tmpd}"/{program,config} +touch "${tmpd}"/program/a +touch "${tmpd}"/config/a # create the config file cfg="${basedir}/config.yaml" -create_conf ${cfg} # sets token +create_conf "${cfg}" # sets token # import echo "[+] import" -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/program -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/config +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/program +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/config # add files echo "[+] add files" -touch ${tmpd}/program/b -touch ${tmpd}/config/b +touch "${tmpd}"/program/b +touch "${tmpd}"/config/b # adding ignore in dotfile cfg2="${basedir}/config2.yaml" @@ -105,13 +79,13 @@ sed '/dotpath: dotfiles/a\ \ \ cmpignore:\ \ \ \ \ - "*/config/*"\ \ \ \ \ - "!*/config/a"\ -' ${cfg} > ${cfg2} -cat ${cfg2} +' "${cfg}" > "${cfg2}" +cat "${cfg2}" # expects one diff echo "[+] comparing with ignore in dotfile - 1 diff" set +e -cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose +cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose [ "$?" = "0" ] && exit 1 set -e diff --git a/tests-ng/global-update-ignore.sh b/tests-ng/global-update-ignore.sh index 60e18c0..efd758d 100755 --- a/tests-ng/global-update-ignore.sh +++ b/tests-ng/global-update-ignore.sh @@ -28,42 +28,45 @@ 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 ################################################################ # dotdrop directory -tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) dt="${tmps}/dotfiles" -mkdir -p ${dt} -mkdir -p ${dt}/a/{b,c} -echo 'a' > ${dt}/a/b/abfile -echo 'a' > ${dt}/a/c/acfile +mkdir -p "${dt}" +mkdir -p "${dt}"/a/{b,c} +echo 'a' > "${dt}"/a/b/abfile +echo 'a' > "${dt}"/a/c/acfile # fs dotfiles -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` -cp -r ${dt}/a ${tmpd}/ +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +cp -r "${dt}"/a "${tmpd}"/ clear_on_exit "${tmps}" clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: false create: true @@ -87,25 +90,25 @@ _EOF # edit/add files echo "[+] edit/add files" -touch ${tmpd}/a/newfile -echo 'b' > ${tmpd}/a/c/acfile -mkdir -p ${tmpd}/a/newdir/b -touch ${tmpd}/a/newdir/b/c +touch "${tmpd}"/a/newfile +echo 'b' > "${tmpd}"/a/c/acfile +mkdir -p "${tmpd}"/a/newdir/b +touch "${tmpd}"/a/newdir/b/c #tree ${tmpd}/a # update echo "[+] update" -cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=p1 --key f_abc +cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=p1 --key f_abc #tree ${dt} # check files haven't been updated -[ ! -e ${dt}/a/c/acfile ] && echo "acfile not found" && exit 1 +[ ! -e "${dt}"/a/c/acfile ] && echo "acfile not found" && exit 1 set +e -grep 'b' ${dt}/a/c/acfile || (echo "acfile not updated" && exit 1) +grep 'b' "${dt}"/a/c/acfile || (echo "acfile not updated" && exit 1) set -e -[ -e ${dt}/a/newfile ] && echo "newfile found" && exit 1 +[ -e "${dt}"/a/newfile ] && echo "newfile found" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/global-update-negative-ignore.sh b/tests-ng/global-update-negative-ignore.sh index 5afa67d..faee38c 100755 --- a/tests-ng/global-update-negative-ignore.sh +++ b/tests-ng/global-update-negative-ignore.sh @@ -9,41 +9,12 @@ set -e # all this crap to get current path -if [ $(uname) = Darwin ]; then - # Unfortunately, readlink works differently on macOS than it does on GNU/Linux - # (the -f option behaves differently) and the realpath command does not exist. - # Workarounds I find on the Internet suggest just using Homebrew to install coreutils - # so you can get the GNU coreutils on your Mac. But, I don't want this script to - # assume (a) users have Homebrew installed and (b) if they have Homebrew installed, that - # they then installed the GNU coreutils. - readlink() { - TARGET_FILE=$1 +rl="readlink -f" +if ! ${rl} "${0}" >/dev/null 2>&1; then + rl="realpath" - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - - # Iterate down a (possible) chain of symlinks - while [ -L "$TARGET_FILE" ]; do - TARGET_FILE=`readlink $TARGET_FILE` - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - done - - # Compute the canonicalized name by finding the physical path - # for the directory we're in and appending the target file. - PHYS_DIR=`pwd -P` - RESULT=$PHYS_DIR/$TARGET_FILE - echo $RESULT - } - rl="readlink" -else - rl="readlink -f" - if ! ${rl} "${0}" >/dev/null 2>&1; then - rl="realpath" - - if ! hash ${rl}; then - echo "\"${rl}\" not found !" && exit 1 - fi + if ! hash ${rl}; then + echo "\"${rl}\" not found !" && exit 1 fi fi cur=$(dirname "$(${rl} "${0}")") @@ -51,44 +22,47 @@ cur=$(dirname "$(${rl} "${0}")") # dotdrop path can be pass as argument ddpath="${cur}/../" [ -n "${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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" -mkdir -p ${basedir}/dotfiles/a/{b,c} -echo 'a' > ${basedir}/dotfiles/a/b/abfile1 -echo 'a' > ${basedir}/dotfiles/a/b/abfile2 -echo 'a' > ${basedir}/dotfiles/a/b/abfile3 -echo 'a' > ${basedir}/dotfiles/a/c/acfile +mkdir -p "${basedir}"/dotfiles/a/{b,c} +echo 'a' > "${basedir}"/dotfiles/a/b/abfile1 +echo 'a' > "${basedir}"/dotfiles/a/b/abfile2 +echo 'a' > "${basedir}"/dotfiles/a/b/abfile3 +echo 'a' > "${basedir}"/dotfiles/a/c/acfile # the dotfile to be updated -tmpd=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` -cp -r ${basedir}/dotfiles/a ${tmpd}/ +tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) +cp -r "${basedir}"/dotfiles/a "${tmpd}"/ clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # create the config file cfg="${basedir}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: false create: true @@ -110,26 +84,26 @@ _EOF # edit/add files echo "[+] edit/add files" -mkdir -p ${tmpd}/a/newdir/b -echo 'b' > ${tmpd}/a/b/abfile1 -echo 'b' > ${tmpd}/a/b/abfile2 -echo 'b' > ${tmpd}/a/b/abfile3 -echo 'b' > ${tmpd}/a/b/abfile4 -touch ${tmpd}/a/newdir/b/{c,d} +mkdir -p "${tmpd}"/a/newdir/b +echo 'b' > "${tmpd}"/a/b/abfile1 +echo 'b' > "${tmpd}"/a/b/abfile2 +echo 'b' > "${tmpd}"/a/b/abfile3 +echo 'b' > "${tmpd}"/a/b/abfile4 +touch "${tmpd}"/a/newdir/b/{c,d} # update echo "[+] update" -cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=p1 --key f_abc +cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=p1 --key f_abc # check files haven't been updated set +e -grep 'a' ${basedir}/dotfiles/a/b/abfile1 >/dev/null 2>&1 || (echo "abfile1 should not have been updated" && exit 1) -grep 'a' ${basedir}/dotfiles/a/b/abfile2 >/dev/null 2>&1 || (echo "abfile2 should not have been updated" && exit 1) -grep 'b' ${basedir}/dotfiles/a/b/abfile3 >/dev/null 2>&1 || (echo "abfile3 was not updated" && exit 1) +grep 'a' "${basedir}"/dotfiles/a/b/abfile1 >/dev/null 2>&1 || (echo "abfile1 should not have been updated" && exit 1) +grep 'a' "${basedir}"/dotfiles/a/b/abfile2 >/dev/null 2>&1 || (echo "abfile2 should not have been updated" && exit 1) +grep 'b' "${basedir}"/dotfiles/a/b/abfile3 >/dev/null 2>&1 || (echo "abfile3 was not updated" && exit 1) set -e -[ -e ${basedir}/dotfiles/a/b/abfile4 ] && echo "abfile4 should not have been updated" && exit 1 -[ -e ${basedir}/dotfiles/a/newdir/b/c ] && echo "newdir/b/c should not have been updated" && exit 1 -[ ! -e ${basedir}/dotfiles/a/newdir/b/d ] && echo "newdir/b/d should have been updated" && exit 1 +[ -e "${basedir}"/dotfiles/a/b/abfile4 ] && echo "abfile4 should not have been updated" && exit 1 +[ -e "${basedir}"/dotfiles/a/newdir/b/c ] && echo "newdir/b/c should not have been updated" && exit 1 +[ ! -e "${basedir}"/dotfiles/a/newdir/b/d ] && echo "newdir/b/d should have been updated" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/globs.sh b/tests-ng/globs.sh index 5ae60bf..ee5d0ec 100755 --- a/tests-ng/globs.sh +++ b/tests-ng/globs.sh @@ -31,31 +31,34 @@ 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) # temporary -tmpa=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpa=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -66,18 +69,18 @@ clear_on_exit "${tmpa}" ########### # create the action files actionsd="${tmps}/actions" -mkdir -p ${actionsd} -cat > ${actionsd}/action1.yaml << _EOF +mkdir -p "${actionsd}" +cat > "${actionsd}"/action1.yaml << _EOF actions: fromaction1: echo "fromaction1" > ${tmpa}/fromaction1 _EOF -cat > ${actionsd}/action2.yaml << _EOF +cat > "${actionsd}"/action2.yaml << _EOF actions: fromaction2: echo "fromaction2" > ${tmpa}/fromaction2 _EOF cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -98,18 +101,18 @@ profiles: _EOF # create the source -mkdir -p ${tmps}/dotfiles/ -echo "abc" > ${tmps}/dotfiles/abc +mkdir -p "${tmps}"/dotfiles/ +echo "abc" > "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 -V +cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 -V # checks -[ ! -e ${tmpd}/abc ] && echo "dotfile not installed" && exit 1 -[ ! -e ${tmpa}/fromaction1 ] && echo "action1 not executed" && exit 1 -grep fromaction1 ${tmpa}/fromaction1 -[ ! -e ${tmpa}/fromaction2 ] && echo "action2 not executed" && exit 1 -grep fromaction2 ${tmpa}/fromaction2 +[ ! -e "${tmpd}"/abc ] && echo "dotfile not installed" && exit 1 +[ ! -e "${tmpa}"/fromaction1 ] && echo "action1 not executed" && exit 1 +grep fromaction1 "${tmpa}"/fromaction1 +[ ! -e "${tmpa}"/fromaction2 ] && echo "action2 not executed" && exit 1 +grep fromaction2 "${tmpa}"/fromaction2 echo "OK" exit 0 diff --git a/tests-ng/header.sh b/tests-ng/header.sh index bd0ae5b..e51e6ec 100755 --- a/tests-ng/header.sh +++ b/tests-ng/header.sh @@ -28,30 +28,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 +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmps}"/dotfiles #echo "dotfile source: ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) #echo "dotfile destination: ${tmpd}" clear_on_exit "${tmps}" @@ -60,7 +63,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -77,17 +80,17 @@ _EOF #cat ${cfg} # create the dotfile -echo "{{@@ header() @@}}" > ${tmps}/dotfiles/abc -echo "{{@@ header('# ') @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ header('// ') @@}}" >> ${tmps}/dotfiles/abc -echo "test" >> ${tmps}/dotfiles/abc +echo "{{@@ header() @@}}" > "${tmps}"/dotfiles/abc +echo "{{@@ header('# ') @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ header('// ') @@}}" >> "${tmps}"/dotfiles/abc +echo "test" >> "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -grep '^This dotfile is managed using dotdrop' ${tmpd}/abc >/dev/null -grep '^# This dotfile is managed using dotdrop' ${tmpd}/abc >/dev/null -grep '^// This dotfile is managed using dotdrop' ${tmpd}/abc >/dev/null +grep '^This dotfile is managed using dotdrop' "${tmpd}"/abc >/dev/null +grep '^# This dotfile is managed using dotdrop' "${tmpd}"/abc >/dev/null +grep '^// This dotfile is managed using dotdrop' "${tmpd}"/abc >/dev/null #cat ${tmpd}/abc diff --git a/tests-ng/ignore-empty.sh b/tests-ng/ignore-empty.sh index 8e265ef..b3d2431 100755 --- a/tests-ng/ignore-empty.sh +++ b/tests-ng/ignore-empty.sh @@ -28,30 +28,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 +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmps}"/dotfiles #echo "dotfile source: ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) #echo "dotfile destination: ${tmpd}" clear_on_exit "${tmps}" @@ -61,7 +64,7 @@ clear_on_exit "${tmpd}" cfg="${tmps}/config.yaml" # globally -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -79,19 +82,19 @@ _EOF #cat ${cfg} # create the dotfile -mkdir -p ${tmps}/dotfiles/d1 -echo "{#@@ should be stripped @@#}" > ${tmps}/dotfiles/d1/empty -echo "not empty" > ${tmps}/dotfiles/d1/notempty +mkdir -p "${tmps}"/dotfiles/d1 +echo "{#@@ should be stripped @@#}" > "${tmps}"/dotfiles/d1/empty +echo "not empty" > "${tmps}"/dotfiles/d1/notempty # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V # test existence -[ -e ${tmpd}/d1/empty ] && echo 'empty should not exist' && exit 1 -[ ! -e ${tmpd}/d1/notempty ] && echo 'not empty should exist' && exit 1 +[ -e "${tmpd}"/d1/empty ] && echo 'empty should not exist' && exit 1 +[ ! -e "${tmpd}"/d1/notempty ] && echo 'not empty should exist' && exit 1 # through the dotfile -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -110,14 +113,14 @@ _EOF #cat ${cfg} # clean destination -rm -rf ${tmpd}/* +rm -rf "${tmpd:?}"/* # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V # test existence -[ -e ${tmpd}/d1/empty ] && echo 'empty should not exist' && exit 1 -[ ! -e ${tmpd}/d1/notempty ] && echo 'not empty should exist' && exit 1 +[ -e "${tmpd}"/d1/empty ] && echo 'empty should not exist' && exit 1 +[ ! -e "${tmpd}"/d1/notempty ] && echo 'not empty should exist' && exit 1 echo "OK" exit 0 diff --git a/tests-ng/import-as.sh b/tests-ng/import-as.sh index c1ca48f..2ea3f29 100755 --- a/tests-ng/import-as.sh +++ b/tests-ng/import-as.sh @@ -27,46 +27,49 @@ 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}" clear_on_exit "${tmps}" clear_on_exit "${tmpd}" -clear_on_exit "~/.dotdrop.test" -clear_on_exit "~/.dotdrop-dotfiles-test" +clear_on_exit "${HOME}/.dotdrop.test" +clear_on_exit "${HOME}/.dotdrop-dotfiles-test" # create the dotfile -mkdir -p ${tmpd}/adir -echo "adir/file1" > ${tmpd}/adir/file1 -echo "adir/fil2" > ${tmpd}/adir/file2 -echo "file3" > ${tmpd}/file3 +mkdir -p "${tmpd}"/adir +echo "adir/file1" > "${tmpd}"/adir/file1 +echo "adir/fil2" > "${tmpd}"/adir/file2 +echo "file3" > "${tmpd}"/file3 # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -77,47 +80,47 @@ _EOF #cat ${cfg} # import -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/adir -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/file3 +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/adir +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/file3 echo "import --as dotfiles" -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p2 -V ${tmpd}/adir --as ~/config/adir -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p2 -V ${tmpd}/file3 --as ~/config2/file3 +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p2 -V "${tmpd}"/adir --as ~/config/adir +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p2 -V "${tmpd}"/file3 --as ~/config2/file3 -cat ${cfg} +cat "${cfg}" set +e -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p2 -V ${tmpd}/adir --as ~/config/should_not && echo "dual dst imported" && exit 1 +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p2 -V "${tmpd}"/adir --as ~/config/should_not && echo "dual dst imported" && exit 1 set -e -cat ${cfg} | grep should_not && echo "dual dst imported" && exit 1 +cat "${cfg}" | grep should_not && echo "dual dst imported" && exit 1 -cat ${cfg} +cat "${cfg}" echo "ensure exists and is not link" -[ ! -d ${tmps}/dotfiles/${tmpd}/adir ] && echo "not a directory" && exit 1 -[ ! -e ${tmps}/dotfiles/${tmpd}/adir/file1 ] && echo "not exist" && exit 1 -[ ! -e ${tmps}/dotfiles/${tmpd}/adir/file2 ] && echo "not exist" && exit 1 -[ ! -e ${tmps}/dotfiles/${tmpd}/file3 ] && echo "not a file" && exit 1 +[ ! -d "${tmps}"/dotfiles/"${tmpd}"/adir ] && echo "not a directory" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/adir/file1 ] && echo "not exist" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/adir/file2 ] && echo "not exist" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/file3 ] && echo "not a file" && exit 1 echo "ensure --as are correctly imported" -[ ! -d ${tmps}/dotfiles/config/adir ] && echo "not a directory" && exit 1 -[ ! -e ${tmps}/dotfiles/config/adir/file1 ] && echo "not exist" && exit 1 -[ ! -e ${tmps}/dotfiles/config/adir/file2 ] && echo "not exist" && exit 1 -[ ! -e ${tmps}/dotfiles/config2/file3 ] && echo "not a file" && exit 1 +[ ! -d "${tmps}"/dotfiles/config/adir ] && echo "not a directory" && exit 1 +[ ! -e "${tmps}"/dotfiles/config/adir/file1 ] && echo "not exist" && exit 1 +[ ! -e "${tmps}"/dotfiles/config/adir/file2 ] && echo "not exist" && exit 1 +[ ! -e "${tmps}"/dotfiles/config2/file3 ] && echo "not a file" && exit 1 -cat ${cfg} | grep ${tmpd}/adir >/dev/null 2>&1 -cat ${cfg} | grep ${tmpd}/file3 >/dev/null 2>&1 +cat "${cfg}" | grep "${tmpd}"/adir >/dev/null 2>&1 +cat "${cfg}" | grep "${tmpd}"/file3 >/dev/null 2>&1 -cat ${cfg} | grep config/adir >/dev/null 2>&1 -cat ${cfg} | grep config2/file3 >/dev/null 2>&1 +cat "${cfg}" | grep config/adir >/dev/null 2>&1 +cat "${cfg}" | grep config2/file3 >/dev/null 2>&1 -nb=`cat ${cfg} | grep d_adir | wc -l` +nb=$(cat "${cfg}" | grep d_adir | wc -l) [ "${nb}" != "2" ] && echo 'bad config1' && exit 1 -nb=`cat ${cfg} | grep f_file3 | wc -l` +nb=$(cat "${cfg}" | grep f_file3 | wc -l) [ "${nb}" != "2" ] && echo 'bad config2' && exit 1 -cat ${cfg} | grep "src: config/adir" || exit 1 -cat ${cfg} | grep "src: config2/file3" || exit 1 +cat "${cfg}" | grep "src: config/adir" || exit 1 +cat "${cfg}" | grep "src: config2/file3" || exit 1 # test import from sub in home mkdir -p ~/.dotdrop-dotfiles-test/{dotfiles,config} @@ -137,11 +140,11 @@ dotfiles: profiles: _EOF -cd ${ddpath} | ${bin} import -f -b -c ${cfg} -p test -V ~/.dotdrop.test --as=~/.whatever +cd "${ddpath}" | ${bin} import -f -b -c ${cfg} -p test -V ~/.dotdrop.test --as=~/.whatever #cat ${cfg} [ ! -e ~/.dotdrop-dotfiles-test/dotfiles/whatever ] && echo 'tild imported' && exit 1 -cat ${cfg} | grep '~/.whatever' && echo 'import with tild failed' && exit 1 +cat ${cfg} | grep "${HOME}/.whatever" && echo 'import with tild failed' && exit 1 echo "OK" exit 0 diff --git a/tests-ng/import-configs.sh b/tests-ng/import-configs.sh index b81c39e..079c032 100755 --- a/tests-ng/import-configs.sh +++ b/tests-ng/import-configs.sh @@ -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" diff --git a/tests-ng/import-configs2.sh b/tests-ng/import-configs2.sh index 24ca4c0..b3845e9 100755 --- a/tests-ng/import-configs2.sh +++ b/tests-ng/import-configs2.sh @@ -27,41 +27,44 @@ 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 sources -tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) # 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}" first="${tmps}/first" second="${tmps}/second" -mkdir -p ${first} ${second} +mkdir -p "${first}" "${second}" # create the config file cfg1="${first}/config.yaml" cfg2="${second}/config.yaml" -cat > ${cfg1} << _EOF +cat > "${cfg1}" << _EOF config: backup: true create: true @@ -80,7 +83,7 @@ profiles: - f_abc _EOF -cat > ${cfg2} << _EOF +cat > "${cfg2}" << _EOF config: backup: true create: true @@ -96,24 +99,24 @@ profiles: _EOF # create the source -echo "abc" > ${first}/abc -echo "{{@@ _dotfile_abs_dst @@}}" >> ${first}/abc +echo "abc" > "${first}"/abc +echo "{{@@ _dotfile_abs_dst @@}}" >> "${first}"/abc -echo "def" > ${second}/def -echo "{{@@ _dotfile_abs_dst @@}}" >> ${second}/def +echo "def" > "${second}"/def +echo "{{@@ _dotfile_abs_dst @@}}" >> "${second}"/def # files comparison -cd ${ddpath} | ${bin} files -c ${cfg1} -G -p p0 | grep '^f_abc' -cd ${ddpath} | ${bin} files -c ${cfg1} -G -p p0 | grep '^f_def' -cd ${ddpath} | ${bin} files -c ${cfg1} -G -p p1 | grep '^f_def' -cd ${ddpath} | ${bin} files -c ${cfg2} -G -p p1 | grep '^f_def' +cd "${ddpath}" | ${bin} files -c "${cfg1}" -G -p p0 | grep '^f_abc' +cd "${ddpath}" | ${bin} files -c "${cfg1}" -G -p p0 | grep '^f_def' +cd "${ddpath}" | ${bin} files -c "${cfg1}" -G -p p1 | grep '^f_def' +cd "${ddpath}" | ${bin} files -c "${cfg2}" -G -p p1 | grep '^f_def' # test compare too -cd ${ddpath} | ${bin} install -c ${cfg1} -p p0 -V -f -cd ${ddpath} | ${bin} compare -c ${cfg1} -p p0 -V +cd "${ddpath}" | ${bin} install -c "${cfg1}" -p p0 -V -f +cd "${ddpath}" | ${bin} compare -c "${cfg1}" -p p0 -V -[ ! -s ${tmpd}/abc ] && echo "abc not installed" && exit 1 -[ ! -s ${tmpd}/def ] && echo "def not installed" && exit 1 +[ ! -s "${tmpd}"/abc ] && echo "abc not installed" && exit 1 +[ ! -s "${tmpd}"/def ] && echo "def not installed" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/import-duplicate.sh b/tests-ng/import-duplicate.sh index 4950334..6358ace 100755 --- a/tests-ng/import-duplicate.sh +++ b/tests-ng/import-duplicate.sh @@ -27,43 +27,46 @@ 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}" clear_on_exit "${tmps}" clear_on_exit "${tmpd}" # create the dotfile -touch ${tmpd}/.colors -mkdir -p ${tmpd}/.mutt -touch ${tmpd}/.mutt/colors +touch "${tmpd}"/.colors +mkdir -p "${tmpd}"/.mutt +touch "${tmpd}"/.mutt/colors # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -76,35 +79,35 @@ dotfiles: f_mutt_colors: src: abc dst: abc - f_`echo ${tmpd} | sed -e 's#^/\(.*\)$#\1#g' | sed 's#/#_#g' | tr '[:upper:]' '[:lower:]'`_colors: + f_$(echo "${tmpd}" | sed -e 's#^/\(.*\)$#\1#g' | sed 's#/#_#g' | tr '[:upper:]' '[:lower:]')_colors: src: abc dst: abc - f_`echo ${tmpd} | sed -e 's#^/tmp/\(.*\)$#\1#g' | sed 's#/#_#g' | tr '[:upper:]' '[:lower:]'`_colors: + f_$(echo "${tmpd}" | sed -e 's#^/tmp/\(.*\)$#\1#g' | sed 's#/#_#g' | tr '[:upper:]' '[:lower:]')_colors: src: abc dst: abc - f_`echo ${tmpd} | sed -e 's#^/\(.*\)$#\1#g' | sed 's#/#_#g' | tr '[:upper:]' '[:lower:]'`_mutt_colors: + f_$(echo "${tmpd}" | sed -e 's#^/\(.*\)$#\1#g' | sed 's#/#_#g' | tr '[:upper:]' '[:lower:]')_mutt_colors: src: abc dst: abc - f_`echo ${tmpd} | sed -e 's#^/tmp/\(.*\)$#\1#g' | sed 's#/#_#g' | tr '[:upper:]' '[:lower:]'`_mutt_colors: + f_$(echo "${tmpd}" | sed -e 's#^/tmp/\(.*\)$#\1#g' | sed 's#/#_#g' | tr '[:upper:]' '[:lower:]')_mutt_colors: src: abc dst: abc profiles: _EOF -cat ${cfg} +cat "${cfg}" # import -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/.mutt/colors -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/.colors +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/.mutt/colors +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/.colors -cat ${cfg} +cat "${cfg}" # ensure exists and is not link -[ ! -d ${tmps}/dotfiles/${tmpd}/.mutt ] && echo "not a directory" && exit 1 -[ ! -e ${tmps}/dotfiles/${tmpd}/.mutt/colors ] && echo "not exist" && exit 1 -[ ! -e ${tmps}/dotfiles/${tmpd}/.colors ] && echo "not exist (2)" && exit 1 +[ ! -d "${tmps}"/dotfiles/"${tmpd}"/.mutt ] && echo "not a directory" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/.mutt/colors ] && echo "not exist" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/.colors ] && echo "not exist (2)" && exit 1 -cat ${cfg} | grep ${tmpd}/.mutt/colors >/dev/null 2>&1 -cat ${cfg} | grep ${tmpd}/.colors >/dev/null 2>&1 +cat "${cfg}" | grep "${tmpd}"/.mutt/colors >/dev/null 2>&1 +cat "${cfg}" | grep "${tmpd}"/.colors >/dev/null 2>&1 echo "OK" exit 0 diff --git a/tests-ng/import-ignore.sh b/tests-ng/import-ignore.sh index ea571ef..82949d0 100755 --- a/tests-ng/import-ignore.sh +++ b/tests-ng/import-ignore.sh @@ -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,27 +57,27 @@ grep_or_fail() } # 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` -mkdir -p ${tmpd} +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmpd}" #echo "dotfile destination: ${tmpd}" clear_on_exit "${tmps}" clear_on_exit "${tmpd}" # dotdrop directory -mkdir -p ${tmpd}/a/{b,c} -echo 'a' > ${tmpd}/a/b/abfile -echo 'a' > ${tmpd}/a/c/acfile -echo 'a' > ${tmpd}/a/b/newfile -mkdir -p ${tmpd}/a/newdir -echo 'a' > ${tmpd}/a/newdir/newfile +mkdir -p "${tmpd}"/a/{b,c} +echo 'a' > "${tmpd}"/a/b/abfile +echo 'a' > "${tmpd}"/a/c/acfile +echo 'a' > "${tmpd}"/a/b/newfile +mkdir -p "${tmpd}"/a/newdir +echo 'a' > "${tmpd}"/a/newdir/newfile # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: false create: true @@ -90,11 +93,11 @@ _EOF # import echo "[+] import" -cd ${ddpath} | ${bin} import -c ${cfg} -f --verbose --profile=p1 ${tmpd}/a +cd "${ddpath}" | ${bin} import -c "${cfg}" -f --verbose --profile=p1 "${tmpd}"/a -[ -d ${tmps}/dotfiles/newdir ] && echo "newdir not ignored" && exit 1 -[ -e ${tmps}/dotfiles/newdir/newfile ] && echo "newfile not ignored" && exit 1 -[ -e ${tmps}/dotfiles/a/b/newfile ] && echo "newfile not ignored" && exit 1 +[ -d "${tmps}"/dotfiles/newdir ] && echo "newdir not ignored" && exit 1 +[ -e "${tmps}"/dotfiles/newdir/newfile ] && echo "newfile not ignored" && exit 1 +[ -e "${tmps}"/dotfiles/a/b/newfile ] && echo "newfile not ignored" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/import-include.sh b/tests-ng/import-include.sh index 0d0c2c4..848b5e1 100755 --- a/tests-ng/import-include.sh +++ b/tests-ng/import-include.sh @@ -27,43 +27,46 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" # create the dotfile to import -echo "file" > ${tmpd}/file +echo "file" > "${tmpd}"/file # create the dotfiles already imported -echo "already in" > ${tmps}/dotfiles/abc +echo "already in" > "${tmps}"/dotfiles/abc # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -80,22 +83,22 @@ profiles: dotfiles: - f_abc _EOF -cat ${cfg} +cat "${cfg}" -cnt=`cd ${ddpath} | ${bin} files -c ${cfg} -p p0 | grep '^f_' | wc -l` +cnt=$(cd "${ddpath}" | ${bin} files -c "${cfg}" -p p0 | grep '^f_' | wc -l) [ "${cnt}" != "1" ] && echo "this is bad" && exit 1 # import -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p0 --verbose ${tmpd}/file +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p0 --verbose "${tmpd}"/file -[ ! -e ${tmps}/dotfiles/${tmpd}/file ] && echo "file not imported" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/file ] && echo "file not imported" && exit 1 # make sure file is in -cnt=`cd ${ddpath} | ${bin} files -c ${cfg} -p p0 | grep '^f_file' | wc -l` +cnt=$(cd "${ddpath}" | ${bin} files -c "${cfg}" -p p0 | grep '^f_file' | wc -l) [ "${cnt}" != "1" ] && echo "dotfiles not in config" && exit 1 # count -cnt=`cd ${ddpath} | ${bin} files -c ${cfg} -p p0 -b | grep '^f_' | wc -l` +cnt=$(cd "${ddpath}" | ${bin} files -c "${cfg}" -p p0 -b | grep '^f_' | wc -l) [ "${cnt}" != "2" ] && echo "not enough dotfile" exit 1 echo "OK" diff --git a/tests-ng/import-link-children.sh b/tests-ng/import-link-children.sh index 7eccba5..7332333 100755 --- a/tests-ng/import-link-children.sh +++ b/tests-ng/import-link-children.sh @@ -32,7 +32,9 @@ ddpath="${cur}/../" 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}" @@ -40,7 +42,7 @@ echo "pythonpath: ${PYTHONPATH}" # get the 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 @@ -92,39 +94,39 @@ _EOF cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V --link=link_children ${dt} # check is set to link_children -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "d_`basename ${dt}`" | grep ',link:link_children,' +cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "d_`basename "${dt}"`" | grep ',link:link_children,' # checks file exists in dotpath -[ ! -e ${dotpath}/${dt} ] && echo "dotfile not imported" && exit 1 -[ ! -e ${dotpath}/${dtsub1} ] && echo "sub1 not found in dotpath" && exit 1 -[ ! -e ${dotpath}/${dtsub2} ] && echo "sub2 not found in dotpath" && exit 1 -[ ! -e ${dotpath}/${dtsub3} ] && echo "sub3 not found in dotpath" && exit 1 -[ ! -e ${dotpath}/${f1} ] && echo "f1 not found in dotpath" && exit 1 -[ ! -e ${dotpath}/${subf1} ] && echo "subf1 not found in dotpath" && exit 1 -[ ! -e ${dotpath}/${subf2} ] && echo "subf2 not found in dotpath" && exit 1 -[ ! -e ${dotpath}/${subf3} ] && echo "subf3 not found in dotpath" && exit 1 +[ ! -e "${dotpath}"/"${dt}" ] && echo "dotfile not imported" && exit 1 +[ ! -e "${dotpath}"/"${dtsub1}" ] && echo "sub1 not found in dotpath" && exit 1 +[ ! -e "${dotpath}"/"${dtsub2}" ] && echo "sub2 not found in dotpath" && exit 1 +[ ! -e "${dotpath}"/"${dtsub3}" ] && echo "sub3 not found in dotpath" && exit 1 +[ ! -e "${dotpath}"/"${f1}" ] && echo "f1 not found in dotpath" && exit 1 +[ ! -e "${dotpath}"/"${subf1}" ] && echo "subf1 not found in dotpath" && exit 1 +[ ! -e "${dotpath}"/"${subf2}" ] && echo "subf2 not found in dotpath" && exit 1 +[ ! -e "${dotpath}"/"${subf3}" ] && echo "subf3 not found in dotpath" && exit 1 # checks file exists in fs -[ ! -e ${dt} ] && echo "dotfile not imported" && exit 1 -[ ! -e ${dtsub1} ] && echo "sub1 not found in fs" && exit 1 -[ ! -e ${dtsub2} ] && echo "sub2 not found in fs" && exit 1 -[ ! -e ${dtsub3} ] && echo "sub3 not found in fs" && exit 1 -[ ! -e ${f1} ] && echo "f1 not found in fs" && exit 1 -[ ! -e ${subf1} ] && echo "subf1 not found in fs" && exit 1 -[ ! -e ${subf2} ] && echo "subf2 not found in fs" && exit 1 -[ ! -e ${subf3} ] && echo "subf3 not found in fs" && exit 1 +[ ! -e "${dt}" ] && echo "dotfile not imported" && exit 1 +[ ! -e "${dtsub1}" ] && echo "sub1 not found in fs" && exit 1 +[ ! -e "${dtsub2}" ] && echo "sub2 not found in fs" && exit 1 +[ ! -e "${dtsub3}" ] && echo "sub3 not found in fs" && exit 1 +[ ! -e "${f1}" ] && echo "f1 not found in fs" && exit 1 +[ ! -e "${subf1}" ] && echo "subf1 not found in fs" && exit 1 +[ ! -e "${subf2}" ] && echo "subf2 not found in fs" && exit 1 +[ ! -e "${subf3}" ] && echo "subf3 not found in fs" && exit 1 # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V # checks file have correct type in fs -[ ! -h ${f1} ] && echo "f1 is not a symlink" && exit 1 -[ -h ${subf1} ] && echo "subf1 is not a regular file" && exit 1 -[ -h ${subf2} ] && echo "subf2 is not a regular file" && exit 1 -[ -h ${subf3} ] && echo "subf3 is not a regular file" && exit 1 -[ ! -h ${dtsub1} ] && echo "dtsub1 is not a symlink" && exit 1 -[ ! -h ${dtsub2} ] && echo "dtsub2 is not a symlink" && exit 1 -[ -h ${dtsub3} ] && echo "dtsub3 is not a regular directory" && exit 1 +[ ! -h "${f1}" ] && echo "f1 is not a symlink" && exit 1 +[ -h "${subf1}" ] && echo "subf1 is not a regular file" && exit 1 +[ -h "${subf2}" ] && echo "subf2 is not a regular file" && exit 1 +[ -h "${subf3}" ] && echo "subf3 is not a regular file" && exit 1 +[ ! -h "${dtsub1}" ] && echo "dtsub1 is not a symlink" && exit 1 +[ ! -h "${dtsub2}" ] && echo "dtsub2 is not a symlink" && exit 1 +[ -h "${dtsub3}" ] && echo "dtsub3 is not a regular directory" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/import-negative-ignore.sh b/tests-ng/import-negative-ignore.sh index ff1c073..00ed4fc 100755 --- a/tests-ng/import-negative-ignore.sh +++ b/tests-ng/import-negative-ignore.sh @@ -9,41 +9,12 @@ set -e # all this crap to get current path -if [ $(uname) = Darwin ]; then - # Unfortunately, readlink works differently on macOS than it does on GNU/Linux - # (the -f option behaves differently) and the realpath command does not exist. - # Workarounds I find on the Internet suggest just using Homebrew to install coreutils - # so you can get the GNU coreutils on your Mac. But, I don't want this script to - # assume (a) users have Homebrew installed and (b) if they have Homebrew installed, that - # they then installed the GNU coreutils. - readlink() { - TARGET_FILE=$1 +rl="readlink -f" +if ! ${rl} "${0}" >/dev/null 2>&1; then + rl="realpath" - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - - # Iterate down a (possible) chain of symlinks - while [ -L "$TARGET_FILE" ]; do - TARGET_FILE=`readlink $TARGET_FILE` - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - done - - # Compute the canonicalized name by finding the physical path - # for the directory we're in and appending the target file. - PHYS_DIR=`pwd -P` - RESULT=$PHYS_DIR/$TARGET_FILE - echo $RESULT - } - rl="readlink" -else - rl="readlink -f" - if ! ${rl} "${0}" >/dev/null 2>&1; then - rl="realpath" - - if ! hash ${rl}; then - echo "\"${rl}\" not found !" && exit 1 - fi + if ! hash ${rl}; then + echo "\"${rl}\" not found !" && exit 1 fi fi cur=$(dirname "$(${rl} "${0}")") @@ -51,29 +22,32 @@ cur=$(dirname "$(${rl} "${0}")") # dotdrop path can be pass as argument ddpath="${cur}/../" [ -n "${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 -basedir=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` -mkdir -p ${basedir}/dotfiles +basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) +mkdir -p "${basedir}"/dotfiles # the dotfile destination -tmpd=`mkdir -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` +tmpd=$(mkdir -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" @@ -81,36 +55,36 @@ clear_on_exit "${tmpd}" # dotdrop directory echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" -mkdir -p ${tmpd}/a/{b,c} -echo 'a' > ${tmpd}/a/b/abfile1 -echo 'a' > ${tmpd}/a/b/abfile2 -echo 'a' > ${tmpd}/a/b/abfile3 -echo 'a' > ${tmpd}/a/c/acfile -mkdir -p ${tmpd}/a/newdir/b -touch ${tmpd}/a/newdir/b/{c,d} +mkdir -p "${tmpd}"/a/{b,c} +echo 'a' > "${tmpd}"/a/b/abfile1 +echo 'a' > "${tmpd}"/a/b/abfile2 +echo 'a' > "${tmpd}"/a/b/abfile3 +echo 'a' > "${tmpd}"/a/c/acfile +mkdir -p "${tmpd}"/a/newdir/b +touch "${tmpd}"/a/newdir/b/{c,d} # create the config file cfg="${basedir}/config.yaml" cfg2="${basedir}/config2.yaml" -create_conf ${cfg} # sets token +create_conf "${cfg}" # sets token sed '/dotpath: dotfiles/a\ \ \ impignore:\ \ \ \ \ - "*/newdir/b/*"\ \ \ \ \ - "!*/newdir/b/d"\ \ \ \ \ - "*/abfile?"\ \ \ \ \ - "!*/abfile3" -' ${cfg} > ${cfg2} +' "${cfg}" > "${cfg2}" # import echo "[+] import" -cd ${ddpath} | ${bin} import -f -c ${cfg2} --verbose --profile=p1 ${tmpd}/a --as=~/a +cd "${ddpath}" | ${bin} import -f -c "${cfg2}" --verbose --profile=p1 "${tmpd}"/a --as=~/a # check files haven't been imported -[ -e ${basedir}/dotfiles/a/newdir/b/c ] && echo "newdir/b/c should not have been imported" && exit 1 -[ ! -e ${basedir}/dotfiles/a/newdir/b/d ] && echo "newdir/b/d should have been imported" && exit 1 -[ -e ${basedir}/dotfiles/a/b/abfile1 ] && echo "abfile1 should not have been imported" && exit 1 -[ -e ${basedir}/dotfiles/a/b/abfile2 ] && echo "abfile2 should not have been imported" && exit 1 -[ ! -e ${basedir}/dotfiles/a/b/abfile3 ] && echo "abfile3 should have been imported" && exit 1 +[ -e "${basedir}"/dotfiles/a/newdir/b/c ] && echo "newdir/b/c should not have been imported" && exit 1 +[ ! -e "${basedir}"/dotfiles/a/newdir/b/d ] && echo "newdir/b/d should have been imported" && exit 1 +[ -e "${basedir}"/dotfiles/a/b/abfile1 ] && echo "abfile1 should not have been imported" && exit 1 +[ -e "${basedir}"/dotfiles/a/b/abfile2 ] && echo "abfile2 should not have been imported" && exit 1 +[ ! -e "${basedir}"/dotfiles/a/b/abfile3 ] && echo "abfile3 should have been imported" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/import-non-existing.sh b/tests-ng/import-non-existing.sh index 72b5e83..7868445 100755 --- a/tests-ng/import-non-existing.sh +++ b/tests-ng/import-non-existing.sh @@ -27,41 +27,44 @@ 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}" clear_on_exit "${tmps}" clear_on_exit "${tmpd}" # create the dotfile -echo "test" > ${tmps}/dotfiles/abc +echo "test" > "${tmps}"/dotfiles/abc # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -90,9 +93,9 @@ _EOF #cat ${cfg} # dummy call -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -111,11 +114,11 @@ _EOF # dummy call set +e -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V [ "$?" = "0" ] && echo "variables" && exit 1 set -e -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -134,11 +137,11 @@ _EOF # dummy call set +e -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V [ "$?" = "0" ] && echo "variables with separator" && exit 1 set -e -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -157,11 +160,11 @@ _EOF # dummy call set +e -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V [ "$?" = "0" ] && echo "variables glob" && exit 1 set -e -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -180,11 +183,11 @@ _EOF # dummy call set +e -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V [ "$?" = "0" ] && echo "actions" && exit 1 set -e -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -203,11 +206,11 @@ _EOF # dummy call set +e -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V [ "$?" = "0" ] && echo "actions with separator" && exit 1 set -e -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -226,11 +229,11 @@ _EOF # dummy call set +e -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V [ "$?" = "0" ] && echo "actions glob" && exit 1 set -e -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -249,11 +252,11 @@ _EOF # dummy call set +e -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V [ "$?" = "0" ] && echo "configs" && exit 1 set -e -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -272,11 +275,11 @@ _EOF # dummy call set +e -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V [ "$?" = "0" ] && echo "configs with separator" && exit 1 set -e -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -295,7 +298,7 @@ _EOF # dummy call set +e -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V [ "$?" = "0" ] && echo "configs glob" && exit 1 set -e diff --git a/tests-ng/import-profile-dotfiles.sh b/tests-ng/import-profile-dotfiles.sh index bfd6528..d97c8fc 100755 --- a/tests-ng/import-profile-dotfiles.sh +++ b/tests-ng/import-profile-dotfiles.sh @@ -28,29 +28,32 @@ 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) extdotfiles="${tmps}/df_p1.yaml" clear_on_exit "${tmps}" @@ -62,7 +65,7 @@ dynextdotfiles="${tmps}/ext_${dynextdotfiles_name}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -87,42 +90,42 @@ profiles: dotfiles: - f_abc import: - - $(basename ${extdotfiles}) + - $(basename "${extdotfiles}") - "ext_{{@@ d_uid @@}}" _EOF # create the external dotfile file -cat > ${extdotfiles} << _EOF +cat > "${extdotfiles}" << _EOF dotfiles: - f_def - f_xyz _EOF -cat > ${dynextdotfiles} << _EOF +cat > "${dynextdotfiles}" << _EOF dotfiles: - f_dyn _EOF # create the source -mkdir -p ${tmps}/dotfiles/ -echo "abc" > ${tmps}/dotfiles/abc -echo "def" > ${tmps}/dotfiles/def -echo "xyz" > ${tmps}/dotfiles/xyz -echo "dyn" > ${tmps}/dotfiles/dyn +mkdir -p "${tmps}"/dotfiles/ +echo "abc" > "${tmps}"/dotfiles/abc +echo "def" > "${tmps}"/dotfiles/def +echo "xyz" > "${tmps}"/dotfiles/xyz +echo "dyn" > "${tmps}"/dotfiles/dyn # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V # checks -[ ! -e ${tmpd}/abc ] && exit 1 -[ ! -e ${tmpd}/def ] && exit 1 -[ ! -e ${tmpd}/xyz ] && exit 1 -[ ! -e ${tmpd}/dyn ] && exit 1 +[ ! -e "${tmpd}"/abc ] && exit 1 +[ ! -e "${tmpd}"/def ] && exit 1 +[ ! -e "${tmpd}"/xyz ] && exit 1 +[ ! -e "${tmpd}"/dyn ] && exit 1 echo 'file found' -grep 'abc' ${tmpd}/abc >/dev/null 2>&1 -grep 'def' ${tmpd}/def >/dev/null 2>&1 -grep 'xyz' ${tmpd}/xyz >/dev/null 2>&1 -grep 'dyn' ${tmpd}/dyn >/dev/null 2>&1 +grep 'abc' "${tmpd}"/abc >/dev/null 2>&1 +grep 'def' "${tmpd}"/def >/dev/null 2>&1 +grep 'xyz' "${tmpd}"/xyz >/dev/null 2>&1 +grep 'dyn' "${tmpd}"/dyn >/dev/null 2>&1 echo "OK" exit 0 diff --git a/tests-ng/import-subfile.sh b/tests-ng/import-subfile.sh index 38a6c01..503591e 100755 --- a/tests-ng/import-subfile.sh +++ b/tests-ng/import-subfile.sh @@ -28,42 +28,45 @@ 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}" clear_on_exit "${tmps}" clear_on_exit "${tmpd}" # create the dotfile -mkdir -p ${tmpd}/adir -echo "first" > ${tmpd}/adir/file1 +mkdir -p "${tmpd}"/adir +echo "first" > "${tmpd}"/adir/file1 # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -74,18 +77,18 @@ _EOF #cat ${cfg} # import dir -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/adir +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/adir # change the file -echo "second" >> ${tmpd}/adir/file1 +echo "second" >> "${tmpd}"/adir/file1 # import file -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/adir/file1 +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/adir/file1 # test #cat ${tmps}/dotfiles/${tmpd}/adir/file1 -[ ! -e ${tmps}/dotfiles/${tmpd}/adir/file1 ] && echo "not exist" && exit 1 -grep 'second' ${tmps}/dotfiles/${tmpd}/adir/file1 >/dev/null +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/adir/file1 ] && echo "not exist" && exit 1 +grep 'second' "${tmps}"/dotfiles/"${tmpd}"/adir/file1 >/dev/null echo "OK" exit 0 diff --git a/tests-ng/import-to-no-profile.sh b/tests-ng/import-to-no-profile.sh index 1dbc3fa..e497fa8 100755 --- a/tests-ng/import-to-no-profile.sh +++ b/tests-ng/import-to-no-profile.sh @@ -27,42 +27,45 @@ 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}" clear_on_exit "${tmps}" clear_on_exit "${tmpd}" # create the dotfile -echo "file1" > ${tmpd}/file1 -echo "file2" > ${tmpd}/file2 +echo "file1" > "${tmpd}"/file1 +echo "file2" > "${tmpd}"/file2 # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -76,57 +79,57 @@ noprofile="ALL" ################################## # import with profile from arg -cd ${ddpath} | ${bin} import -f -c ${cfg} -p "${noprofile}" -V ${tmpd}/file1 -cat ${cfg} +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p "${noprofile}" -V "${tmpd}"/file1 +cat "${cfg}" # ensure exists and is not link -[ ! -e ${tmps}/dotfiles/${tmpd}/file1 ] && echo "file not imported" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/file1 ] && echo "file not imported" && exit 1 # ensure present in config -cat ${cfg} | grep ${tmpd}/file1 >/dev/null 2>&1 +cat "${cfg}" | grep "${tmpd}"/file1 >/dev/null 2>&1 -nb=`cat ${cfg} | grep f_file1 | wc -l` +nb=$(cat "${cfg}" | grep f_file1 | wc -l) [ "${nb}" != "1" ] && echo 'bad config' && exit 1 -cntpre=`find ${tmps}/dotfiles -type f | wc -l` +cntpre=$(find "${tmps}"/dotfiles -type f | wc -l) # reimport set +e -cd ${ddpath} | ${bin} import -f -c ${cfg} -p "${noprofile}" -V ${tmpd}/file1 +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p "${noprofile}" -V "${tmpd}"/file1 set -e -cat ${cfg} +cat "${cfg}" -cntpost=`find ${tmps}/dotfiles -type f | wc -l` +cntpost=$(find "${tmps}"/dotfiles -type f | wc -l) [ "${cntpost}" != "${cntpre}" ] && echo "imported twice" && exit 1 -nb=`cat ${cfg} | grep "dst: ${tmpd}/file1" | wc -l` +nb=$(cat "${cfg}" | grep "dst: ${tmpd}/file1" | wc -l) [ "${nb}" != "1" ] && echo 'imported twice in config' && exit 1 ################################## # import with profile from env export DOTDROP_PROFILE="${noprofile}" -cd ${ddpath} | ${bin} import -f -c ${cfg} -V ${tmpd}/file2 -cat ${cfg} +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -V "${tmpd}"/file2 +cat "${cfg}" # ensure exists and is not link -[ ! -e ${tmps}/dotfiles/${tmpd}/file2 ] && echo "file not imported" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/file2 ] && echo "file not imported" && exit 1 # ensure present in config -cat ${cfg} | grep ${tmpd}/file2 >/dev/null 2>&1 +cat "${cfg}" | grep "${tmpd}"/file2 >/dev/null 2>&1 -nb=`cat ${cfg} | grep f_file2 | wc -l` +nb=$(cat "${cfg}" | grep f_file2 | wc -l) [ "${nb}" != "1" ] && echo 'bad config' && exit 1 -cntpre=`find ${tmps}/dotfiles -type f | wc -l` +cntpre=$(find "${tmps}"/dotfiles -type f | wc -l) # reimport set +e -cd ${ddpath} | ${bin} import -f -c ${cfg} -V ${tmpd}/file2 +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -V "${tmpd}"/file2 set -e -cat ${cfg} +cat "${cfg}" -cntpost=`find ${tmps}/dotfiles -type f | wc -l` +cntpost=$(find "${tmps}"/dotfiles -type f | wc -l) [ "${cntpost}" != "${cntpre}" ] && echo "imported twice" && exit 1 -nb=`cat ${cfg} | grep "dst: ${tmpd}/file2" | wc -l` +nb=$(cat "${cfg}" | grep "dst: ${tmpd}/file2" | wc -l) [ "${nb}" != "1" ] && echo 'imported twice in config' && exit 1 echo "OK" diff --git a/tests-ng/import-with-empty.sh b/tests-ng/import-with-empty.sh index 73bd1f3..c0abee3 100755 --- a/tests-ng/import-with-empty.sh +++ b/tests-ng/import-with-empty.sh @@ -28,41 +28,44 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" # the temp directory -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # create a dotfile dftoimport="${tmpd}/a_dotfile" -echo 'some content' > ${dftoimport} +echo 'some content' > "${dftoimport}" # create the config file cfg="${basedir}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -96,15 +99,15 @@ profiles: _EOF echo "[+] import" -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 --verbose ${dftoimport} +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 --verbose "${dftoimport}" [ "$?" != "0" ] && exit 1 echo "[+] install" -cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 --verbose | grep '^5 dotfile(s) installed.$' -rm -f ${dftoimport} -cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 --verbose | grep '^6 dotfile(s) installed.$' +cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 --verbose | grep '^5 dotfile(s) installed.$' +rm -f "${dftoimport}" +cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 --verbose | grep '^6 dotfile(s) installed.$' -nb=`cd ${ddpath} | ${bin} files -c ${cfg} -p p1 --verbose | grep '^[a-zA-Z]' | grep -v '^Dotfile(s)' | wc -l` +nb=$(cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 --verbose | grep '^[a-zA-Z]' | grep -v '^Dotfile(s)' | wc -l) [ "${nb}" != "6" ] && echo "error in dotfile list (${nb} VS 6)" && exit 1 #cat ${cfg} diff --git a/tests-ng/import-with-trans.sh b/tests-ng/import-with-trans.sh index bcc26ea..ef9a1c2 100755 --- a/tests-ng/import-with-trans.sh +++ b/tests-ng/import-with-trans.sh @@ -29,30 +29,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 +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmps}"/dotfiles echo "dotfiles source (dotpath): ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" clear_on_exit "${tmps}" @@ -61,7 +64,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF trans_read: base64: "cat {0} | base64 -d > {1}" decompress: "mkdir -p {1} && tar -xf {0} -C {1}" @@ -85,10 +88,10 @@ tokend="compressed archive" tokenenc="encrypted" # create the dotfiles -echo ${token} > ${tmpd}/abc -mkdir -p ${tmpd}/def/a -echo ${tokend} > ${tmpd}/def/a/file -echo ${tokenenc} > ${tmpd}/ghi +echo ${token} > "${tmpd}"/abc +mkdir -p "${tmpd}"/def/a +echo "${tokend}" > "${tmpd}"/def/a/file +echo ${tokenenc} > "${tmpd}"/ghi ########################### # test import @@ -96,73 +99,73 @@ echo ${tokenenc} > ${tmpd}/ghi echo "[+] run import" # import file (to base64) -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -b -V --transw=base64 --transr=base64 ${tmpd}/abc +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -b -V --transw=base64 --transr=base64 "${tmpd}"/abc # import directory (to compress) -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -b -V --transw=compress --transr=decompress ${tmpd}/def +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -b -V --transw=compress --transr=decompress "${tmpd}"/def # import file (to encrypt) -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -b -V --transw=encrypt --transr=decrypt ${tmpd}/ghi +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -b -V --transw=encrypt --transr=decrypt "${tmpd}"/ghi # check file imported in dotpath -[ ! -e ${tmps}/dotfiles/${tmpd}/abc ] && echo "abc does not exist" && exit 1 -[ ! -e ${tmps}/dotfiles/${tmpd}/def ] && echo "def does not exist" && exit 1 -[ ! -e ${tmps}/dotfiles/${tmpd}/ghi ] && echo "ghi does not exist" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/abc ] && echo "abc does not exist" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/def ] && echo "def does not exist" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/ghi ] && echo "ghi does not exist" && exit 1 # check content in dotpath echo "checking content" -file ${tmps}/dotfiles/${tmpd}/abc | grep -i 'text' -cat ${tmpd}/abc | base64 > ${tmps}/test-abc -diff ${tmps}/dotfiles/${tmpd}/abc ${tmps}/test-abc +file "${tmps}"/dotfiles/"${tmpd}"/abc | grep -i 'text' +cat "${tmpd}"/abc | base64 > "${tmps}"/test-abc +diff "${tmps}"/dotfiles/"${tmpd}"/abc "${tmps}"/test-abc -file ${tmps}/dotfiles/${tmpd}/def | grep -i 'tar' -tar -cf ${tmps}/test-def -C ${tmpd}/def . -diff ${tmps}/dotfiles/${tmpd}/def ${tmps}/test-def +file "${tmps}"/dotfiles/"${tmpd}"/def | grep -i 'tar' +tar -cf "${tmps}"/test-def -C "${tmpd}"/def . +diff "${tmps}"/dotfiles/"${tmpd}"/def "${tmps}"/test-def -file ${tmps}/dotfiles/${tmpd}/ghi | grep -i 'gpg symmetrically encrypted data' -echo p1 | gpg -q --batch --yes --passphrase-fd 0 --no-tty -d ${tmps}/dotfiles/${tmpd}/ghi > ${tmps}/test-ghi -diff ${tmps}/test-ghi ${tmpd}/ghi +file "${tmps}"/dotfiles/"${tmpd}"/ghi | grep -i 'gpg symmetrically encrypted data' +echo p1 | gpg -q --batch --yes --passphrase-fd 0 --no-tty -d "${tmps}"/dotfiles/"${tmpd}"/ghi > "${tmps}"/test-ghi +diff "${tmps}"/test-ghi "${tmpd}"/ghi # check is imported in config echo "checking imported in config" -cd ${ddpath} | ${bin} -p p1 -c ${cfg} files -cd ${ddpath} | ${bin} -p p1 -c ${cfg} files | grep '^f_abc' -cd ${ddpath} | ${bin} -p p1 -c ${cfg} files | grep '^d_def' -cd ${ddpath} | ${bin} -p p1 -c ${cfg} files | grep '^f_ghi' +cd "${ddpath}" | ${bin} -p p1 -c "${cfg}" files +cd "${ddpath}" | ${bin} -p p1 -c "${cfg}" files | grep '^f_abc' +cd "${ddpath}" | ${bin} -p p1 -c "${cfg}" files | grep '^d_def' +cd "${ddpath}" | ${bin} -p p1 -c "${cfg}" files | grep '^f_ghi' # check has trans_write and trans_read in config echo "checking trans_write is set in config" echo "--------------" -cat ${cfg} +cat "${cfg}" echo "--------------" -cat ${cfg} | grep -A 4 'f_abc:' | grep 'trans_write: base64' -cat ${cfg} | grep -A 4 'd_def:' | grep 'trans_write: compress' -cat ${cfg} | grep -A 4 'f_ghi:' | grep 'trans_write: encrypt' +cat "${cfg}" | grep -A 4 'f_abc:' | grep 'trans_write: base64' +cat "${cfg}" | grep -A 4 'd_def:' | grep 'trans_write: compress' +cat "${cfg}" | grep -A 4 'f_ghi:' | grep 'trans_write: encrypt' -cat ${cfg} | grep -A 4 'f_abc:' | grep 'trans_read: base64' -cat ${cfg} | grep -A 4 'd_def:' | grep 'trans_read: decompress' -cat ${cfg} | grep -A 4 'f_ghi:' | grep 'trans_read: decrypt' +cat "${cfg}" | grep -A 4 'f_abc:' | grep 'trans_read: base64' +cat "${cfg}" | grep -A 4 'd_def:' | grep 'trans_read: decompress' +cat "${cfg}" | grep -A 4 'f_ghi:' | grep 'trans_read: decrypt' # install these echo "install and check" -rm ${tmpd}/abc -rm -r ${tmpd}/def -rm ${tmpd}/ghi +rm "${tmpd}"/abc +rm -r "${tmpd}"/def +rm "${tmpd}"/ghi -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V # test exist echo "check exist" -[ ! -e ${tmpd}/abc ] && exit 1 -[ ! -d ${tmpd}/def/a ] && exit 1 -[ ! -e ${tmpd}/def/a/file ] && exit 1 -[ ! -e ${tmpd}/ghi ] && exit 1 +[ ! -e "${tmpd}"/abc ] && exit 1 +[ ! -d "${tmpd}"/def/a ] && exit 1 +[ ! -e "${tmpd}"/def/a/file ] && exit 1 +[ ! -e "${tmpd}"/ghi ] && exit 1 # test content echo "check content" -cat ${tmpd}/abc -cat ${tmpd}/abc | grep "${token}" -cat ${tmpd}/def/a/file -cat ${tmpd}/def/a/file | grep "${tokend}" -cat ${tmpd}/ghi | grep "${tokenenc}" +cat "${tmpd}"/abc +cat "${tmpd}"/abc | grep "${token}" +cat "${tmpd}"/def/a/file +cat "${tmpd}"/def/a/file | grep "${tokend}" +cat "${tmpd}"/ghi | grep "${tokenenc}" echo "OK" exit 0 diff --git a/tests-ng/import.sh b/tests-ng/import.sh index e6ffb92..c4a70fa 100755 --- a/tests-ng/import.sh +++ b/tests-ng/import.sh @@ -27,44 +27,47 @@ 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}" clear_on_exit "${tmps}" clear_on_exit "${tmpd}" # create the dotfile -mkdir -p ${tmpd}/adir -echo "adir/file1" > ${tmpd}/adir/file1 -echo "adir/fil2" > ${tmpd}/adir/file2 -echo "file3" > ${tmpd}/file3 +mkdir -p "${tmpd}"/adir +echo "adir/file1" > "${tmpd}"/adir/file1 +echo "adir/fil2" > "${tmpd}"/adir/file2 +echo "file3" > "${tmpd}"/file3 # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -75,39 +78,39 @@ _EOF #cat ${cfg} # import -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/adir -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/file3 +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/adir +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/file3 -cat ${cfg} +cat "${cfg}" # ensure exists and is not link -[ ! -d ${tmps}/dotfiles/${tmpd}/adir ] && echo "not a directory" && exit 1 -[ ! -e ${tmps}/dotfiles/${tmpd}/adir/file1 ] && echo "not exist" && exit 1 -[ ! -e ${tmps}/dotfiles/${tmpd}/adir/file2 ] && echo "not exist" && exit 1 -[ ! -e ${tmps}/dotfiles/${tmpd}/file3 ] && echo "not a file" && exit 1 +[ ! -d "${tmps}"/dotfiles/"${tmpd}"/adir ] && echo "not a directory" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/adir/file1 ] && echo "not exist" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/adir/file2 ] && echo "not exist" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/file3 ] && echo "not a file" && exit 1 -cat ${cfg} | grep ${tmpd}/adir >/dev/null 2>&1 -cat ${cfg} | grep ${tmpd}/file3 >/dev/null 2>&1 +cat "${cfg}" | grep "${tmpd}"/adir >/dev/null 2>&1 +cat "${cfg}" | grep "${tmpd}"/file3 >/dev/null 2>&1 -nb=`cat ${cfg} | grep d_adir | wc -l` +nb=$(cat "${cfg}" | grep d_adir | wc -l) [ "${nb}" != "2" ] && echo 'bad config1' && exit 1 -nb=`cat ${cfg} | grep f_file3 | wc -l` +nb=$(cat "${cfg}" | grep f_file3 | wc -l) [ "${nb}" != "2" ] && echo 'bad config2' && exit 1 -cntpre=`find ${tmps}/dotfiles -type f | wc -l` +cntpre=$(find "${tmps}"/dotfiles -type f | wc -l) # reimport -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/adir -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/file3 +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/adir +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/file3 -cntpost=`find ${tmps}/dotfiles -type f | wc -l` +cntpost=$(find "${tmps}"/dotfiles -type f | wc -l) [ "${cntpost}" != "${cntpre}" ] && echo "import issue" && exit 1 ####################################### # import directory with named pipe -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -118,20 +121,20 @@ _EOF # create the dotfile d="${tmpd}/with_named_pipe" -mkdir -p ${d} -echo "file1" > ${d}/file1 -echo "fil2" > ${d}/file2 -mkfifo ${d}/fifo +mkdir -p "${d}" +echo "file1" > "${d}"/file1 +echo "fil2" > "${d}"/file2 +mkfifo "${d}"/fifo # import -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p2 -V ${d} +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p2 -V "${d}" # ensure exists and is not link -[ ! -d ${tmps}/dotfiles/${d} ] && echo "not a directory" && exit 1 -[ ! -e ${tmps}/dotfiles/${d}/file1 ] && echo "not exist" && exit 1 -[ ! -e ${tmps}/dotfiles/${d}/file2 ] && echo "not exist" && exit 1 +[ ! -d "${tmps}"/dotfiles/"${d}" ] && echo "not a directory" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${d}"/file1 ] && echo "not exist" && exit 1 +[ ! -e "${tmps}"/dotfiles/"${d}"/file2 ] && echo "not exist" && exit 1 -cat ${cfg} | grep ${d} >/dev/null 2>&1 +cat "${cfg}" | grep "${d}" >/dev/null 2>&1 echo "OK" exit 0 diff --git a/tests-ng/imported-configs-variables.sh b/tests-ng/imported-configs-variables.sh index 55093c6..b89d340 100755 --- a/tests-ng/imported-configs-variables.sh +++ b/tests-ng/imported-configs-variables.sh @@ -28,29 +28,32 @@ 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}" clear_on_exit "${tmps}" @@ -59,13 +62,13 @@ clear_on_exit "${tmpd}" # create the config file extcfg="${tmps}/ext-config.yaml" cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true dotpath: dotfiles import_configs: - - $(basename ${extcfg}) + - $(basename "${extcfg}") variables: varx: "test" provar: "local" @@ -87,10 +90,10 @@ profiles: dvarx: echo dprofvarx dprovar: echo dprovar _EOF -cat ${cfg} +cat "${cfg}" # create the external variables file -cat > ${extcfg} << _EOF +cat > "${extcfg}" << _EOF config: profiles: p2: @@ -104,36 +107,36 @@ profiles: dprovar: echo extdprovar dotfiles: _EOF -ls -l ${extcfg} -cat ${extcfg} +ls -l "${extcfg}" +cat "${extcfg}" # create the dotfile -echo "varx: {{@@ varx @@}}" > ${tmps}/dotfiles/abc -echo "provar: {{@@ provar @@}}" >> ${tmps}/dotfiles/abc -echo "dvarx: {{@@ dvarx @@}}" >> ${tmps}/dotfiles/abc -echo "dprovar: {{@@ dprovar@@}}" >> ${tmps}/dotfiles/abc +echo "varx: {{@@ varx @@}}" > "${tmps}"/dotfiles/abc +echo "provar: {{@@ provar @@}}" >> "${tmps}"/dotfiles/abc +echo "dvarx: {{@@ dvarx @@}}" >> "${tmps}"/dotfiles/abc +echo "dprovar: {{@@ dprovar@@}}" >> "${tmps}"/dotfiles/abc #cat ${tmps}/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p2 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p2 -V echo "test1" -cat ${tmpd}/abc -grep '^varx: extprofvarx' ${tmpd}/abc >/dev/null -grep '^provar: extprovar' ${tmpd}/abc >/dev/null -grep '^dvarx: extdprofvarx' ${tmpd}/abc >/dev/null -grep '^dprovar: extdprovar' ${tmpd}/abc >/dev/null +cat "${tmpd}"/abc +grep '^varx: extprofvarx' "${tmpd}"/abc >/dev/null +grep '^provar: extprovar' "${tmpd}"/abc >/dev/null +grep '^dvarx: extdprofvarx' "${tmpd}"/abc >/dev/null +grep '^dprovar: extdprovar' "${tmpd}"/abc >/dev/null -rm -f ${tmpd}/abc -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +rm -f "${tmpd}"/abc +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V echo "test2" -cat ${tmpd}/abc -grep '^varx: profvarx' ${tmpd}/abc >/dev/null -grep '^provar: provar' ${tmpd}/abc >/dev/null -grep '^dvarx: dprofvarx' ${tmpd}/abc >/dev/null -grep '^dprovar: dprovar' ${tmpd}/abc >/dev/null +cat "${tmpd}"/abc +grep '^varx: profvarx' "${tmpd}"/abc >/dev/null +grep '^provar: provar' "${tmpd}"/abc >/dev/null +grep '^dvarx: dprofvarx' "${tmpd}"/abc >/dev/null +grep '^dprovar: dprovar' "${tmpd}"/abc >/dev/null echo "OK" exit 0 diff --git a/tests-ng/imported-variables-from-config.sh b/tests-ng/imported-variables-from-config.sh index 2cf6c88..c29fae8 100755 --- a/tests-ng/imported-variables-from-config.sh +++ b/tests-ng/imported-variables-from-config.sh @@ -28,29 +28,32 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -59,7 +62,7 @@ clear_on_exit "${tmpd}" cfg="${tmps}/config.yaml" subcfg="${tmps}/subconfig.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -75,10 +78,10 @@ profiles: dotfiles: - f_abc _EOF -cat ${cfg} +cat "${cfg}" # create the subconfig file -cat > ${subcfg} << _EOF +cat > "${subcfg}" << _EOF config: backup: true create: true @@ -92,13 +95,13 @@ profiles: [] _EOF # create the dotfile -dirname ${tmps}/dotfiles/abc | xargs mkdir -p -cat > ${tmps}/dotfiles/abc << _EOF +dirname "${tmps}"/dotfiles/abc | xargs mkdir -p +cat > "${tmps}"/dotfiles/abc << _EOF Hell yeah _EOF # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V # test file existence and content [ -f "${tmpd}/abc" ] || { diff --git a/tests-ng/include-actions.sh b/tests-ng/include-actions.sh index ffd4e36..42d077d 100755 --- a/tests-ng/include-actions.sh +++ b/tests-ng/include-actions.sh @@ -29,31 +29,34 @@ 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) # the action 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}" @@ -62,7 +65,7 @@ clear_on_exit "${tmpa}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF actions: pre: preaction: echo 'pre' >> ${tmpa}/pre @@ -103,109 +106,109 @@ profiles: _EOF # create the source -mkdir -p ${tmps}/dotfiles/ -echo "test" > ${tmps}/dotfiles/abc +mkdir -p "${tmps}"/dotfiles/ +echo "test" > "${tmps}"/dotfiles/abc # install echo "PROFILE p2" -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p2 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p2 -V # checks -[ ! -e ${tmpa}/pre ] && echo "pre not found" && exit 1 -nb=`wc -l ${tmpa}/pre | awk '{print $1}'` +[ ! -e "${tmpa}"/pre ] && echo "pre not found" && exit 1 +nb=$(wc -l "${tmpa}"/pre | awk '{print $1}') [ "${nb}" != "1" ] && echo "pre executed multiple times" && exit 1 -[ ! -e ${tmpa}/pre2 ] && echo "pre2 not found" && exit 1 -nb=`wc -l ${tmpa}/pre2 | awk '{print $1}'` +[ ! -e "${tmpa}"/pre2 ] && echo "pre2 not found" && exit 1 +nb=$(wc -l "${tmpa}"/pre2 | awk '{print $1}') [ "${nb}" != "1" ] && echo "pre2 executed multiple times" && exit 1 -[ ! -e ${tmpa}/post ] && echo "post not found" && exit 1 -nb=`wc -l ${tmpa}/post | awk '{print $1}'` +[ ! -e "${tmpa}"/post ] && echo "post not found" && exit 1 +nb=$(wc -l "${tmpa}"/post | awk '{print $1}') [ "${nb}" != "1" ] && echo "post executed multiple times" && exit 1 -[ ! -e ${tmpa}/post2 ] && echo "post2 not found" && exit 1 -nb=`wc -l ${tmpa}/post2 | awk '{print $1}'` +[ ! -e "${tmpa}"/post2 ] && echo "post2 not found" && exit 1 +nb=$(wc -l "${tmpa}"/post2 | awk '{print $1}') [ "${nb}" != "1" ] && echo "post2 executed multiple times" && exit 1 # install -rm -f ${tmpa}/pre ${tmpa}/pre2 ${tmpa}/post ${tmpa}/post2 ${tmpa}/naked -rm -f ${tmpd}/abc +rm -f "${tmpa}"/pre "${tmpa}"/pre2 "${tmpa}"/post "${tmpa}"/post2 "${tmpa}"/naked +rm -f "${tmpd}"/abc echo "PROFILE p3" -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p3 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p3 -V # checks -[ ! -e ${tmpa}/pre ] && echo "pre not found" && exit 1 -nb=`wc -l ${tmpa}/pre | awk '{print $1}'` +[ ! -e "${tmpa}"/pre ] && echo "pre not found" && exit 1 +nb=$(wc -l "${tmpa}"/pre | awk '{print $1}') [ "${nb}" != "1" ] && echo "pre executed multiple times" && exit 1 -[ ! -e ${tmpa}/pre2 ] && echo "pre2 not found" && exit 1 -nb=`wc -l ${tmpa}/pre2 | awk '{print $1}'` +[ ! -e "${tmpa}"/pre2 ] && echo "pre2 not found" && exit 1 +nb=$(wc -l "${tmpa}"/pre2 | awk '{print $1}') [ "${nb}" != "1" ] && echo "pre2 executed multiple times" && exit 1 -[ ! -e ${tmpa}/post ] && echo "post not found" && exit 1 -nb=`wc -l ${tmpa}/post | awk '{print $1}'` +[ ! -e "${tmpa}"/post ] && echo "post not found" && exit 1 +nb=$(wc -l "${tmpa}"/post | awk '{print $1}') [ "${nb}" != "1" ] && echo "post executed multiple times" && exit 1 -[ ! -e ${tmpa}/post2 ] && echo "post2 not found" && exit 1 -nb=`wc -l ${tmpa}/post2 | awk '{print $1}'` +[ ! -e "${tmpa}"/post2 ] && echo "post2 not found" && exit 1 +nb=$(wc -l "${tmpa}"/post2 | awk '{print $1}') [ "${nb}" != "1" ] && echo "post2 executed multiple times" && exit 1 -[ ! -e ${tmpa}/naked ] && echo "naked not found" && exit 1 -nb=`wc -l ${tmpa}/naked | awk '{print $1}'` +[ ! -e "${tmpa}"/naked ] && echo "naked not found" && exit 1 +nb=$(wc -l "${tmpa}"/naked | awk '{print $1}') [ "${nb}" != "1" ] && echo "naked executed multiple times" && exit 1 # install -rm -f ${tmpa}/pre ${tmpa}/pre2 ${tmpa}/post ${tmpa}/post2 ${tmpa}/naked -rm -f ${tmpd}/abc +rm -f "${tmpa}"/pre "${tmpa}"/pre2 "${tmpa}"/post "${tmpa}"/post2 "${tmpa}"/naked +rm -f "${tmpd}"/abc echo "PROFILE p0" -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p0 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p0 -V # checks -[ ! -e ${tmpa}/pre ] && echo "pre not found" && exit 1 -nb=`wc -l ${tmpa}/pre | awk '{print $1}'` +[ ! -e "${tmpa}"/pre ] && echo "pre not found" && exit 1 +nb=$(wc -l "${tmpa}"/pre | awk '{print $1}') [ "${nb}" != "1" ] && echo "pre executed multiple times" && exit 1 -[ ! -e ${tmpa}/pre2 ] && echo "pre2 not found" && exit 1 -nb=`wc -l ${tmpa}/pre2 | awk '{print $1}'` +[ ! -e "${tmpa}"/pre2 ] && echo "pre2 not found" && exit 1 +nb=$(wc -l "${tmpa}"/pre2 | awk '{print $1}') [ "${nb}" != "1" ] && echo "pre2 executed multiple times" && exit 1 -[ ! -e ${tmpa}/post ] && echo "post not found" && exit 1 -nb=`wc -l ${tmpa}/post | awk '{print $1}'` +[ ! -e "${tmpa}"/post ] && echo "post not found" && exit 1 +nb=$(wc -l "${tmpa}"/post | awk '{print $1}') [ "${nb}" != "1" ] && echo "post executed multiple times" && exit 1 -[ ! -e ${tmpa}/post2 ] && echo "post2 not found" && exit 1 -nb=`wc -l ${tmpa}/post2 | awk '{print $1}'` +[ ! -e "${tmpa}"/post2 ] && echo "post2 not found" && exit 1 +nb=$(wc -l "${tmpa}"/post2 | awk '{print $1}') [ "${nb}" != "1" ] && echo "post2 executed multiple times" && exit 1 -[ ! -e ${tmpa}/naked ] && echo "naked not found" && exit 1 -nb=`wc -l ${tmpa}/naked | awk '{print $1}'` +[ ! -e "${tmpa}"/naked ] && echo "naked not found" && exit 1 +nb=$(wc -l "${tmpa}"/naked | awk '{print $1}') [ "${nb}" != "1" ] && echo "naked executed multiple times" && exit 1 # install without verbose -rm -f ${tmpa}/pre ${tmpa}/pre2 ${tmpa}/post ${tmpa}/post2 ${tmpa}/naked -rm -f ${tmpd}/abc +rm -f "${tmpa}"/pre "${tmpa}"/pre2 "${tmpa}"/post "${tmpa}"/post2 "${tmpa}"/naked +rm -f "${tmpd}"/abc echo "PROFILE p0 without verbose" -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p0 +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p0 # checks -[ ! -e ${tmpa}/pre ] && echo "pre not found" && exit 1 -nb=`wc -l ${tmpa}/pre | awk '{print $1}'` +[ ! -e "${tmpa}"/pre ] && echo "pre not found" && exit 1 +nb=$(wc -l "${tmpa}"/pre | awk '{print $1}') [ "${nb}" != "1" ] && echo "pre executed multiple times" && exit 1 -[ ! -e ${tmpa}/pre2 ] && echo "pre2 not found" && exit 1 -nb=`wc -l ${tmpa}/pre2 | awk '{print $1}'` +[ ! -e "${tmpa}"/pre2 ] && echo "pre2 not found" && exit 1 +nb=$(wc -l "${tmpa}"/pre2 | awk '{print $1}') [ "${nb}" != "1" ] && echo "pre2 executed multiple times" && exit 1 -[ ! -e ${tmpa}/post ] && echo "post not found" && exit 1 -nb=`wc -l ${tmpa}/post | awk '{print $1}'` +[ ! -e "${tmpa}"/post ] && echo "post not found" && exit 1 +nb=$(wc -l "${tmpa}"/post | awk '{print $1}') [ "${nb}" != "1" ] && echo "post executed multiple times" && exit 1 -[ ! -e ${tmpa}/post2 ] && echo "post2 not found" && exit 1 -nb=`wc -l ${tmpa}/post2 | awk '{print $1}'` +[ ! -e "${tmpa}"/post2 ] && echo "post2 not found" && exit 1 +nb=$(wc -l "${tmpa}"/post2 | awk '{print $1}') [ "${nb}" != "1" ] && echo "post2 executed multiple times" && exit 1 -[ ! -e ${tmpa}/naked ] && echo "naked not found" && exit 1 -nb=`wc -l ${tmpa}/naked | awk '{print $1}'` +[ ! -e "${tmpa}"/naked ] && echo "naked not found" && exit 1 +nb=$(wc -l "${tmpa}"/naked | awk '{print $1}') [ "${nb}" != "1" ] && echo "naked executed multiple times" && exit 1 echo "OK" diff --git a/tests-ng/include-order.sh b/tests-ng/include-order.sh index 60978d1..ec27bd2 100755 --- a/tests-ng/include-order.sh +++ b/tests-ng/include-order.sh @@ -29,31 +29,34 @@ 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) # temporary -tmpa=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpa=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -63,7 +66,7 @@ export DOTDROP_WORKERS=1 # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -105,24 +108,24 @@ profiles: _EOF # create the source -mkdir -p ${tmps}/dotfiles/ -echo "first" > ${tmps}/dotfiles/first -echo "second" > ${tmps}/dotfiles/second -echo "third" > ${tmps}/dotfiles/third +mkdir -p "${tmps}"/dotfiles/ +echo "first" > "${tmps}"/dotfiles/first +echo "second" > "${tmps}"/dotfiles/second +echo "third" > "${tmps}"/dotfiles/third attempts="3" for ((i=0;i<${attempts};i++)); do # install - cd ${ddpath} | ${bin} install -w 1 -f -c ${cfg} -p p0 -V + cd "${ddpath}" | ${bin} install -w 1 -f -c "${cfg}" -p p0 -V # checks timestamp - echo "first timestamp: `stat -c %y ${tmpd}/first`" - echo "second timestamp: `stat -c %y ${tmpd}/second`" - echo "third timestamp: `stat -c %y ${tmpd}/third`" + echo "first timestamp: $(stat -c %y "${tmpd}"/first)" + echo "second timestamp: $(stat -c %y "${tmpd}"/second)" + echo "third timestamp: $(stat -c %y "${tmpd}"/third)" - ts_first=`date "+%s" -d "$(stat -c %y ${tmpd}/first)"` - ts_second=`date "+%s" -d "$(stat -c %y ${tmpd}/second)"` - ts_third=`date "+%s" -d "$(stat -c %y ${tmpd}/third)"` + ts_first=$(date "+%s" -d "$(stat -c %y "${tmpd}"/first)") + ts_second=$(date "+%s" -d "$(stat -c %y "${tmpd}"/second)") + ts_third=$(date "+%s" -d "$(stat -c %y "${tmpd}"/third)") #echo "first ts: ${ts_first}" #echo "second ts: ${ts_second}" @@ -132,13 +135,13 @@ for ((i=0;i<${attempts};i++)); do [ "${ts_second}" -ge "${ts_third}" ] && echo "third created before second" && exit 1 # check cookie - cat ${tmpa}/cookie - content=`cat ${tmpa}/cookie | xargs` + cat "${tmpa}"/cookie + content=$(cat "${tmpa}"/cookie | xargs) [ "${content}" != "first second third" ] && echo "bad cookie" && exit 1 # clean - rm ${tmpa}/cookie - rm ${tmpd}/first ${tmpd}/second ${tmpd}/third + rm "${tmpa}"/cookie + rm "${tmpd}"/first "${tmpd}"/second "${tmpd}"/third done echo "OK" diff --git a/tests-ng/include-variables.sh b/tests-ng/include-variables.sh index 98919a7..a6df34e 100755 --- a/tests-ng/include-variables.sh +++ b/tests-ng/include-variables.sh @@ -29,29 +29,32 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -59,7 +62,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -91,18 +94,18 @@ _EOF #cat ${cfg} # create the source -mkdir -p ${tmps}/dotfiles/ -echo "head" > ${tmps}/dotfiles/abc -echo "{{@@ var @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ dvar @@}}" >> ${tmps}/dotfiles/abc -echo "tail" >> ${tmps}/dotfiles/abc +mkdir -p "${tmps}"/dotfiles/ +echo "head" > "${tmps}"/dotfiles/abc +echo "{{@@ var @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ dvar @@}}" >> "${tmps}"/dotfiles/abc +echo "tail" >> "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p0 --verbose +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p0 --verbose #cat ${tmpd}/abc -grep 'p0v' ${tmpd}/abc -grep 'p0dv' ${tmpd}/abc +grep 'p0v' "${tmpd}"/abc +grep 'p0dv' "${tmpd}"/abc echo "OK" exit 0 diff --git a/tests-ng/include.sh b/tests-ng/include.sh index 069b989..0068fdb 100755 --- a/tests-ng/include.sh +++ b/tests-ng/include.sh @@ -28,29 +28,32 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -58,7 +61,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -89,35 +92,35 @@ profiles: include: - p2 _EOF -cat ${cfg} +cat "${cfg}" # create the source -mkdir -p ${tmps}/dotfiles/ -echo "test" > ${tmps}/dotfiles/abc +mkdir -p "${tmps}"/dotfiles/ +echo "test" > "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p0 --verbose +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p0 --verbose -[ ! -e ${tmpd}/action.pre ] && exit 1 -[ ! -e ${tmpd}/action.post ] && exit 1 +[ ! -e "${tmpd}"/action.pre ] && exit 1 +[ ! -e "${tmpd}"/action.post ] && exit 1 # compare -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 -cd ${ddpath} | ${bin} compare -c ${cfg} -p p2 -cd ${ddpath} | ${bin} compare -c ${cfg} -p p3 -cd ${ddpath} | ${bin} compare -c ${cfg} -p p0 +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p2 +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p3 +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p0 # list -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 | grep f_abc -cd ${ddpath} | ${bin} files -c ${cfg} -p p2 | grep f_abc -cd ${ddpath} | ${bin} files -c ${cfg} -p p3 | grep f_abc -cd ${ddpath} | ${bin} files -c ${cfg} -p p0 | grep f_abc +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 | grep f_abc +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p2 | grep f_abc +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p3 | grep f_abc +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p0 | grep f_abc -cnt=`cd ${ddpath} | ${bin} files -c ${cfg} -p p0 | grep f_abc | wc -l` +cnt=$(cd "${ddpath}" | ${bin} files -c "${cfg}" -p p0 | grep f_abc | wc -l) [ "${cnt}" != "1" ] && echo "dotfiles displayed more than once" && exit 1 # count -cnt=`cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -b | grep '^f_' | wc -l` +cnt=$(cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -b | grep '^f_' | wc -l) [ "${cnt}" != "1" ] && exit 1 echo "OK" diff --git a/tests-ng/inst-link-default.sh b/tests-ng/inst-link-default.sh index 200eb5e..eb0628f 100755 --- a/tests-ng/inst-link-default.sh +++ b/tests-ng/inst-link-default.sh @@ -28,45 +28,48 @@ 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}" clear_on_exit "${tmps}" clear_on_exit "${tmpd}" # create the dotfile -mkdir -p ${tmps}/dotfiles/abc -echo "test link_dotfile_default 1" > ${tmps}/dotfiles/abc/file1 -echo "test link_dotfile_default 2" > ${tmps}/dotfiles/abc/file2 -echo "should be linked" > ${tmps}/dotfiles/def +mkdir -p "${tmps}"/dotfiles/abc +echo "test link_dotfile_default 1" > "${tmps}"/dotfiles/abc/file1 +echo "test link_dotfile_default 2" > "${tmps}"/dotfiles/abc/file2 +echo "should be linked" > "${tmps}"/dotfiles/def # create a shell script # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -84,19 +87,19 @@ _EOF #cat ${cfg} # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V #cat ${cfg} # ensure exists and is not link -[ ! -d ${tmpd}/abc ] && echo "not a directory" && exit 1 -[ -h ${tmpd}/abc ] && echo "not a regular file" && exit 1 -[ ! -e ${tmpd}/abc/file1 ] && echo "not exist" && exit 1 -[ -h ${tmpd}/abc/file1 ] && echo "not a regular file" && exit 1 -[ ! -e ${tmpd}/abc/file2 ] && echo "not exist" && exit 1 -[ -h ${tmpd}/abc/file2 ] && echo "not a regular file" && exit 1 -rm -rf ${tmpd}/abc +[ ! -d "${tmpd}"/abc ] && echo "not a directory" && exit 1 +[ -h "${tmpd}"/abc ] && echo "not a regular file" && exit 1 +[ ! -e "${tmpd}"/abc/file1 ] && echo "not exist" && exit 1 +[ -h "${tmpd}"/abc/file1 ] && echo "not a regular file" && exit 1 +[ ! -e "${tmpd}"/abc/file2 ] && echo "not exist" && exit 1 +[ -h "${tmpd}"/abc/file2 ] && echo "not a regular file" && exit 1 +rm -rf "${tmpd}"/abc -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -117,23 +120,23 @@ profiles: _EOF # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V #cat ${cfg} # ensure exists and parent is a link -[ ! -e ${tmpd}/abc ] && echo "not exist" && exit 1 -[ ! -h ${tmpd}/abc ] && echo "not a symlink" && exit 1 -[ ! -e ${tmpd}/abc/file1 ] && echo "not exist" && exit 1 -[ -h ${tmpd}/abc/file1 ] && echo "not a regular file" && exit 1 -[ ! -e ${tmpd}/abc/file2 ] && echo "not exist" && exit 1 -[ -h ${tmpd}/abc/file2 ] && echo "not a regular file" && exit 1 -rm -rf ${tmpd}/abc +[ ! -e "${tmpd}"/abc ] && echo "not exist" && exit 1 +[ ! -h "${tmpd}"/abc ] && echo "not a symlink" && exit 1 +[ ! -e "${tmpd}"/abc/file1 ] && echo "not exist" && exit 1 +[ -h "${tmpd}"/abc/file1 ] && echo "not a regular file" && exit 1 +[ ! -e "${tmpd}"/abc/file2 ] && echo "not exist" && exit 1 +[ -h "${tmpd}"/abc/file2 ] && echo "not a regular file" && exit 1 +rm -rf "${tmpd}"/abc -[ ! -e ${tmpd}/def ] && echo "not exist" && exit 1 -[ ! -h ${tmpd}/def ] && echo "not a symlink" && exit 1 -rm -f ${tmpd}/def +[ ! -e "${tmpd}"/def ] && echo "not exist" && exit 1 +[ ! -h "${tmpd}"/def ] && echo "not a symlink" && exit 1 +rm -f "${tmpd}"/def -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -150,17 +153,17 @@ profiles: _EOF # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V #cat ${cfg} # ensure exists and children are links -[ ! -e ${tmpd}/abc ] && echo "not exist" && exit 1 -[ -h ${tmpd}/abc ] && echo "not a regular file" && exit 1 -[ ! -e ${tmpd}/abc/file1 ] && echo "not exist" && exit 1 -[ ! -h ${tmpd}/abc/file1 ] && echo "not a symlink" && exit 1 -[ ! -e ${tmpd}/abc/file2 ] && echo "not exist" && exit 1 -[ ! -h ${tmpd}/abc/file2 ] && echo "not a symlink" && exit 1 -rm -rf ${tmpd}/abc +[ ! -e "${tmpd}"/abc ] && echo "not exist" && exit 1 +[ -h "${tmpd}"/abc ] && echo "not a regular file" && exit 1 +[ ! -e "${tmpd}"/abc/file1 ] && echo "not exist" && exit 1 +[ ! -h "${tmpd}"/abc/file1 ] && echo "not a symlink" && exit 1 +[ ! -e "${tmpd}"/abc/file2 ] && echo "not exist" && exit 1 +[ ! -h "${tmpd}"/abc/file2 ] && echo "not a symlink" && exit 1 +rm -rf "${tmpd}"/abc echo "OK" exit 0 diff --git a/tests-ng/install-empty.sh b/tests-ng/install-empty.sh index 34ce1c9..377789a 100755 --- a/tests-ng/install-empty.sh +++ b/tests-ng/install-empty.sh @@ -28,26 +28,29 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" @@ -55,7 +58,7 @@ clear_on_exit "${basedir}" # create the config file cfg="${basedir}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -89,7 +92,7 @@ profiles: _EOF echo "[+] install" -cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 --verbose | grep '^5 dotfile(s) installed.$' +cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 --verbose | grep '^5 dotfile(s) installed.$' [ "$?" != "0" ] && exit 1 echo "OK" diff --git a/tests-ng/install-ignore.sh b/tests-ng/install-ignore.sh index 3395f8d..5011a7c 100755 --- a/tests-ng/install-ignore.sh +++ b/tests-ng/install-ignore.sh @@ -28,105 +28,108 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" # the dotfile to be imported -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) tmps="${basedir}" clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # some files -mkdir -p ${tmpd}/{program,config,vscode} -echo "some data" > ${tmpd}/program/a -echo "some data" > ${tmpd}/config/a -echo "some data" > ${tmpd}/vscode/extensions.txt -echo "some data" > ${tmpd}/vscode/keybindings.json +mkdir -p "${tmpd}"/{program,config,vscode} +echo "some data" > "${tmpd}"/program/a +echo "some data" > "${tmpd}"/config/a +echo "some data" > "${tmpd}"/vscode/extensions.txt +echo "some data" > "${tmpd}"/vscode/keybindings.json # create the config file cfg="${basedir}/config.yaml" -create_conf ${cfg} # sets token +create_conf "${cfg}" # sets token # import echo "[+] import" -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/program -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/config -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/vscode +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/program +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/config +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/vscode # add files on filesystem echo "[+] add files" -echo "new data" > ${basedir}/dotfiles/${tmpd}/README.md -echo "new data" > ${basedir}/dotfiles/${tmpd}/vscode/README.md -echo "new data" > ${basedir}/dotfiles/${tmpd}/program/README.md -mkdir -p ${basedir}/dotfiles/${tmpd}/readmes -echo "new data" > ${basedir}/dotfiles/${tmpd}/readmes/README.md +echo "new data" > "${basedir}"/dotfiles/"${tmpd}"/README.md +echo "new data" > "${basedir}"/dotfiles/"${tmpd}"/vscode/README.md +echo "new data" > "${basedir}"/dotfiles/"${tmpd}"/program/README.md +mkdir -p "${basedir}"/dotfiles/"${tmpd}"/readmes +echo "new data" > "${basedir}"/dotfiles/"${tmpd}"/readmes/README.md # install -rm -rf ${tmpd} +rm -rf "${tmpd}" echo "[+] install normal" -cd ${ddpath} | ${bin} install --showdiff -c ${cfg} --verbose -f +cd "${ddpath}" | ${bin} install --showdiff -c "${cfg}" --verbose -f [ "$?" != "0" ] && exit 1 -nb=`find ${tmpd} -iname 'README.md' | wc -l` +nb=$(find "${tmpd}" -iname 'README.md' | wc -l) echo "(1) found ${nb} README.md file(s)" [ "${nb}" != "2" ] && exit 1 # adding ignore in dotfile cfg2="${basedir}/config2.yaml" -sed '/d_program:/a \ \ \ \ instignore:\n\ \ \ \ - "README.md"' ${cfg} > ${cfg2} -cat ${cfg2} +sed '/d_program:/a \ \ \ \ instignore:\n\ \ \ \ - "README.md"' "${cfg}" > "${cfg2}" +cat "${cfg2}" # install -rm -rf ${tmpd} +rm -rf "${tmpd}" echo "[+] install with ignore in dotfile" -cd ${ddpath} | ${bin} install -c ${cfg2} --verbose -f +cd "${ddpath}" | ${bin} install -c "${cfg2}" --verbose -f [ "$?" != "0" ] && exit 1 -nb=`find ${tmpd} -iname 'README.md' | wc -l` +nb=$(find "${tmpd}" -iname 'README.md' | wc -l) echo "(2) found ${nb} README.md file(s)" [ "${nb}" != "1" ] && exit 1 # adding ignore in config cfg2="${basedir}/config2.yaml" -sed '/^config:/a \ \ instignore:\n\ \ - "README.md"' ${cfg} > ${cfg2} -cat ${cfg2} +sed '/^config:/a \ \ instignore:\n\ \ - "README.md"' "${cfg}" > "${cfg2}" +cat "${cfg2}" # install -rm -rf ${tmpd} +rm -rf "${tmpd}" echo "[+] install with ignore in config" -cd ${ddpath} | ${bin} install -c ${cfg2} --verbose -f +cd "${ddpath}" | ${bin} install -c "${cfg2}" --verbose -f [ "$?" != "0" ] && exit 1 -nb=`find ${tmpd} -iname 'README.md' | wc -l` +nb=$(find "${tmpd}" -iname 'README.md' | wc -l) echo "(3) found ${nb} README.md file(s)" [ "${nb}" != "0" ] && exit 1 ## reinstall to trigger showdiff -echo "showdiff" > ${tmpd}/program/a -cd ${ddpath} | echo "y" | ${bin} install --showdiff -c ${cfg} --verbose -f +echo "showdiff" > "${tmpd}"/program/a +cd "${ddpath}" | echo "y" | ${bin} install --showdiff -c "${cfg}" --verbose -f [ "$?" != "0" ] && exit 1 # test templated subdir -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -135,52 +138,52 @@ dotfiles: profiles: _EOF -mkdir -p ${tmpd}/nvim -mkdir -p ${tmpd}/nvim/dir1 -echo "f1" > ${tmpd}/nvim/dir1/file1 -mkdir -p ${tmpd}/nvim/dir2 -echo "f1" > ${tmpd}/nvim/dir2/file2 -echo "ftop" > ${tmpd}/nvim/ftop +mkdir -p "${tmpd}"/nvim +mkdir -p "${tmpd}"/nvim/dir1 +echo "f1" > "${tmpd}"/nvim/dir1/file1 +mkdir -p "${tmpd}"/nvim/dir2 +echo "f1" > "${tmpd}"/nvim/dir2/file2 +echo "ftop" > "${tmpd}"/nvim/ftop echo "[+] import top" -cd ${ddpath} | ${bin} import -f -c ${cfg} -l link_children -p p1 ${tmpd}/nvim +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -l link_children -p p1 "${tmpd}"/nvim # add sub dir -mkdir -p ${tmpd}/nvim/templated -echo "noprofile" > ${tmpd}/nvim/templated/ftemplated -echo "noprofile" > ${tmpd}/nvim/template +mkdir -p "${tmpd}"/nvim/templated +echo "noprofile" > "${tmpd}"/nvim/templated/ftemplated +echo "noprofile" > "${tmpd}"/nvim/template echo "[+] import sub" -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 ${tmpd}/nvim/templated -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 ${tmpd}/nvim/template +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 "${tmpd}"/nvim/templated +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 "${tmpd}"/nvim/template cfg2="${basedir}/config2.yaml" -sed '/d_nvim:/a \ \ \ \ instignore:\n\ \ \ \ - "*template*"' ${cfg} > ${cfg2} -cat ${cfg2} +sed '/d_nvim:/a \ \ \ \ instignore:\n\ \ \ \ - "*template*"' "${cfg}" > "${cfg2}" +cat "${cfg2}" ## clean destination files -rm -rf ${tmpd}/nvim +rm -rf "${tmpd}"/nvim ## patch template file -echo "{{@@ profile @@}}" > ${tmps}/dotfiles/${tmpd}/nvim/templated/ftemplated -echo "{{@@ profile @@}}" > ${tmps}/dotfiles/${tmpd}/nvim/template +echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/"${tmpd}"/nvim/templated/ftemplated +echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/"${tmpd}"/nvim/template echo "[+] install link_children" -cd ${ddpath} | ${bin} install -f -c ${cfg2} -p p1 -V d_nvim +cd "${ddpath}" | ${bin} install -f -c "${cfg2}" -p p1 -V d_nvim -[ -d ${tmpd}/nvim/templated ] && echo "templated should not be installed" && exit 1 -[ -e ${tmpd}/nvim/templated/ftemplated ] && echo "templated file should not be installed" && exit 1 -[ -e ${tmpd}/nvim/template ] && echo "template file should not be installed" && exit 1 +[ -d "${tmpd}"/nvim/templated ] && echo "templated should not be installed" && exit 1 +[ -e "${tmpd}"/nvim/templated/ftemplated ] && echo "templated file should not be installed" && exit 1 +[ -e "${tmpd}"/nvim/template ] && echo "template file should not be installed" && exit 1 echo "[+] install sub" -cd ${ddpath} | ${bin} install -f -c ${cfg2} -p p1 -V d_templated +cd "${ddpath}" | ${bin} install -f -c "${cfg2}" -p p1 -V d_templated echo "[+] install template" -cd ${ddpath} | ${bin} install -f -c ${cfg2} -p p1 -V f_template +cd "${ddpath}" | ${bin} install -f -c "${cfg2}" -p p1 -V f_template -[ ! -d ${tmpd}/nvim/templated ] && echo "templated not installed" && exit 1 -[ ! -e ${tmpd}/nvim/templated/ftemplated ] && echo "templated file not installed" && exit 1 -[ ! -e ${tmpd}/nvim/template ] && echo "template file not installed" && exit 1 -grep 'p1' ${tmpd}/nvim/templated/ftemplated -grep 'p1' ${tmpd}/nvim/template +[ ! -d "${tmpd}"/nvim/templated ] && echo "templated not installed" && exit 1 +[ ! -e "${tmpd}"/nvim/templated/ftemplated ] && echo "templated file not installed" && exit 1 +[ ! -e "${tmpd}"/nvim/template ] && echo "template file not installed" && exit 1 +grep 'p1' "${tmpd}"/nvim/templated/ftemplated +grep 'p1' "${tmpd}"/nvim/template echo "OK" exit 0 diff --git a/tests-ng/install-link-children.sh b/tests-ng/install-link-children.sh index b2f0146..3b3bc51 100755 --- a/tests-ng/install-link-children.sh +++ b/tests-ng/install-link-children.sh @@ -28,29 +28,32 @@ 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}" clear_on_exit "${tmps}" @@ -59,7 +62,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -80,34 +83,34 @@ _EOF #cat ${cfg} # create the dotfile -mkdir ${tmps}/dotfiles/dir1 -mkdir ${tmps}/dotfiles/dir1/empty -echo "{{@@ profile @@}}" > ${tmps}/dotfiles/dir1/empty/this.ignore -mkdir ${tmps}/dotfiles/dir1/not-empty -echo "{{@@ profile @@}}" > ${tmps}/dotfiles/dir1/not-empty/file -mkdir ${tmps}/dotfiles/dir1/sub -mkdir ${tmps}/dotfiles/dir1/sub/empty -echo "{{@@ profile @@}}" > ${tmps}/dotfiles/dir1/sub/empty/that.ignore +mkdir "${tmps}"/dotfiles/dir1 +mkdir "${tmps}"/dotfiles/dir1/empty +echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/dir1/empty/this.ignore +mkdir "${tmps}"/dotfiles/dir1/not-empty +echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/dir1/not-empty/file +mkdir "${tmps}"/dotfiles/dir1/sub +mkdir "${tmps}"/dotfiles/dir1/sub/empty +echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/dir1/sub/empty/that.ignore # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V #cat ${cfg} # check normal -[ ! -d ${tmpd}/dir1 ] && exit 1 -[ -d ${tmpd}/dir1/empty ] && exit 1 -[ -d ${tmpd}/dir1/sub ] && exit 1 -[ -d ${tmpd}/dir1/sub/empty ] && exit 1 -[ ! -d ${tmpd}/dir1/not-empty ] && exit 1 +[ ! -d "${tmpd}"/dir1 ] && exit 1 +[ -d "${tmpd}"/dir1/empty ] && exit 1 +[ -d "${tmpd}"/dir1/sub ] && exit 1 +[ -d "${tmpd}"/dir1/sub/empty ] && exit 1 +[ ! -d "${tmpd}"/dir1/not-empty ] && exit 1 -[ ! -e ${tmpd}/dir1/not-empty/file ] && exit 1 +[ ! -e "${tmpd}"/dir1/not-empty/file ] && exit 1 # ignored files -[ -e ${tmpd}/dir1/empty/this.ignore ] && exit 1 -[ -e ${tmpd}/dir1/sub/empty/that.ignore ] && exit 1 +[ -e "${tmpd}"/dir1/empty/this.ignore ] && exit 1 +[ -e "${tmpd}"/dir1/sub/empty/that.ignore ] && exit 1 -cat ${tmpd}/dir1/not-empty/file -grep "p1" ${tmpd}/dir1/not-empty/file +cat "${tmpd}"/dir1/not-empty/file +grep "p1" "${tmpd}"/dir1/not-empty/file echo "OK" exit 0 diff --git a/tests-ng/install-negative-ignore.sh b/tests-ng/install-negative-ignore.sh index 961d242..094e39c 100755 --- a/tests-ng/install-negative-ignore.sh +++ b/tests-ng/install-negative-ignore.sh @@ -9,41 +9,12 @@ set -e # all this crap to get current path -if [ $(uname) = Darwin ]; then - # Unfortunately, readlink works differently on macOS than it does on GNU/Linux - # (the -f option behaves differently) and the realpath command does not exist. - # Workarounds I find on the Internet suggest just using Homebrew to install coreutils - # so you can get the GNU coreutils on your Mac. But, I don't want this script to - # assume (a) users have Homebrew installed and (b) if they have Homebrew installed, that - # they then installed the GNU coreutils. - readlink() { - TARGET_FILE=$1 +rl="readlink -f" +if ! ${rl} "${0}" >/dev/null 2>&1; then + rl="realpath" - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - - # Iterate down a (possible) chain of symlinks - while [ -L "$TARGET_FILE" ]; do - TARGET_FILE=`readlink $TARGET_FILE` - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - done - - # Compute the canonicalized name by finding the physical path - # for the directory we're in and appending the target file. - PHYS_DIR=`pwd -P` - RESULT=$PHYS_DIR/$TARGET_FILE - echo $RESULT - } - rl="readlink" -else - rl="readlink -f" - if ! ${rl} "${0}" >/dev/null 2>&1; then - rl="realpath" - - if ! hash ${rl}; then - echo "\"${rl}\" not found !" && exit 1 - fi + if ! hash ${rl}; then + echo "\"${rl}\" not found !" && exit 1 fi fi cur=$(dirname "$(${rl} "${0}")") @@ -51,48 +22,51 @@ cur=$(dirname "$(${rl} "${0}")") # dotdrop path can be pass as argument ddpath="${cur}/../" [ -n "${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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" # the dotfile to be imported -tmpd=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # some files -mkdir -p ${tmpd}/program/ignore_me -echo "some data" > ${tmpd}/program/a -echo "some data" > ${tmpd}/program/ignore_me/b -echo "some data" > ${tmpd}/program/ignore_me/c +mkdir -p "${tmpd}"/program/ignore_me +echo "some data" > "${tmpd}"/program/a +echo "some data" > "${tmpd}"/program/ignore_me/b +echo "some data" > "${tmpd}"/program/ignore_me/c # create the config file cfg="${basedir}/config.yaml" -create_conf ${cfg} # sets token +create_conf "${cfg}" # sets token # import echo "[+] import" -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/program +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/program # adding ignore in dotfile cfg2="${basedir}/config2.yaml" @@ -100,12 +74,12 @@ sed '/d_program:/a\ \ \ \ \ instignore:\ \ \ \ \ - "*/ignore_me/*"\ \ \ \ \ - "!*/ignore_me/c" -' ${cfg} > ${cfg2} +' "${cfg}" > "${cfg2}" # install -rm -rf ${tmpd} +rm -rf "${tmpd}" echo "[+] install with negative ignore in dotfile" -cd ${ddpath} | ${bin} install -c ${cfg2} --verbose +cd "${ddpath}" | ${bin} install -c "${cfg2}" --verbose [ "$?" != "0" ] && exit 1 echo '(1) expect structure to be . @@ -114,11 +88,11 @@ echo '(1) expect structure to be └── ignore_me └── c' -[[ -n "$(find ${tmpd}/program -name a)" ]] || exit 1 +[[ -n "$(find "${tmpd}"/program -name a)" ]] || exit 1 echo "(1) found program/a ... good" -[[ -n "$(find ${tmpd}/program/ignore_me -name b)" ]] && exit 1 +[[ -n "$(find "${tmpd}"/program/ignore_me -name b)" ]] && exit 1 echo "(1) didn't find program/b ... good" -[[ -n "$(find ${tmpd}/program/ignore_me -name c)" ]] || exit 1 +[[ -n "$(find "${tmpd}"/program/ignore_me -name c)" ]] || exit 1 echo "(1) found program/c ... good" echo "OK" diff --git a/tests-ng/install-to-temp.sh b/tests-ng/install-to-temp.sh index 831970a..bd86ced 100755 --- a/tests-ng/install-to-temp.sh +++ b/tests-ng/install-to-temp.sh @@ -28,28 +28,31 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` -mkdir -p ${basedir}/dotfiles -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${basedir}"/dotfiles +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" @@ -58,7 +61,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${basedir}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -82,19 +85,19 @@ profiles: - f_z _EOF -echo 'test_x' > ${basedir}/dotfiles/x -echo 'test_y' > ${basedir}/dotfiles/y -echo "00000000 01 02 03 04 05" | xxd -r - ${basedir}/dotfiles/z +echo 'test_x' > "${basedir}"/dotfiles/x +echo 'test_y' > "${basedir}"/dotfiles/y +echo "00000000 01 02 03 04 05" | xxd -r - "${basedir}"/dotfiles/z echo "[+] install" log="${basedir}/log" -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 --showdiff --verbose --temp > ${log} +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 --showdiff --verbose --temp > "${log}" -tmpfile=`cat ${basedir}/log | grep 'installed to tmp ' | sed 's/^.*to tmp "\(.*\)"./\1/'` +tmpfile=$(cat "${basedir}"/log | grep 'installed to tmp ' | sed 's/^.*to tmp "\(.*\)"./\1/') echo "tmpfile: ${tmpfile}" clear_on_exit "${tmpfile}" -cat ${log} | grep '^3 dotfile(s) installed.$' +cat "${log}" | grep '^3 dotfile(s) installed.$' [ "$?" != "0" ] && exit 1 echo "OK" diff --git a/tests-ng/install.sh b/tests-ng/install.sh index 5164330..83da88c 100755 --- a/tests-ng/install.sh +++ b/tests-ng/install.sh @@ -32,7 +32,9 @@ ddpath="${cur}/../" 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}" @@ -40,7 +42,7 @@ echo "pythonpath: ${PYTHONPATH}" # get the 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 @@ -61,25 +63,25 @@ has_rights() echo "testing ${1} is ${2}" [ ! -e "$1" ] && echo "`basename $1` does not exist" && exit 1 local mode=`stat -L -c '%a' "$1"` - [ "${mode}" != "$2" ] && echo "bad mode for `basename $1` (${mode} VS expected ${2})" && exit 1 + [ "${mode}" != "$2" ] && echo "bad mode for `basename "$1"` (${mode} VS expected ${2})" && exit 1 true } # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` -mkdir -p ${basedir}/dotfiles +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${basedir}"/dotfiles echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" -echo "content" > ${basedir}/dotfiles/x +echo "content" > "${basedir}"/dotfiles/x # create the config file cfg="${basedir}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -95,30 +97,30 @@ profiles: _EOF echo "[+] install" -cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 --verbose | grep '^1 dotfile(s) installed.$' +cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 --verbose | grep '^1 dotfile(s) installed.$' [ "$?" != "0" ] && exit 1 -[ ! -e ${tmpd}/x ] && echo "f_x not installed" && exit 1 +[ ! -e "${tmpd}"/x ] && echo "f_x not installed" && exit 1 # update chmod -chmod 666 ${tmpd}/x -cd ${ddpath} | ${bin} update -c ${cfg} -f -p p1 --verbose ${tmpd}/x +chmod 666 "${tmpd}"/x +cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 --verbose "${tmpd}"/x # chmod updated -cat ${cfg} | grep "chmod: '666'" +cat "${cfg}" | grep "chmod: '666'" -chmod 644 ${tmpd}/x +chmod 644 "${tmpd}"/x -mode=`get_file_mode ${tmpd}/x` +mode=$(get_file_mode "${tmpd}"/x) echo "[+] re-install with no" -cd ${ddpath} | printf "N\n" | ${bin} install -c ${cfg} -p p1 --verbose +cd "${ddpath}" | printf "N\n" | ${bin} install -c "${cfg}" -p p1 --verbose [ "$?" != "0" ] && exit 1 # if user answers N, chmod should not be done has_rights "${tmpd}/x" "${mode}" echo "[+] re-install with yes" -cd ${ddpath} | printf "y\n" | ${bin} install -c ${cfg} -p p1 --verbose +cd "${ddpath}" | printf "y\n" | ${bin} install -c "${cfg}" -p p1 --verbose [ "$?" != "0" ] && exit 1 has_rights "${tmpd}/x" "666" diff --git a/tests-ng/jhelpers.sh b/tests-ng/jhelpers.sh index c2067b1..df15fa1 100755 --- a/tests-ng/jhelpers.sh +++ b/tests-ng/jhelpers.sh @@ -28,29 +28,32 @@ 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}" clear_on_exit "${tmps}" @@ -59,7 +62,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -80,25 +83,25 @@ _EOF #cat ${cfg} # create the dotfile -echo "this is the test dotfile" > ${tmps}/dotfiles/abc +echo "this is the test dotfile" > "${tmps}"/dotfiles/abc # test exists -echo "{%@@ if exists('/dev/null') @@%}" >> ${tmps}/dotfiles/abc -echo "this should exist" >> ${tmps}/dotfiles/abc -echo "{%@@ endif @@%}" >> ${tmps}/dotfiles/abc +echo "{%@@ if exists('/dev/null') @@%}" >> "${tmps}"/dotfiles/abc +echo "this should exist" >> "${tmps}"/dotfiles/abc +echo "{%@@ endif @@%}" >> "${tmps}"/dotfiles/abc -echo "{%@@ if exists('/dev/abcdef') @@%}" >> ${tmps}/dotfiles/abc -echo "this should not exist" >> ${tmps}/dotfiles/abc -echo "{%@@ endif @@%}" >> ${tmps}/dotfiles/abc +echo "{%@@ if exists('/dev/abcdef') @@%}" >> "${tmps}"/dotfiles/abc +echo "this should not exist" >> "${tmps}"/dotfiles/abc +echo "{%@@ endif @@%}" >> "${tmps}"/dotfiles/abc # test exists_in_path -cat >> ${tmps}/dotfiles/abc << _EOF +cat >> "${tmps}"/dotfiles/abc << _EOF {%@@ if exists_in_path('cat') @@%} this should exist too {%@@ endif @@%} _EOF -cat >> ${tmps}/dotfiles/abc << _EOF +cat >> "${tmps}"/dotfiles/abc << _EOF {%@@ if exists_in_path('a_name_that_is_unlikely_to_be_chosen_for_an_executable') @@%} this should not exist either {%@@ endif @@%} @@ -106,16 +109,16 @@ _EOF #cat ${tmps}/dotfiles/abc -echo "this is def" > ${tmps}/dotfiles/def +echo "this is def" > "${tmps}"/dotfiles/def # test basename -cat >> ${tmps}/dotfiles/def << _EOF +cat >> "${tmps}"/dotfiles/def << _EOF {%@@ set dotfile_filename = basename( _dotfile_abs_dst ) @@%} dotfile dst filename: {{@@ dotfile_filename @@}} _EOF # test dirname -cat >> ${tmps}/dotfiles/def << _EOF +cat >> "${tmps}"/dotfiles/def << _EOF {%@@ set dotfile_dirname= dirname( _dotfile_abs_dst ) @@%} dotfile dst dirname: {{@@ dotfile_dirname @@}} _EOF @@ -123,22 +126,22 @@ _EOF #cat ${tmps}/dotfiles/def # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V #cat ${tmpd}/abc -grep '^this should exist' ${tmpd}/abc >/dev/null -grep '^this should exist too' ${tmpd}/abc >/dev/null +grep '^this should exist' "${tmpd}"/abc >/dev/null +grep '^this should exist too' "${tmpd}"/abc >/dev/null set +e -grep '^this should not exist' ${tmpd}/abc >/dev/null && exit 1 -grep '^this should not exist either' ${tmpd}/abc >/dev/null && exit 1 +grep '^this should not exist' "${tmpd}"/abc >/dev/null && exit 1 +grep '^this should not exist either' "${tmpd}"/abc >/dev/null && exit 1 set -e #cat ${tmpd}/abc # test def -grep "dotfile dst filename: `basename ${tmpd}/def`" ${tmpd}/def -grep "dotfile dst dirname: `dirname ${tmpd}/def`" ${tmpd}/def +grep "dotfile dst filename: $(basename "${tmpd}"/def)" "${tmpd}"/def +grep "dotfile dst dirname: $(dirname "${tmpd}"/def)" "${tmpd}"/def echo "OK" exit 0 diff --git a/tests-ng/key-prefix-sep.sh b/tests-ng/key-prefix-sep.sh index 35a6c31..55c4628 100755 --- a/tests-ng/key-prefix-sep.sh +++ b/tests-ng/key-prefix-sep.sh @@ -27,45 +27,48 @@ 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}" clear_on_exit "${tmps}" clear_on_exit "${tmpd}" # create the dotfile -mkdir -p ${tmpd}/top -touch ${tmpd}/top/.colors -mkdir -p ${tmpd}/.mutt/sub -touch ${tmpd}/.mutt/sub/colors +mkdir -p "${tmpd}"/top +touch "${tmpd}"/top/.colors +mkdir -p "${tmpd}"/.mutt/sub +touch "${tmpd}"/.mutt/sub/colors # create the config file cfg="${tmps}/config.yaml" # normal behavior -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -78,19 +81,19 @@ profiles: _EOF # import -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/top/.colors -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/.mutt/sub +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/top/.colors +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/.mutt/sub -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | cut -f1 -d',' | grep -q '_top_colors' -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | cut -f1 -d',' | grep -q '_mutt_sub' +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -G | cut -f1 -d',' | grep -q '_top_colors' +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -G | cut -f1 -d',' | grep -q '_mutt_sub' -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | cut -f1 -d',' | grep '_top_colors' | grep -q 'f_' -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | cut -f1 -d',' | grep '_mutt_sub' | grep -q 'd_' +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -G | cut -f1 -d',' | grep '_top_colors' | grep -q 'f_' +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -G | cut -f1 -d',' | grep '_mutt_sub' | grep -q 'd_' # pimping -rm -rf ${tmps}/* +rm -rf "${tmps}"/* -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -103,17 +106,17 @@ profiles: _EOF # import -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/top/.colors -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/.mutt/sub +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/top/.colors +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/.mutt/sub -cat ${cfg} -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G +cat "${cfg}" +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -G -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | cut -f1 -d',' | grep -q '+top+colors' -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | cut -f1 -d',' | grep -q '+mutt+sub' +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -G | cut -f1 -d',' | grep -q '+top+colors' +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -G | cut -f1 -d',' | grep -q '+mutt+sub' -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | cut -f1 -d',' | grep '+top+colors' | grep -qv 'f_' -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | cut -f1 -d',' | grep '+mutt+sub' | grep -qv 'd_' +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -G | cut -f1 -d',' | grep '+top+colors' | grep -qv 'f_' +cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -G | cut -f1 -d',' | grep '+mutt+sub' | grep -qv 'd_' echo "OK" exit 0 diff --git a/tests-ng/link-import-default.sh b/tests-ng/link-import-default.sh index e792848..3e5ba52 100755 --- a/tests-ng/link-import-default.sh +++ b/tests-ng/link-import-default.sh @@ -28,29 +28,32 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -59,10 +62,10 @@ clear_on_exit "${tmpd}" cfg="${tmps}/config.yaml" # create the source -echo "abc" > ${tmpd}/abc +echo "abc" > "${tmpd}"/abc # import with nolink by default -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -73,18 +76,18 @@ profiles: _EOF # import -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/abc +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/abc # checks inside="${tmps}/dotfiles/${tmpd}/abc" -[ ! -e ${inside} ] && exit 1 +[ ! -e "${inside}" ] && exit 1 set +e -cat ${cfg} | grep 'link:' && exit 1 +cat "${cfg}" | grep 'link:' && exit 1 set -e # import with parent by default -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -95,14 +98,14 @@ profiles: _EOF # import -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/abc +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/abc # checks inside="${tmps}/dotfiles/${tmpd}/abc" -[ ! -e ${inside} ] && exit 1 +[ ! -e "${inside}" ] && exit 1 -cat ${cfg} -cat ${cfg} | grep 'link: absolute' >/dev/null +cat "${cfg}" +cat "${cfg}" | grep 'link: absolute' >/dev/null echo "OK" exit 0 diff --git a/tests-ng/link-templates-dir-home.sh b/tests-ng/link-templates-dir-home.sh index b1bb603..b6ec873 100755 --- a/tests-ng/link-templates-dir-home.sh +++ b/tests-ng/link-templates-dir-home.sh @@ -28,33 +28,36 @@ 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 echo "dotfiles source (dotpath): ${tmps}" # the dotfile destination -tmpd=`mktemp -d -p ${HOME} --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d -p "${HOME}" --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" # the workdir -tmpw=`mktemp -d -p ${HOME} --suffix='-dotdrop-tests' || mktemp -d` +tmpw=$(mktemp -d -p "${HOME}" --suffix='-dotdrop-tests' || mktemp -d) export DOTDROP_WORKDIR="${tmpw}" echo "workdir: ${tmpw}" @@ -65,7 +68,7 @@ clear_on_exit "${tmpw}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -84,21 +87,21 @@ _EOF #cat ${cfg} # create the dotfile -mkdir -p ${tmps}/dotfiles/abc -echo "{{@@ profile @@}}" > ${tmps}/dotfiles/abc/template -echo "blabla" >> ${tmps}/dotfiles/abc/template -echo "blabla" > ${tmps}/dotfiles/abc/nottemplate +mkdir -p "${tmps}"/dotfiles/abc +echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/abc/template +echo "blabla" >> "${tmps}"/dotfiles/abc/template +echo "blabla" > "${tmps}"/dotfiles/abc/nottemplate # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V # checks -[ ! -d ${tmpd}/abc ] && echo "[ERROR] dotfile not installed" && exit 1 -[ ! -h ${tmpd}/abc ] && echo "[ERROR] dotfile is not a symlink" && exit 1 +[ ! -d "${tmpd}"/abc ] && echo "[ERROR] dotfile not installed" && exit 1 +[ ! -h "${tmpd}"/abc ] && echo "[ERROR] dotfile is not a symlink" && exit 1 #cat ${tmpd}/abc/template #tree -a ${tmpd}/abc/ set +e -grep '{{@@' ${tmpd}/abc/template >/dev/null 2>&1 && echo "[ERROR] template in dir not replace" && exit 1 +grep '{{@@' "${tmpd}"/abc/template >/dev/null 2>&1 && echo "[ERROR] template in dir not replace" && exit 1 set -e echo "OK" diff --git a/tests-ng/link-templates-dir.sh b/tests-ng/link-templates-dir.sh index 77b8d5a..239ef62 100755 --- a/tests-ng/link-templates-dir.sh +++ b/tests-ng/link-templates-dir.sh @@ -28,33 +28,36 @@ 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 echo "dotfiles source (dotpath): ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" # the workdir -tmpw=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpw=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) export DOTDROP_WORKDIR="${tmpw}" echo "workdir: ${tmpw}" @@ -65,7 +68,7 @@ clear_on_exit "${tmpw}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -84,21 +87,21 @@ _EOF #cat ${cfg} # create the dotfile -mkdir -p ${tmps}/dotfiles/abc -echo "{{@@ profile @@}}" > ${tmps}/dotfiles/abc/template -echo "blabla" >> ${tmps}/dotfiles/abc/template -echo "blabla" > ${tmps}/dotfiles/abc/nottemplate +mkdir -p "${tmps}"/dotfiles/abc +echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/abc/template +echo "blabla" >> "${tmps}"/dotfiles/abc/template +echo "blabla" > "${tmps}"/dotfiles/abc/nottemplate # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V # checks -[ ! -d ${tmpd}/abc ] && echo "[ERROR] dotfile not installed" && exit 1 -[ ! -h ${tmpd}/abc ] && echo "[ERROR] dotfile is not a symlink" && exit 1 +[ ! -d "${tmpd}"/abc ] && echo "[ERROR] dotfile not installed" && exit 1 +[ ! -h "${tmpd}"/abc ] && echo "[ERROR] dotfile is not a symlink" && exit 1 #cat ${tmpd}/abc/template #tree -a ${tmpd}/abc/ set +e -grep '{{@@' ${tmpd}/abc/template >/dev/null 2>&1 && echo "[ERROR] template in dir not replace" && exit 1 +grep '{{@@' "${tmpd}"/abc/template >/dev/null 2>&1 && echo "[ERROR] template in dir not replace" && exit 1 set -e echo "OK" diff --git a/tests-ng/link-templates.sh b/tests-ng/link-templates.sh index 8a74a45..0fb5723 100755 --- a/tests-ng/link-templates.sh +++ b/tests-ng/link-templates.sh @@ -28,33 +28,36 @@ 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 echo "dotfiles source (dotpath): ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" # the workdir -tmpw=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpw=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) export DOTDROP_WORKDIR="${tmpw}" echo "workdir: ${tmpw}" @@ -65,7 +68,7 @@ clear_on_exit "${tmpw}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -84,15 +87,15 @@ _EOF #cat ${cfg} # create the dotfile -echo "{{@@ profile @@}}" > ${tmps}/dotfiles/abc -echo "blabla" >> ${tmps}/dotfiles/abc +echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/abc +echo "blabla" >> "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V # checks -[ ! -e ${tmpd}/abc ] && echo "[ERROR] dotfile not installed" && exit 1 -[ ! -h ${tmpd}/abc ] && echo "[ERROR] dotfile is not a symlink" && exit 1 +[ ! -e "${tmpd}"/abc ] && echo "[ERROR] dotfile not installed" && exit 1 +[ ! -h "${tmpd}"/abc ] && echo "[ERROR] dotfile is not a symlink" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/link-value-tests.sh b/tests-ng/link-value-tests.sh index cdc40ea..62b8df5 100755 --- a/tests-ng/link-value-tests.sh +++ b/tests-ng/link-value-tests.sh @@ -33,7 +33,9 @@ ddpath="${cur}/../" 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}" @@ -41,7 +43,7 @@ echo "pythonpath: ${PYTHONPATH}" # get the 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 @@ -454,16 +456,16 @@ cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 ${df} -V # checks cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "d_`basename ${df}`" | head -1 | grep ',link:link_children,' +cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "d_`basename "${df}"`" | head -1 | grep ',link:link_children,' # try to install -rm -rf ${tmpd}/qwert -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V -[ ! -e ${df} ] && echo "does not exist" && exit 1 -[ -h ${df} ] && echo "is a symlink" && exit 1 -[ ! -h ${df}/file ] && echo "file is not a symlink" && exit 1 -[ ! -h ${df}/directory ] && echo "directory is not a symlink" && exit 1 -[ -h ${df}/directory/file ] && echo "directory/file is a symlink" && exit 1 +rm -rf "${tmpd}"/qwert +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V +[ ! -e "${df}" ] && echo "does not exist" && exit 1 +[ -h "${df}" ] && echo "is a symlink" && exit 1 +[ ! -h "${df}"/file ] && echo "file is not a symlink" && exit 1 +[ ! -h "${df}"/directory ] && echo "directory is not a symlink" && exit 1 +[ -h "${df}"/directory/file ] && echo "directory/file is a symlink" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/macro-with-globals.sh b/tests-ng/macro-with-globals.sh index d03e14f..2c015c2 100755 --- a/tests-ng/macro-with-globals.sh +++ b/tests-ng/macro-with-globals.sh @@ -27,29 +27,32 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -57,7 +60,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -76,27 +79,27 @@ variables: _EOF # create the source -mkdir -p ${tmps}/dotfiles/ +mkdir -p "${tmps}"/dotfiles/ -cat > ${tmps}/dotfiles/macro_file << _EOF +cat > "${tmps}"/dotfiles/macro_file << _EOF {%@@ macro macro(var) @@%} {{@@ global @@}} {{@@ var @@}} {%@@ endmacro @@%} _EOF -cat > ${tmps}/dotfiles/abc << _EOF +cat > "${tmps}"/dotfiles/abc << _EOF {%@@ from 'macro_file' import macro with context @@%} {{@@ macro(local) @@}} _EOF # install -cd ${ddpath} | ${bin} install -c ${cfg} -p p0 -V -f +cd "${ddpath}" | ${bin} install -c "${cfg}" -p p0 -V -f # test file content -cat ${tmpd}/abc -grep 'global_var' ${tmpd}/abc >/dev/null 2>&1 -grep 'local_var' ${tmpd}/abc >/dev/null 2>&1 +cat "${tmpd}"/abc +grep 'global_var' "${tmpd}"/abc >/dev/null 2>&1 +grep 'local_var' "${tmpd}"/abc >/dev/null 2>&1 echo "OK" exit 0 diff --git a/tests-ng/minversion.sh b/tests-ng/minversion.sh index 616005a..2376b96 100755 --- a/tests-ng/minversion.sh +++ b/tests-ng/minversion.sh @@ -26,35 +26,38 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -71,20 +74,20 @@ profiles: _EOF # create the source -mkdir -p ${tmps}/dotfiles/ -echo "abc" > ${tmps}/dotfiles/abc -ln -s ${tmps}/dotfiles/abc ${tmpd}/abc +mkdir -p "${tmps}"/dotfiles/ +echo "abc" > "${tmps}"/dotfiles/abc +ln -s "${tmps}"/dotfiles/abc "${tmpd}"/abc # compare -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 -V # ensure minversion is present -cat ${cfg} -grep 'link: absolute' ${cfg} -grep 'minversion' ${cfg} +cat "${cfg}" +grep 'link: absolute' "${cfg}" +grep 'minversion' "${cfg}" # fake a higher version -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -103,12 +106,12 @@ _EOF # compare set +e -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 -V [ "$?" != "1" ] && echo "minversion not working" && exit 1 set -e # all clean -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -124,11 +127,11 @@ profiles: _EOF # compare -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 -V # test -cat ${cfg} -grep 'minversion' ${cfg} && echo "minversion added, not needed" && exit 1 +cat "${cfg}" +grep 'minversion' "${cfg}" && echo "minversion added, not needed" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/negative-ignore-no-match.sh b/tests-ng/negative-ignore-no-match.sh index e0ca76b..935a2bf 100755 --- a/tests-ng/negative-ignore-no-match.sh +++ b/tests-ng/negative-ignore-no-match.sh @@ -10,106 +10,79 @@ set -e # all this crap to get current path -if [ $(uname) = Darwin ]; then - # Unfortunately, readlink works differently on macOS than it does on GNU/Linux - # (the -f option behaves differently) and the realpath command does not exist. - # Workarounds I find on the Internet suggest just using Homebrew to install coreutils - # so you can get the GNU coreutils on your Mac. But, I don't want this script to - # assume (a) users have Homebrew installed and (b) if they have Homebrew installed, that - # they then installed the GNU coreutils. - readlink() { - TARGET_FILE=$1 +rl="readlink -f" +if ! ${rl} "${0}" >/dev/null 2>&1; then + rl="realpath" - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - - # Iterate down a (possible) chain of symlinks - while [ -L "$TARGET_FILE" ]; do - TARGET_FILE=`readlink $TARGET_FILE` - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - done - - # Compute the canonicalized name by finding the physical path - # for the directory we're in and appending the target file. - PHYS_DIR=`pwd -P` - RESULT=$PHYS_DIR/$TARGET_FILE - echo $RESULT - } - rl="readlink" -else - rl="readlink -f" - if ! ${rl} "${0}" >/dev/null 2>&1; then - rl="realpath" - - if ! hash ${rl}; then - echo "\"${rl}\" not found !" && exit 1 - fi + if ! hash ${rl}; then + echo "\"${rl}\" not found !" && exit 1 fi fi cur=$(dirname "$(${rl} "${0}")") - # dotdrop path can be pass as argument ddpath="${cur}/../" [ -n "${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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" # the dotfile to be imported -tmpd=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # some files -mkdir -p ${tmpd}/program/ignore_me -echo "some data" > ${tmpd}/program/a -echo "some data" > ${tmpd}/program/ignore_me/b -echo "some data" > ${tmpd}/program/ignore_me/c +mkdir -p "${tmpd}"/program/ignore_me +echo "some data" > "${tmpd}"/program/a +echo "some data" > "${tmpd}"/program/ignore_me/b +echo "some data" > "${tmpd}"/program/ignore_me/c # create the config file cfg="${basedir}/config.yaml" -create_conf ${cfg} # sets token +create_conf "${cfg}" # sets token # import echo "[+] import" -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/program +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/program # adding ignore in dotfile cfg2="${basedir}/config2.yaml" sed '/d_program:/a\ \ \ \ \ instignore:\ \ \ \ \ - "!*/ignore_me/c" -' ${cfg} > ${cfg2} +' "${cfg}" > "${cfg2}" # install -rm -rf ${tmpd} +rm -rf "${tmpd}" echo "[+] install with negative ignore in dotfile" echo '(1) expect dotdrop install to warn when negative ignore pattern does not match an already-ignored file' patt="[WARN] no files that are currently being ignored match \"*/ignore_me/c\". In order for a negative ignore pattern to work, it must match a file that is being ignored by a previous ignore pattern." -cd ${ddpath} | ${bin} install -c ${cfg2} --verbose 2>&1 >/dev/null | grep -F "${patt}" || +cd "${ddpath}" | ${bin} install -c "${cfg2}" --verbose 2>&1 >/dev/null | grep -F "${patt}" || (echo "dotdrop did not warn when negative ignore pattern did not match an already-ignored file" && exit 1) echo "OK" diff --git a/tests-ng/notemplate.sh b/tests-ng/notemplate.sh index e8bb451..d4a67e9 100755 --- a/tests-ng/notemplate.sh +++ b/tests-ng/notemplate.sh @@ -28,30 +28,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 +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmps}"/dotfiles #echo "dotfile source: ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) #echo "dotfile destination: ${tmpd}" clear_on_exit "${tmps}" @@ -61,7 +64,7 @@ clear_on_exit "${tmpd}" cfg="${tmps}/config.yaml" # globally -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -103,93 +106,93 @@ _EOF #cat ${cfg} # create the dotfile -echo "before" > ${tmps}/dotfiles/f1 -echo "{#@@ should not be stripped @@#}" >> ${tmps}/dotfiles/f1 -echo "{{@@ header() @@}}" >> ${tmps}/dotfiles/f1 -echo "after" >> ${tmps}/dotfiles/f1 +echo "before" > "${tmps}"/dotfiles/f1 +echo "{#@@ should not be stripped @@#}" >> "${tmps}"/dotfiles/f1 +echo "{{@@ header() @@}}" >> "${tmps}"/dotfiles/f1 +echo "after" >> "${tmps}"/dotfiles/f1 # create the directory -mkdir -p ${tmps}/dotfiles/dir1/d1 -echo "{{@@ header() @@}}" > ${tmps}/dotfiles/dir1/d1/f2 +mkdir -p "${tmps}"/dotfiles/dir1/d1 +echo "{{@@ header() @@}}" > "${tmps}"/dotfiles/dir1/d1/f2 # create the linked directory -mkdir -p ${tmps}/dotfiles/dir2/d1 -echo "{{@@ header() @@}}" > ${tmps}/dotfiles/dir2/d1/f2 +mkdir -p "${tmps}"/dotfiles/dir2/d1 +echo "{{@@ header() @@}}" > "${tmps}"/dotfiles/dir2/d1/f2 # create the link_children directory -mkdir -p ${tmps}/dotfiles/dir3/{s1,s2,s3} -echo "{{@@ header() @@}}" > ${tmps}/dotfiles/dir3/s1/f1 -echo "{{@@ header() @@}}" > ${tmps}/dotfiles/dir3/s2/f2 +mkdir -p "${tmps}"/dotfiles/dir3/{s1,s2,s3} +echo "{{@@ header() @@}}" > "${tmps}"/dotfiles/dir3/s1/f1 +echo "{{@@ header() @@}}" > "${tmps}"/dotfiles/dir3/s2/f2 # create the linked dotfile -echo "{{@@ header() @@}}" > ${tmps}/dotfiles/fl +echo "{{@@ header() @@}}" > "${tmps}"/dotfiles/fl # create the normal dotfile -echo "before" > ${tmps}/dotfiles/fn -echo "{#@@ should be stripped @@#}" >> ${tmps}/dotfiles/fn -echo "after" >> ${tmps}/dotfiles/fn +echo "before" > "${tmps}"/dotfiles/fn +echo "{#@@ should be stripped @@#}" >> "${tmps}"/dotfiles/fn +echo "after" >> "${tmps}"/dotfiles/fn # install echo "installing" -cd ${ddpath} | ${bin} install -f --showdiff -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f --showdiff -c "${cfg}" -p p1 -V echo "comparing" -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 -V # simple file echo "doing globally" echo "* test simple file" -[ ! -e ${tmpd}/f1 ] && echo 'not installed1' && exit 1 -grep 'header' ${tmpd}/f1 || (echo "header stripped" && exit 1) -grep 'should not be stripped' ${tmpd}/f1 || (echo "comment stripped" && exit 1) +[ ! -e "${tmpd}"/f1 ] && echo 'not installed1' && exit 1 +grep 'header' "${tmpd}"/f1 || (echo "header stripped" && exit 1) +grep 'should not be stripped' "${tmpd}"/f1 || (echo "comment stripped" && exit 1) # directory echo "* test directory" -[ ! -d ${tmpd}/dir1 ] && echo 'not installed1' && exit 1 -[ ! -d ${tmpd}/dir1/d1 ] && echo 'not installed2' && exit 1 -[ ! -e ${tmpd}/dir1/d1/f2 ] && echo 'not installed3' && exit 1 -grep 'header' ${tmpd}/dir1/d1/f2 || (echo "header stripped" && exit 1) +[ ! -d "${tmpd}"/dir1 ] && echo 'not installed1' && exit 1 +[ ! -d "${tmpd}"/dir1/d1 ] && echo 'not installed2' && exit 1 +[ ! -e "${tmpd}"/dir1/d1/f2 ] && echo 'not installed3' && exit 1 +grep 'header' "${tmpd}"/dir1/d1/f2 || (echo "header stripped" && exit 1) # linked directory echo "* test linked directory" -[ ! -h ${tmpd}/dir2 ] && echo 'not installed1' && exit 1 -[ ! -d ${tmpd}/dir2/d1 ] && echo 'not installed2' && exit 1 -[ ! -e ${tmpd}/dir2/d1/f2 ] && echo 'not installed3' && exit 1 -grep 'header' ${tmpd}/dir2/d1/f2 || (echo "header stripped" && exit 1) +[ ! -h "${tmpd}"/dir2 ] && echo 'not installed1' && exit 1 +[ ! -d "${tmpd}"/dir2/d1 ] && echo 'not installed2' && exit 1 +[ ! -e "${tmpd}"/dir2/d1/f2 ] && echo 'not installed3' && exit 1 +grep 'header' "${tmpd}"/dir2/d1/f2 || (echo "header stripped" && exit 1) # children_link directory echo "* test link_children directory" -[ ! -d ${tmpd}/dir3 ] && echo 'not installed1' && exit 1 -[ ! -h ${tmpd}/dir3/s1 ] && echo 'not installed2' && exit 1 -[ ! -h ${tmpd}/dir3/s2 ] && echo 'not installed3' && exit 1 -[ ! -h ${tmpd}/dir3/s3 ] && echo 'not installed4' && exit 1 -[ ! -e ${tmpd}/dir3/s1/f1 ] && echo 'not installed5' && exit 1 -[ ! -e ${tmpd}/dir3/s2/f2 ] && echo 'not installed6' && exit 1 -grep 'header' ${tmpd}/dir3/s1/f1 || (echo "header stripped" && exit 1) -grep 'header' ${tmpd}/dir3/s2/f2 || (echo "header stripped" && exit 1) +[ ! -d "${tmpd}"/dir3 ] && echo 'not installed1' && exit 1 +[ ! -h "${tmpd}"/dir3/s1 ] && echo 'not installed2' && exit 1 +[ ! -h "${tmpd}"/dir3/s2 ] && echo 'not installed3' && exit 1 +[ ! -h "${tmpd}"/dir3/s3 ] && echo 'not installed4' && exit 1 +[ ! -e "${tmpd}"/dir3/s1/f1 ] && echo 'not installed5' && exit 1 +[ ! -e "${tmpd}"/dir3/s2/f2 ] && echo 'not installed6' && exit 1 +grep 'header' "${tmpd}"/dir3/s1/f1 || (echo "header stripped" && exit 1) +grep 'header' "${tmpd}"/dir3/s2/f2 || (echo "header stripped" && exit 1) # linked file echo "* test linked file" -[ ! -h ${tmpd}/fl ] && echo 'not installed' && exit 1 -grep 'header' ${tmpd}/f1 || (echo "header stripped" && exit 1) +[ ! -h "${tmpd}"/fl ] && echo 'not installed' && exit 1 +grep 'header' "${tmpd}"/f1 || (echo "header stripped" && exit 1) # normal dotfile echo "* normal dotfile" -[ ! -e ${tmpd}/fn ] && echo 'not installed' && exit 1 -grep 'should be stripped' ${tmpd}/fn && echo "not templated" && exit 1 +[ ! -e "${tmpd}"/fn ] && echo 'not installed' && exit 1 +grep 'should be stripped' "${tmpd}"/fn && echo "not templated" && exit 1 # test backup done -echo "before" > ${tmps}/dotfiles/f1 -cd ${ddpath} | ${bin} install -f --showdiff -c ${cfg} -p p1 -V -[ ! -e ${tmpd}/f1.dotdropbak ] && echo "backup not done" && exit 1 +echo "before" > "${tmps}"/dotfiles/f1 +cd "${ddpath}" | ${bin} install -f --showdiff -c "${cfg}" -p p1 -V +[ ! -e "${tmpd}"/f1.dotdropbak ] && echo "backup not done" && exit 1 # re-create the dotfile -echo "before" > ${tmps}/dotfiles/f1 -echo "{#@@ should not be stripped @@#}" >> ${tmps}/dotfiles/f1 -echo "{{@@ header() @@}}" >> ${tmps}/dotfiles/f1 -echo "after" >> ${tmps}/dotfiles/f1 +echo "before" > "${tmps}"/dotfiles/f1 +echo "{#@@ should not be stripped @@#}" >> "${tmps}"/dotfiles/f1 +echo "{{@@ header() @@}}" >> "${tmps}"/dotfiles/f1 +echo "after" >> "${tmps}"/dotfiles/f1 # through the dotfile -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -235,53 +238,53 @@ _EOF #cat ${cfg} # clean destination -rm -rf ${tmpd}/* +rm -rf "${tmpd}"/* # install -cd ${ddpath} | ${bin} install -f --showdiff -c ${cfg} -p p1 -V -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f --showdiff -c "${cfg}" -p p1 -V +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 -V # simple file echo "doing specifically" echo "* test simple file" -[ ! -e ${tmpd}/f1 ] && echo 'not installed1' && exit 1 -grep 'header' ${tmpd}/f1 || (echo "header stripped" && exit 1) -grep 'should not be stripped' ${tmpd}/f1 || (echo "comment stripped" && exit 1) +[ ! -e "${tmpd}"/f1 ] && echo 'not installed1' && exit 1 +grep 'header' "${tmpd}"/f1 || (echo "header stripped" && exit 1) +grep 'should not be stripped' "${tmpd}"/f1 || (echo "comment stripped" && exit 1) # directory echo "* test directory" -[ ! -d ${tmpd}/dir1 ] && echo 'not installed1' && exit 1 -[ ! -d ${tmpd}/dir1/d1 ] && echo 'not installed2' && exit 1 -[ ! -e ${tmpd}/dir1/d1/f2 ] && echo 'not installed3' && exit 1 -grep 'header' ${tmpd}/dir1/d1/f2 || (echo "header stripped" && exit 1) +[ ! -d "${tmpd}"/dir1 ] && echo 'not installed1' && exit 1 +[ ! -d "${tmpd}"/dir1/d1 ] && echo 'not installed2' && exit 1 +[ ! -e "${tmpd}"/dir1/d1/f2 ] && echo 'not installed3' && exit 1 +grep 'header' "${tmpd}"/dir1/d1/f2 || (echo "header stripped" && exit 1) # linked directory echo "* test linked directory" -[ ! -h ${tmpd}/dir2 ] && echo 'not installed1' && exit 1 -[ ! -d ${tmpd}/dir2/d1 ] && echo 'not installed2' && exit 1 -[ ! -e ${tmpd}/dir2/d1/f2 ] && echo 'not installed3' && exit 1 -grep 'header' ${tmpd}/dir2/d1/f2 || (echo "header stripped" && exit 1) +[ ! -h "${tmpd}"/dir2 ] && echo 'not installed1' && exit 1 +[ ! -d "${tmpd}"/dir2/d1 ] && echo 'not installed2' && exit 1 +[ ! -e "${tmpd}"/dir2/d1/f2 ] && echo 'not installed3' && exit 1 +grep 'header' "${tmpd}"/dir2/d1/f2 || (echo "header stripped" && exit 1) # children_link directory echo "* test link_children directory" -[ ! -d ${tmpd}/dir3 ] && echo 'not installed1' && exit 1 -[ ! -h ${tmpd}/dir3/s1 ] && echo 'not installed2' && exit 1 -[ ! -h ${tmpd}/dir3/s2 ] && echo 'not installed3' && exit 1 -[ ! -h ${tmpd}/dir3/s3 ] && echo 'not installed4' && exit 1 -[ ! -e ${tmpd}/dir3/s1/f1 ] && echo 'not installed5' && exit 1 -[ ! -e ${tmpd}/dir3/s2/f2 ] && echo 'not installed6' && exit 1 -grep 'header' ${tmpd}/dir3/s1/f1 || (echo "header stripped" && exit 1) -grep 'header' ${tmpd}/dir3/s2/f2 || (echo "header stripped" && exit 1) +[ ! -d "${tmpd}"/dir3 ] && echo 'not installed1' && exit 1 +[ ! -h "${tmpd}"/dir3/s1 ] && echo 'not installed2' && exit 1 +[ ! -h "${tmpd}"/dir3/s2 ] && echo 'not installed3' && exit 1 +[ ! -h "${tmpd}"/dir3/s3 ] && echo 'not installed4' && exit 1 +[ ! -e "${tmpd}"/dir3/s1/f1 ] && echo 'not installed5' && exit 1 +[ ! -e "${tmpd}"/dir3/s2/f2 ] && echo 'not installed6' && exit 1 +grep 'header' "${tmpd}"/dir3/s1/f1 || (echo "header stripped" && exit 1) +grep 'header' "${tmpd}"/dir3/s2/f2 || (echo "header stripped" && exit 1) # linked file echo "* test linked file" -[ ! -h ${tmpd}/fl ] && echo 'not installed' && exit 1 -grep 'header' ${tmpd}/f1 || (echo "header stripped" && exit 1) +[ ! -h "${tmpd}"/fl ] && echo 'not installed' && exit 1 +grep 'header' "${tmpd}"/f1 || (echo "header stripped" && exit 1) # normal dotfile echo "* normal dotfile" -[ ! -e ${tmpd}/fn ] && echo 'not installed' && exit 1 -grep 'should not be stripped' ${tmpd}/fn && echo "no templated" && exit 1 +[ ! -e "${tmpd}"/fn ] && echo 'not installed' && exit 1 +grep 'should not be stripped' "${tmpd}"/fn && echo "no templated" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/profile-actions.sh b/tests-ng/profile-actions.sh index c050efe..46e532e 100755 --- a/tests-ng/profile-actions.sh +++ b/tests-ng/profile-actions.sh @@ -28,32 +28,35 @@ 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}" # the action 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}" @@ -62,7 +65,7 @@ clear_on_exit "${tmpa}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -99,40 +102,40 @@ _EOF #cat ${cfg} # list profiles -cd ${ddpath} | ${bin} profiles -c ${cfg} -V +cd "${ddpath}" | ${bin} profiles -c "${cfg}" -V # create the dotfile -echo "test" > ${tmps}/dotfiles/abc -echo "test" > ${tmps}/dotfiles/def -echo "test" > ${tmps}/dotfiles/ghi +echo "test" > "${tmps}"/dotfiles/abc +echo "test" > "${tmps}"/dotfiles/def +echo "test" > "${tmps}"/dotfiles/ghi # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p0 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p0 -V # check actions executed -[ ! -e ${tmpa}/pre2 ] && echo 'action not executed' && exit 1 -[ ! -e ${tmpa}/post2 ] && echo 'action not executed' && exit 1 -[ ! -e ${tmpa}/naked ] && echo 'action not executed' && exit 1 +[ ! -e "${tmpa}"/pre2 ] && echo 'action not executed' && exit 1 +[ ! -e "${tmpa}"/post2 ] && echo 'action not executed' && exit 1 +[ ! -e "${tmpa}"/naked ] && echo 'action not executed' && exit 1 -grep pre2 ${tmpa}/pre2 -nb=`wc -l ${tmpa}/pre2 | awk '{print $1}'` +grep pre2 "${tmpa}"/pre2 +nb=$(wc -l "${tmpa}"/pre2 | awk '{print $1}') [ "${nb}" != "1" ] && echo "profile action executed multiple times" && exit 1 -grep post2 ${tmpa}/post2 -nb=`wc -l ${tmpa}/post2 | awk '{print $1}'` +grep post2 "${tmpa}"/post2 +nb=$(wc -l "${tmpa}"/post2 | awk '{print $1}') [ "${nb}" != "1" ] && echo "profile action executed multiple times" && exit 1 -grep naked ${tmpa}/naked -nb=`wc -l ${tmpa}/naked | awk '{print $1}'` +grep naked "${tmpa}"/naked +nb=$(wc -l "${tmpa}"/naked | awk '{print $1}') [ "${nb}" != "1" ] && echo "profile action executed multiple times" && exit 1 # install again -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p0 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p0 -V # check actions not executed twice -nb=`wc -l ${tmpa}/post2 | awk '{print $1}'` +nb=$(wc -l "${tmpa}"/post2 | awk '{print $1}') [ "${nb}" -gt "1" ] && echo "action post2 executed twice" && exit 1 -nb=`wc -l ${tmpa}/naked | awk '{print $1}'` +nb=$(wc -l "${tmpa}"/naked | awk '{print $1}') [ "${nb}" -gt "1" ] && echo "action naked executed twice" && exit 1 echo "OK" diff --git a/tests-ng/profile-dyninclude.sh b/tests-ng/profile-dyninclude.sh index 94bd7c8..37ed483 100755 --- a/tests-ng/profile-dyninclude.sh +++ b/tests-ng/profile-dyninclude.sh @@ -28,29 +28,32 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -59,7 +62,7 @@ clear_on_exit "${tmpd}" cfg="${tmps}/config.yaml" cfg2="${tmps}/sub.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: dotpath: dotfiles import_configs: @@ -85,7 +88,7 @@ profiles: _EOF #cat ${cfg} -cat > ${cfg2} << _EOF +cat > "${cfg2}" << _EOF config: dotfiles: f_abc: @@ -120,26 +123,26 @@ _EOF #cat ${cfg2} # create the dotfile -echo "start" > ${tmps}/dotfiles/abc -echo "{{@@ mainvar @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ maindyn @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ subdyn @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ subvar @@}}" >> ${tmps}/dotfiles/abc -echo "end" >> ${tmps}/dotfiles/abc +echo "start" > "${tmps}"/dotfiles/abc +echo "{{@@ mainvar @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ maindyn @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ subdyn @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ subvar @@}}" >> "${tmps}"/dotfiles/abc +echo "end" >> "${tmps}"/dotfiles/abc #cat ${tmps}/dotfiles/abc -echo "ghi content" > ${tmps}/dotfiles/ghi +echo "ghi content" > "${tmps}"/dotfiles/ghi # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p profile_1 --verbose +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p profile_1 --verbose # check dotfile exists -[ ! -e ${tmpd}/abc ] && exit 1 -grep 'maincontent' ${tmpd}/abc >/dev/null || (echo "variables 1 not resolved" && exit 1) -grep 'maindyncontent' ${tmpd}/abc >/dev/null || (echo "dynvariables 1 not resolved" && exit 1) -grep 'subcontent' ${tmpd}/abc >/dev/null || (echo "variables 2 not resolved" && exit 1) -grep 'subdyncontent' ${tmpd}/abc >/dev/null || (echo "dynvariables 2 not resolved" && exit 1) +[ ! -e "${tmpd}"/abc ] && exit 1 +grep 'maincontent' "${tmpd}"/abc >/dev/null || (echo "variables 1 not resolved" && exit 1) +grep 'maindyncontent' "${tmpd}"/abc >/dev/null || (echo "dynvariables 1 not resolved" && exit 1) +grep 'subcontent' "${tmpd}"/abc >/dev/null || (echo "variables 2 not resolved" && exit 1) +grep 'subdyncontent' "${tmpd}"/abc >/dev/null || (echo "dynvariables 2 not resolved" && exit 1) #cat ${tmpd}/abc -[ ! -e ${tmpd}/ghi ] && exit 1 +[ ! -e "${tmpd}"/ghi ] && exit 1 echo "OK" exit 0 diff --git a/tests-ng/profile-dynvariables.sh b/tests-ng/profile-dynvariables.sh index b7323ae..2574a11 100755 --- a/tests-ng/profile-dynvariables.sh +++ b/tests-ng/profile-dynvariables.sh @@ -28,29 +28,32 @@ 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}" clear_on_exit "${tmps}" @@ -58,14 +61,14 @@ clear_on_exit "${tmpd}" # create a shell script export TESTENV="this is my global testenv" -scr=`mktemp --suffix='-dotdrop-tests' || mktemp -d` -chmod +x ${scr} -echo -e "#!/bin/bash\necho $TESTENV\n" >> ${scr} +scr=$(mktemp --suffix='-dotdrop-tests' || mktemp -d) +chmod +x "${scr}" +echo -e "#!/bin/bash\necho $TESTENV\n" >> "${scr}" export TESTENV2="this is my profile testenv" -scr2=`mktemp --suffix='-dotdrop-tests' || mktemp -d` -chmod +x ${scr2} -echo -e "#!/bin/bash\necho $TESTENV2\n" >> ${scr2} +scr2=$(mktemp --suffix='-dotdrop-tests' || mktemp -d) +chmod +x "${scr2}" +echo -e "#!/bin/bash\necho $TESTENV2\n" >> "${scr2}" clear_on_exit "${scr}" clear_on_exit "${scr2}" @@ -73,7 +76,7 @@ clear_on_exit "${scr2}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -103,30 +106,30 @@ _EOF #cat ${cfg} # create the dotfile -echo "===================" > ${tmps}/dotfiles/abc -echo "{{@@ gvar1 @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ gvar2 @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ gdvar1 @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ gdvar2 @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ gdvar3 @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ lvar1 @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ pdvar1 @@}}" >> ${tmps}/dotfiles/abc -echo "===================" >> ${tmps}/dotfiles/abc +echo "===================" > "${tmps}"/dotfiles/abc +echo "{{@@ gvar1 @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ gvar2 @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ gdvar1 @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ gdvar2 @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ gdvar3 @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ lvar1 @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ pdvar1 @@}}" >> "${tmps}"/dotfiles/abc +echo "===================" >> "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V -cat ${tmpd}/abc +cat "${tmpd}"/abc # test variables -grep '^local1' ${tmpd}/abc >/dev/null -grep '^global2' ${tmpd}/abc >/dev/null -grep '^local2' ${tmpd}/abc >/dev/null +grep '^local1' "${tmpd}"/abc >/dev/null +grep '^global2' "${tmpd}"/abc >/dev/null +grep '^local2' "${tmpd}"/abc >/dev/null # test dynvariables -grep "^# author: deadc0de6" ${tmpd}/abc >/dev/null -grep '^tset,emos,si,siht' ${tmpd}/abc >/dev/null -grep "^${TESTENV2}" ${tmpd}/abc > /dev/null -grep "^cba" ${tmpd}/abc >/dev/null +grep "^# author: deadc0de6" "${tmpd}"/abc >/dev/null +grep '^tset,emos,si,siht' "${tmpd}"/abc >/dev/null +grep "^${TESTENV2}" "${tmpd}"/abc > /dev/null +grep "^cba" "${tmpd}"/abc >/dev/null #cat ${tmpd}/abc diff --git a/tests-ng/profile-import-dotfiles.sh b/tests-ng/profile-import-dotfiles.sh index d0fa00b..42f7424 100755 --- a/tests-ng/profile-import-dotfiles.sh +++ b/tests-ng/profile-import-dotfiles.sh @@ -29,29 +29,32 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -64,7 +67,7 @@ src="dotdrop-test" dst=".dotdrop-test" clear_on_exit "${HOME}/${dst}" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: dotpath: dotfiles dotfiles: @@ -81,32 +84,32 @@ profiles: dotfiles: - f_abc _EOF -cat ${cfg} +cat "${cfg}" -cat > ${cfg2} << _EOF +cat > "${cfg2}" << _EOF dotfiles: - f_def _EOF #cat ${cfg2} # create the dotfile -echo "abc" > ${tmps}/dotfiles/abc -echo "abc" > ${tmpd}/abc -echo "def" > ${tmps}/dotfiles/${src} -echo "def" > ${HOME}/${dst} +echo "abc" > "${tmps}"/dotfiles/abc +echo "abc" > "${tmpd}"/abc +echo "def" > "${tmps}"/dotfiles/${src} +echo "def" > "${HOME}"/${dst} # import ## this is a special case since the dotfile must ## be in home (because it is strip) -echo ${ddpath} -echo ${bin} -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 --verbose ~/${dst} +echo "${ddpath}" +echo "${bin}" +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 --verbose ~/${dst} -cat ${cfg} +cat "${cfg}" echo '----------' -cat ${cfg2} +cat "${cfg2}" -cnt=$(cd ${ddpath} | ${bin} files -G -c ${cfg} -p p1 | grep '^f_def' | wc -l) +cnt=$(cd "${ddpath}" | ${bin} files -G -c "${cfg}" -p p1 | grep '^f_def' | wc -l) [ "${cnt}" != "1" ] && echo "imported twice! (${cnt})" && exit 1 echo "OK" diff --git a/tests-ng/profile-undefined-variables.sh b/tests-ng/profile-undefined-variables.sh index 0e6cf23..b803d08 100755 --- a/tests-ng/profile-undefined-variables.sh +++ b/tests-ng/profile-undefined-variables.sh @@ -29,29 +29,32 @@ 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}" clear_on_exit "${tmps}" @@ -60,7 +63,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -96,29 +99,29 @@ _EOF #cat ${cfg} # create the dotfile -echo "main" > ${tmps}/dotfiles/abc -echo "alt" > ${tmps}/dotfiles/def +echo "main" > "${tmps}"/dotfiles/abc +echo "alt" > "${tmps}"/dotfiles/def # install pmain echo "install pmain" -cd ${ddpath} | ${bin} install -f -c ${cfg} -p pmain -V -[ ! -e ${tmpd}/abc ] && echo "dotfile not installed" && exit 1 -grep main ${tmpd}/abc +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p pmain -V +[ ! -e "${tmpd}"/abc ] && echo "dotfile not installed" && exit 1 +grep main "${tmpd}"/abc # install pall echo "install pall" -cd ${ddpath} | ${bin} install -f -c ${cfg} -p pall -V -[ ! -e ${tmpd}/abcall ] && echo "dotfile not installed" && exit 1 -grep main ${tmpd}/abcall -[ ! -e ${tmpd}/defall ] && echo "dotfile not installed" && exit 1 -grep alt ${tmpd}/defall +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p pall -V +[ ! -e "${tmpd}"/abcall ] && echo "dotfile not installed" && exit 1 +grep main "${tmpd}"/abcall +[ ! -e "${tmpd}"/defall ] && echo "dotfile not installed" && exit 1 +grep alt "${tmpd}"/defall # install pinclude echo "install pinclude" -rm -f ${tmpd}/abc -cd ${ddpath} | ${bin} install -f -c ${cfg} -p pinclude -V -[ ! -e ${tmpd}/abc ] && echo "dotfile not installed" && exit 1 -grep main ${tmpd}/abc +rm -f "${tmpd}"/abc +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p pinclude -V +[ ! -e "${tmpd}"/abc ] && echo "dotfile not installed" && exit 1 +grep main "${tmpd}"/abc echo "OK" exit 0 diff --git a/tests-ng/re-import.sh b/tests-ng/re-import.sh index 1bd7c6c..98fb149 100755 --- a/tests-ng/re-import.sh +++ b/tests-ng/re-import.sh @@ -27,42 +27,45 @@ 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}" clear_on_exit "${tmps}" clear_on_exit "${tmpd}" -clear_on_exit "~/.dotdrop-test" +clear_on_exit "${HOME}/.dotdrop-test" # create the dotfile -echo "original" > ${tmpd}/testfile +echo "original" > "${tmpd}"/testfile # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -74,39 +77,39 @@ _EOF # import echo "[+] import file" -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/testfile -cat ${cfg} +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/testfile +cat "${cfg}" # ensure exists and is not link -[ ! -e ${tmps}/dotfiles/${tmpd}/testfile ] && echo "does not exist" && exit 1 -cat ${cfg} | grep ${tmpd}/testfile >/dev/null 2>&1 -grep 'original' ${tmps}/dotfiles/${tmpd}/testfile -nb=`cat ${cfg} | grep ${tmpd}/testfile | wc -l` +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/testfile ] && echo "does not exist" && exit 1 +cat "${cfg}" | grep "${tmpd}"/testfile >/dev/null 2>&1 +grep 'original' "${tmps}"/dotfiles/"${tmpd}"/testfile +nb=$(cat "${cfg}" | grep "${tmpd}"/testfile | wc -l) [ "${nb}" != "1" ] && echo 'not 1 entry' && exit 1 # re-import without changing echo "[+] re-import without changes" -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/testfile -cat ${cfg} +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/testfile +cat "${cfg}" # test is only once -[ ! -e ${tmps}/dotfiles/${tmpd}/testfile ] && echo "does not exist" && exit 1 -cat ${cfg} | grep ${tmpd}/testfile >/dev/null 2>&1 -grep 'original' ${tmps}/dotfiles/${tmpd}/testfile -nb=`cat ${cfg} | grep ${tmpd}/testfile | wc -l` +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/testfile ] && echo "does not exist" && exit 1 +cat "${cfg}" | grep "${tmpd}"/testfile >/dev/null 2>&1 +grep 'original' "${tmps}"/dotfiles/"${tmpd}"/testfile +nb=$(cat "${cfg}" | grep "${tmpd}"/testfile | wc -l) [ "${nb}" != "1" ] && echo 'two entries!' && exit 1 # re-import with changes echo "[+] re-import with changes" -echo 'modified' > ${tmpd}/testfile -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/testfile -cat ${cfg} +echo 'modified' > "${tmpd}"/testfile +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V "${tmpd}"/testfile +cat "${cfg}" # test is only once -[ ! -e ${tmps}/dotfiles/${tmpd}/testfile ] && echo "does not exist" && exit 1 -cat ${cfg} | grep ${tmpd}/testfile >/dev/null 2>&1 -grep 'modified' ${tmps}/dotfiles/${tmpd}/testfile -nb=`cat ${cfg} | grep ${tmpd}/testfile | wc -l` +[ ! -e "${tmps}"/dotfiles/"${tmpd}"/testfile ] && echo "does not exist" && exit 1 +cat "${cfg}" | grep "${tmpd}"/testfile >/dev/null 2>&1 +grep 'modified' "${tmps}"/dotfiles/"${tmpd}"/testfile +nb=$(cat "${cfg}" | grep "${tmpd}"/testfile | wc -l) [ "${nb}" != "1" ] && echo 'two entries!' && exit 1 # ################################################### @@ -114,39 +117,39 @@ nb=`cat ${cfg} | grep ${tmpd}/testfile | wc -l` echo 'original' > "${HOME}/.dotdrop.test" # import in home echo "[+] import file in home" -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ~/.dotdrop.test -cat ${cfg} +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V ~/.dotdrop.test +cat "${cfg}" # ensure exists and is not link [ ! -e "${tmps}/dotfiles/dotdrop.test" ] && echo "does not exist" && exit 1 -cat ${cfg} | grep "~/.dotdrop.test" >/dev/null 2>&1 -grep 'original' ${tmps}/dotfiles/dotdrop.test -nb=`cat ${cfg} | grep "~/.dotdrop.test" | wc -l` +cat "${cfg}" | grep "${HOME}/.dotdrop.test" >/dev/null 2>&1 +grep 'original' "${tmps}"/dotfiles/dotdrop.test +nb=$(cat "${cfg}" | grep "${HOME}/.dotdrop.test" | wc -l) [ "${nb}" != "1" ] && echo 'not 1 entry' && exit 1 # re-import without changing echo "[+] re-import without changes in home" -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ~/.dotdrop.test -cat ${cfg} +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V ~/.dotdrop.test +cat "${cfg}" # test is only once [ ! -e "${tmps}/dotfiles/dotdrop.test" ] && echo "does not exist" && exit 1 -cat ${cfg} | grep "~/.dotdrop.test" >/dev/null 2>&1 -grep 'original' ${tmps}/dotfiles/dotdrop.test -nb=`cat ${cfg} | grep "~/.dotdrop.test" | wc -l` +cat "${cfg}" | grep "${HOME}/.dotdrop.test" >/dev/null 2>&1 +grep 'original' "${tmps}"/dotfiles/dotdrop.test +nb=$(cat "${cfg}" | grep "${HOME}/.dotdrop.test" | wc -l) [ "${nb}" != "1" ] && echo 'two entries!' && exit 1 # re-import with changes echo "[+] re-import with changes in home" echo 'modified' > ~/.dotdrop.test -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ~/.dotdrop.test -cat ${cfg} +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -V ~/.dotdrop.test +cat "${cfg}" # test is only once [ ! -e "${tmps}/dotfiles/dotdrop.test" ] && echo "does not exist" && exit 1 -cat ${cfg} | grep "~/.dotdrop.test" >/dev/null 2>&1 -grep 'modified' ${tmps}/dotfiles/dotdrop.test -nb=`cat ${cfg} | grep "~/.dotdrop.test" | wc -l` +cat "${cfg}" | grep "${HOME}/.dotdrop.test" >/dev/null 2>&1 +grep 'modified' "${tmps}"/dotfiles/dotdrop.test +nb=$(cat "${cfg}" | grep "${HOME}/.dotdrop.test" | wc -l) [ "${nb}" != "1" ] && echo 'two entries!' && exit 1 echo "OK" diff --git a/tests-ng/recinclude.sh b/tests-ng/recinclude.sh index 5cf2b55..3f9da4b 100755 --- a/tests-ng/recinclude.sh +++ b/tests-ng/recinclude.sh @@ -28,29 +28,32 @@ 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) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" @@ -58,7 +61,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -85,26 +88,26 @@ profiles: _EOF # create the source -mkdir -p ${tmps}/dotfiles/ +mkdir -p "${tmps}"/dotfiles/ content_abc="testrecinclude_abc" -echo "${content_abc}" > ${tmps}/dotfiles/abc +echo "${content_abc}" > "${tmps}"/dotfiles/abc content_def="testrecinclude_def" -echo "${content_def}" > ${tmps}/dotfiles/def +echo "${content_def}" > "${tmps}"/dotfiles/def # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p host -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p host -V # checks -[ ! -e ${tmpd}/abc ] && echo "abc not installed" && exit 1 +[ ! -e "${tmpd}"/abc ] && echo "abc not installed" && exit 1 echo "abc installed" -grep ${content_abc} ${tmpd}/abc +grep ${content_abc} "${tmpd}"/abc -[ ! -e ${tmpd}/def ] && echo "def not installed" && exit 1 +[ ! -e "${tmpd}"/def ] && echo "def not installed" && exit 1 echo "def installed" -grep ${content_def} ${tmpd}/def +grep ${content_def} "${tmpd}"/def # test cyclic include -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -134,7 +137,7 @@ _EOF # install set +e -cd ${ddpath} | ${bin} install -f -c ${cfg} -p host -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p host -V [ "$?" = 0 ] && exit 1 set -e diff --git a/tests-ng/recvariables.sh b/tests-ng/recvariables.sh index c1c7369..ebb7f2b 100755 --- a/tests-ng/recvariables.sh +++ b/tests-ng/recvariables.sh @@ -28,29 +28,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 +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}" clear_on_exit "${tmps}" @@ -59,7 +63,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -86,22 +90,22 @@ _EOF #cat ${cfg} # create the dotfile -echo "var3: {{@@ var3 @@}}" > ${tmps}/dotfiles/abc -echo "dvar3: {{@@ dvar3 @@}}" >> ${tmps}/dotfiles/abc -echo "var4: {{@@ var4 @@}}" >> ${tmps}/dotfiles/abc -echo "dvar4: {{@@ dvar4 @@}}" >> ${tmps}/dotfiles/abc +echo "var3: {{@@ var3 @@}}" > "${tmps}"/dotfiles/abc +echo "dvar3: {{@@ dvar3 @@}}" >> "${tmps}"/dotfiles/abc +echo "var4: {{@@ var4 @@}}" >> "${tmps}"/dotfiles/abc +echo "dvar4: {{@@ dvar4 @@}}" >> "${tmps}"/dotfiles/abc #cat ${tmps}/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V #cat ${tmpd}/abc -grep '^var3: var1 var2 var3' ${tmpd}/abc >/dev/null -grep '^dvar3: dvar1 dvar2 dvar3' ${tmpd}/abc >/dev/null -grep '^var4: echo var1 var2 var3' ${tmpd}/abc >/dev/null -grep '^dvar4: var1 var2 var3' ${tmpd}/abc >/dev/null +grep '^var3: var1 var2 var3' "${tmpd}"/abc >/dev/null +grep '^dvar3: dvar1 dvar2 dvar3' "${tmpd}"/abc >/dev/null +grep '^var4: echo var1 var2 var3' "${tmpd}"/abc >/dev/null +grep '^dvar4: var1 var2 var3' "${tmpd}"/abc >/dev/null #cat ${tmpd}/abc diff --git a/tests-ng/remove.sh b/tests-ng/remove.sh index 854f047..90b7862 100755 --- a/tests-ng/remove.sh +++ b/tests-ng/remove.sh @@ -28,36 +28,39 @@ 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 ################################################################ # dotdrop directory -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 to be imported -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -85,44 +88,44 @@ profiles: - f_last _EOF cfgbak="${tmps}/config.yaml.bak" -cp ${cfg} ${cfgbak} +cp "${cfg}" "${cfgbak}" # create the dotfile -echo "abc" > ${tmps}/dotfiles/abc -echo "abc" > ${tmpd}/abc +echo "abc" > "${tmps}"/dotfiles/abc +echo "abc" > "${tmpd}"/abc -echo "def" > ${tmps}/dotfiles/def -echo "def" > ${tmpd}/def +echo "def" > "${tmps}"/dotfiles/def +echo "def" > "${tmpd}"/def # remove with bad profile -cd ${ddpath} | ${bin} remove -f -k -p empty -c ${cfg} f_abc -V -[ ! -e ${tmps}/dotfiles/abc ] && echo "dotfile in dotpath deleted" && exit 1 -[ ! -e ${tmpd}/abc ] && echo "source dotfile deleted" && exit 1 -[ ! -e ${tmps}/dotfiles/def ] && echo "dotfile in dotpath deleted" && exit 1 -[ ! -e ${tmpd}/def ] && echo "source dotfile deleted" && exit 1 +cd "${ddpath}" | ${bin} remove -f -k -p empty -c "${cfg}" f_abc -V +[ ! -e "${tmps}"/dotfiles/abc ] && echo "dotfile in dotpath deleted" && exit 1 +[ ! -e "${tmpd}"/abc ] && echo "source dotfile deleted" && exit 1 +[ ! -e "${tmps}"/dotfiles/def ] && echo "dotfile in dotpath deleted" && exit 1 +[ ! -e "${tmpd}"/def ] && echo "source dotfile deleted" && exit 1 # ensure config not altered -diff ${cfg} ${cfgbak} +diff "${cfg}" "${cfgbak}" # remove by key echo "[+] remove f_abc by key" -cd ${ddpath} | ${bin} remove -p p1 -f -k -c ${cfg} f_abc -V -cat ${cfg} +cd "${ddpath}" | ${bin} remove -p p1 -f -k -c "${cfg}" f_abc -V +cat "${cfg}" echo "[+] remove f_def by key" -cd ${ddpath} | ${bin} remove -p p2 -f -k -c ${cfg} f_def -V -cat ${cfg} +cd "${ddpath}" | ${bin} remove -p p2 -f -k -c "${cfg}" f_def -V +cat "${cfg}" # checks -[ -e ${tmps}/dotfiles/abc ] && echo "dotfile in dotpath not deleted" && exit 1 -[ ! -e ${tmpd}/abc ] && echo "source dotfile deleted" && exit 1 +[ -e "${tmps}"/dotfiles/abc ] && echo "dotfile in dotpath not deleted" && exit 1 +[ ! -e "${tmpd}"/abc ] && echo "source dotfile deleted" && exit 1 -[ -e ${tmps}/dotfiles/def ] && echo "dotfile in dotpath not deleted" && exit 1 -[ ! -e ${tmpd}/def ] && echo "source dotfile deleted" && exit 1 +[ -e "${tmps}"/dotfiles/def ] && echo "dotfile in dotpath not deleted" && exit 1 +[ ! -e "${tmpd}"/def ] && echo "source dotfile deleted" && exit 1 echo "[+] =========" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -149,32 +152,32 @@ profiles: dotfiles: - f_last _EOF -cat ${cfg} +cat "${cfg}" # create the dotfile -echo "abc" > ${tmps}/dotfiles/abc -echo "abc" > ${tmpd}/abc +echo "abc" > "${tmps}"/dotfiles/abc +echo "abc" > "${tmpd}"/abc -echo "def" > ${tmps}/dotfiles/def -echo "def" > ${tmpd}/def +echo "def" > "${tmps}"/dotfiles/def +echo "def" > "${tmpd}"/def # remove by key echo "[+] remove f_abc by path" -cd ${ddpath} | ${bin} remove -p p1 -f -c ${cfg} ${tmpd}/abc -V -cat ${cfg} +cd "${ddpath}" | ${bin} remove -p p1 -f -c "${cfg}" "${tmpd}"/abc -V +cat "${cfg}" echo "[+] remove f_def by path" -cd ${ddpath} | ${bin} remove -p p2 -f -c ${cfg} ${tmpd}/def -V -cat ${cfg} +cd "${ddpath}" | ${bin} remove -p p2 -f -c "${cfg}" "${tmpd}"/def -V +cat "${cfg}" # checks -[ -e ${tmps}/dotfiles/abc ] && echo "(2) dotfile in dotpath not deleted" && exit 1 -[ ! -e ${tmpd}/abc ] && echo "(2) source dotfile deleted" && exit 1 +[ -e "${tmps}"/dotfiles/abc ] && echo "(2) dotfile in dotpath not deleted" && exit 1 +[ ! -e "${tmpd}"/abc ] && echo "(2) source dotfile deleted" && exit 1 -[ -e ${tmps}/dotfiles/def ] && echo "(2) dotfile in dotpath not deleted" && exit 1 -[ ! -e ${tmpd}/def ] && echo "(2) source dotfile deleted" && exit 1 +[ -e "${tmps}"/dotfiles/def ] && echo "(2) dotfile in dotpath not deleted" && exit 1 +[ ! -e "${tmpd}"/def ] && echo "(2) source dotfile deleted" && exit 1 -cat ${cfg} +cat "${cfg}" echo "OK" exit 0 diff --git a/tests-ng/symlink-relative.sh b/tests-ng/symlink-relative.sh index 8534d3a..8bd6690 100755 --- a/tests-ng/symlink-relative.sh +++ b/tests-ng/symlink-relative.sh @@ -27,31 +27,34 @@ 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}" -tmpw=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpw=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) export DOTDROP_WORKDIR="${tmpw}" clear_on_exit "${tmps}" @@ -62,16 +65,16 @@ clear_on_exit "${tmpw}" # test symlink directory ################################################## # create the file -echo "file1" > ${tmps}/dotfiles/abc -mkdir -p ${tmps}/dotfiles/def -echo 'file2' > ${tmps}/dotfiles/def/afile -echo '{{@@ header() @@}}' > ${tmps}/dotfiles/ghi -mkdir -p ${tmps}/dotfiles/jkl -echo '{{@@ header() @@}}' > ${tmps}/dotfiles/jkl/anotherfile +echo "file1" > "${tmps}"/dotfiles/abc +mkdir -p "${tmps}"/dotfiles/def +echo 'file2' > "${tmps}"/dotfiles/def/afile +echo '{{@@ header() @@}}' > "${tmps}"/dotfiles/ghi +mkdir -p "${tmps}"/dotfiles/jkl +echo '{{@@ header() @@}}' > "${tmps}"/dotfiles/jkl/anotherfile # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -111,54 +114,58 @@ _EOF #cat ${cfg} # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V # ensure exists and is link -[ ! -h ${tmpd}/abc ] && echo "not a symlink" && exit 1 -[ ! -h ${tmpd}/abc2 ] && echo "not a symlink" && exit 1 -[ ! -h ${tmpd}/def ] && echo "not a symlink" && exit 1 -[ ! -d ${tmpd}/def ] && echo "not a symlink" && exit 1 -[ ! -h ${tmpd}/ghi ] && echo "not a symlink" && exit 1 -[ ! -h ${tmpd}/jkl ] && echo "not a symlink" && exit 1 -[ ! -d ${tmpd}/jkl ] && echo "not a symlink" && exit 1 +[ ! -h "${tmpd}"/abc ] && echo "not a symlink" && exit 1 +[ ! -h "${tmpd}"/abc2 ] && echo "not a symlink" && exit 1 +[ ! -h "${tmpd}"/def ] && echo "not a symlink" && exit 1 +[ ! -d "${tmpd}"/def ] && echo "not a symlink" && exit 1 +[ ! -h "${tmpd}"/ghi ] && echo "not a symlink" && exit 1 +[ ! -h "${tmpd}"/jkl ] && echo "not a symlink" && exit 1 +[ ! -d "${tmpd}"/jkl ] && echo "not a symlink" && exit 1 -ls -l ${tmpd}/abc | grep '\.\.' || exit 1 -ls -l ${tmpd}/abc2 -ls -l ${tmpd}/def | grep '\.\.' || exit 1 -ls -l ${tmpd}/ghi | grep '\.\.' || exit 1 -ls -l ${tmpd}/jkl | grep '\.\.' || exit 1 +# shellcheck disable=SC2010 +ls -l "${tmpd}"/abc | grep '\.\.' || exit 1 +ls -l "${tmpd}"/abc2 +# shellcheck disable=SC2010 +ls -l "${tmpd}"/def | grep '\.\.' || exit 1 +# shellcheck disable=SC2010 +ls -l "${tmpd}"/ghi | grep '\.\.' || exit 1 +# shellcheck disable=SC2010 +ls -l "${tmpd}"/jkl | grep '\.\.' || exit 1 -grep 'file1' ${tmpd}/abc -grep 'file1' ${tmpd}/abc2 -grep 'file2' ${tmpd}/def/afile -grep 'This dotfile is managed using dotdrop' ${tmpd}/ghi -grep 'This dotfile is managed using dotdrop' ${tmpd}/jkl/anotherfile +grep 'file1' "${tmpd}"/abc +grep 'file1' "${tmpd}"/abc2 +grep 'file2' "${tmpd}"/def/afile +grep 'This dotfile is managed using dotdrop' "${tmpd}"/ghi +grep 'This dotfile is managed using dotdrop' "${tmpd}"/jkl/anotherfile -[[ $(realpath --relative-base="${tmpw}" -- "$(realpath ${tmpd}/ghi)") =~ "^/" ]] && echo "ghi not subpath of workdir" && exit 1 -[[ $(realpath --relative-base="${tmpw}" -- "$(realpath ${tmpd}/jkl)") =~ ^/ ]] && echo "jkl not subpath of workdir" && exit 1 +[[ $(realpath --relative-base="${tmpw}" -- "$(realpath "${tmpd}"/ghi)") =~ "^/" ]] && echo "ghi not subpath of workdir" && exit 1 +[[ $(realpath --relative-base="${tmpw}" -- "$(realpath "${tmpd}"/jkl)") =~ ^/ ]] && echo "jkl not subpath of workdir" && exit 1 ############################################################################################################################# -rm -rf ${tmps} ${tmpd} ${tmpw} +rm -rf "${tmps}" "${tmpd}" "${tmpw}" # 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 tmpd="${tmps}" -mkdir -p ${tmpd} +mkdir -p "${tmpd}" clear_on_exit "${tmps}" clear_on_exit "${tmpd}" # create the file -echo "file1" > ${tmps}/dotfiles/abc -mkdir -p ${tmps}/dotfiles/def -echo 'file2' > ${tmps}/dotfiles/def/afile +echo "file1" > "${tmps}"/dotfiles/abc +mkdir -p "${tmps}"/dotfiles/def +echo 'file2' > "${tmps}"/dotfiles/def/afile # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -188,17 +195,17 @@ _EOF #cat ${cfg} # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V # ensure exists and is link -[ ! -h ${tmpd}/abc ] && echo "not a symlink" && exit 1 -[ ! -h ${tmpd}/abc2 ] && echo "not a symlink" && exit 1 -[ ! -h ${tmpd}/def ] && echo "not a symlink" && exit 1 -[ ! -d ${tmpd}/def ] && echo "not a symlink" && exit 1 +[ ! -h "${tmpd}"/abc ] && echo "not a symlink" && exit 1 +[ ! -h "${tmpd}"/abc2 ] && echo "not a symlink" && exit 1 +[ ! -h "${tmpd}"/def ] && echo "not a symlink" && exit 1 +[ ! -d "${tmpd}"/def ] && echo "not a symlink" && exit 1 -grep 'file1' ${tmpd}/abc -grep 'file1' ${tmpd}/abc2 -grep 'file2' ${tmpd}/def/afile +grep 'file1' "${tmpd}"/abc +grep 'file1' "${tmpd}"/abc2 +grep 'file2' "${tmpd}"/def/afile echo "OK" exit 0 diff --git a/tests-ng/symlink.sh b/tests-ng/symlink.sh index 8f8b8c1..0806ac2 100755 --- a/tests-ng/symlink.sh +++ b/tests-ng/symlink.sh @@ -27,29 +27,32 @@ 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}" clear_on_exit "${tmps}" @@ -59,15 +62,15 @@ clear_on_exit "${tmpd}" # test symlink directory ################################################## # create the dotfile -mkdir -p ${tmps}/dotfiles/abc -echo "file1" > ${tmps}/dotfiles/abc/file1 -echo "file2" > ${tmps}/dotfiles/abc/file2 +mkdir -p "${tmps}"/dotfiles/abc +echo "file1" > "${tmps}"/dotfiles/abc/file1 +echo "file2" > "${tmps}"/dotfiles/abc/file2 # create a shell script # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -86,29 +89,29 @@ _EOF #cat ${cfg} # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V #cat ${cfg} # ensure exists and is link -[ ! -h ${tmpd}/abc ] && echo "not a symlink" && exit 1 -[ ! -e ${tmpd}/abc/file1 ] && echo "does not exist" && exit 1 -[ ! -e ${tmpd}/abc/file2 ] && echo "does not exist" && exit 1 +[ ! -h "${tmpd}"/abc ] && echo "not a symlink" && exit 1 +[ ! -e "${tmpd}"/abc/file1 ] && echo "does not exist" && exit 1 +[ ! -e "${tmpd}"/abc/file2 ] && echo "does not exist" && exit 1 ################################################## # test symlink files ################################################## # clean -rm -rf ${tmps}/dotfiles ${tmpd}/abc +rm -rf "${tmps}"/dotfiles "${tmpd}"/abc # create the dotfiles -mkdir -p ${tmps}/dotfiles/ -echo "abc" > ${tmps}/dotfiles/abc +mkdir -p "${tmps}"/dotfiles/ +echo "abc" > "${tmps}"/dotfiles/abc # create a shell script # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -127,28 +130,28 @@ _EOF #cat ${cfg} # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V #cat ${cfg} # ensure exists and is link -[ ! -h ${tmpd}/abc ] && echo "not a symlink" && exit 1 +[ ! -h "${tmpd}"/abc ] && echo "not a symlink" && exit 1 ################################################## # test link_children ################################################## # clean -rm -rf ${tmps}/dotfiles ${tmpd}/abc +rm -rf "${tmps}"/dotfiles "${tmpd}"/abc # create the dotfile -mkdir -p ${tmps}/dotfiles/abc -echo "file1" > ${tmps}/dotfiles/abc/file1 -echo "file2" > ${tmps}/dotfiles/abc/file2 +mkdir -p "${tmps}"/dotfiles/abc +echo "file1" > "${tmps}"/dotfiles/abc/file1 +echo "file2" > "${tmps}"/dotfiles/abc/file2 # create a shell script # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -167,30 +170,30 @@ _EOF #cat ${cfg} # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V #cat ${cfg} # ensure exists and is link -[ ! -d ${tmpd}/abc ] && echo "not a symlink" && exit 1 -[ ! -h ${tmpd}/abc/file1 ] && echo "does not exist" && exit 1 -[ ! -h ${tmpd}/abc/file2 ] && echo "does not exist" && exit 1 +[ ! -d "${tmpd}"/abc ] && echo "not a symlink" && exit 1 +[ ! -h "${tmpd}"/abc/file1 ] && echo "does not exist" && exit 1 +[ ! -h "${tmpd}"/abc/file2 ] && echo "does not exist" && exit 1 ################################################## # test link_children with templates ################################################## # clean -rm -rf ${tmps}/dotfiles ${tmpd}/abc +rm -rf "${tmps}"/dotfiles "${tmpd}"/abc # create the dotfile -mkdir -p ${tmps}/dotfiles/abc -echo "{{@@ profile @@}}" > ${tmps}/dotfiles/abc/file1 -echo "file2" > ${tmps}/dotfiles/abc/file2 +mkdir -p "${tmps}"/dotfiles/abc +echo "{{@@ profile @@}}" > "${tmps}"/dotfiles/abc/file1 +echo "file2" > "${tmps}"/dotfiles/abc/file2 # create a shell script # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -209,14 +212,14 @@ _EOF #cat ${cfg} # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V #cat ${cfg} # ensure exists and is link -[ ! -d ${tmpd}/abc ] && echo "not a symlink" && exit 1 -[ ! -h ${tmpd}/abc/file1 ] && echo "does not exist" && exit 1 -[ ! -h ${tmpd}/abc/file2 ] && echo "does not exist" && exit 1 -grep '^p1$' ${tmpd}/abc/file1 +[ ! -d "${tmpd}"/abc ] && echo "not a symlink" && exit 1 +[ ! -h "${tmpd}"/abc/file1 ] && echo "does not exist" && exit 1 +[ ! -h "${tmpd}"/abc/file2 ] && echo "does not exist" && exit 1 +grep '^p1$' "${tmpd}"/abc/file1 echo "OK" exit 0 diff --git a/tests-ng/template-dotpath.sh b/tests-ng/template-dotpath.sh index ed4b283..5302e1e 100755 --- a/tests-ng/template-dotpath.sh +++ b/tests-ng/template-dotpath.sh @@ -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 @@ -49,22 +52,22 @@ echo -e "$(tput setaf 6)==> RUNNING $(basename $BASH_SOURCE) <==$(tput sgr0)" dotpath="xyz" # dotdrop directory -tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` -mkdir -p ${tmps}/${dotpath} +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmps}"/${dotpath} echo "[+] dotdrop dir: ${tmps}" echo "[+] dotpath dir: ${tmps}/${dotpath}" # 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}" -echo "content" > ${tmps}/${dotpath}/abc +echo "content" > "${tmps}"/${dotpath}/abc # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -81,16 +84,16 @@ _EOF echo "[+] install" export DOTDROP_DOTPATH=${dotpath} -cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 --verbose | grep '^1 dotfile(s) installed.$' +cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 --verbose | grep '^1 dotfile(s) installed.$' [ "$?" != "0" ] && exit 1 -[ ! -e ${tmpd}/abc ] && echo "f_abc not installed" && exit 1 +[ ! -e "${tmpd}"/abc ] && echo "f_abc not installed" && exit 1 # clean -rm ${tmpd}/abc +rm "${tmpd}"/abc # create the config file -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -108,10 +111,10 @@ profiles: _EOF echo "[+] install" -cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 --verbose | grep '^1 dotfile(s) installed.$' +cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 --verbose | grep '^1 dotfile(s) installed.$' [ "$?" != "0" ] && exit 1 -[ ! -e ${tmpd}/abc ] && echo "f_abc not installed" && exit 1 +[ ! -e "${tmpd}"/abc ] && echo "f_abc not installed" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/template-link-value.sh b/tests-ng/template-link-value.sh index 63e5a96..1c3e400 100755 --- a/tests-ng/template-link-value.sh +++ b/tests-ng/template-link-value.sh @@ -28,30 +28,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 +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmps}"/dotfiles echo "dotfiles source (dotpath): ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" clear_on_exit "${tmps}" @@ -60,7 +63,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -115,38 +118,38 @@ _EOF #cat ${cfg} # create the dotfile -echo "filea" > ${tmps}/dotfiles/a -echo "fileb" > ${tmps}/dotfiles/b -echo "filec" > ${tmps}/dotfiles/c -echo "filed" > ${tmps}/dotfiles/d -mkdir -p ${tmps}/dotfiles/e/{1,2,3} -echo filee > ${tmps}/dotfiles/e/1/file -echo filee > ${tmps}/dotfiles/e/2/file -echo filee > ${tmps}/dotfiles/e/3/file -mkdir -p ${tmps}/dotfiles/f/{1,2,3} -echo filee > ${tmps}/dotfiles/f/1/file -echo filee > ${tmps}/dotfiles/f/2/file -echo filee > ${tmps}/dotfiles/f/3/file +echo "filea" > "${tmps}"/dotfiles/a +echo "fileb" > "${tmps}"/dotfiles/b +echo "filec" > "${tmps}"/dotfiles/c +echo "filed" > "${tmps}"/dotfiles/d +mkdir -p "${tmps}"/dotfiles/e/{1,2,3} +echo filee > "${tmps}"/dotfiles/e/1/file +echo filee > "${tmps}"/dotfiles/e/2/file +echo filee > "${tmps}"/dotfiles/e/3/file +mkdir -p "${tmps}"/dotfiles/f/{1,2,3} +echo filee > "${tmps}"/dotfiles/f/1/file +echo filee > "${tmps}"/dotfiles/f/2/file +echo filee > "${tmps}"/dotfiles/f/3/file # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V # checks -[ ! -e ${tmpd}/a ] && echo "[ERROR] dotfile a not linked" && exit 1 -[ ! -h ${tmpd}/b ] && echo "[ERROR] dotfile b linked" && exit 1 -[ ! -e ${tmpd}/c ] && echo "[ERROR] dotfile c not linked" && exit 1 -[ ! -h ${tmpd}/d ] && echo "[ERROR] dotfile d linked" && exit 1 +[ ! -e "${tmpd}"/a ] && echo "[ERROR] dotfile a not linked" && exit 1 +[ ! -h "${tmpd}"/b ] && echo "[ERROR] dotfile b linked" && exit 1 +[ ! -e "${tmpd}"/c ] && echo "[ERROR] dotfile c not linked" && exit 1 +[ ! -h "${tmpd}"/d ] && echo "[ERROR] dotfile d linked" && exit 1 # link_children -[ ! -d ${tmpd}/e ] && echo "[ERROR] dir e does not exist" && exit 1 -[ ! -h ${tmpd}/e/1 ] && echo "[ERROR] children e/1 not linked" && exit 1 -[ ! -h ${tmpd}/e/2 ] && echo "[ERROR] children e/2 not linked" && exit 1 -[ ! -h ${tmpd}/e/3 ] && echo "[ERROR] children e/3 not linked" && exit 1 +[ ! -d "${tmpd}"/e ] && echo "[ERROR] dir e does not exist" && exit 1 +[ ! -h "${tmpd}"/e/1 ] && echo "[ERROR] children e/1 not linked" && exit 1 +[ ! -h "${tmpd}"/e/2 ] && echo "[ERROR] children e/2 not linked" && exit 1 +[ ! -h "${tmpd}"/e/3 ] && echo "[ERROR] children e/3 not linked" && exit 1 -[ ! -d ${tmpd}/f ] && echo "[ERROR] dir f does not exist" && exit 1 -[ ! -h ${tmpd}/f/1 ] && echo "[ERROR] children f/1 not linked" && exit 1 -[ ! -h ${tmpd}/f/2 ] && echo "[ERROR] children f/2 not linked" && exit 1 -[ ! -h ${tmpd}/f/3 ] && echo "[ERROR] children f/3 not linked" && exit 1 +[ ! -d "${tmpd}"/f ] && echo "[ERROR] dir f does not exist" && exit 1 +[ ! -h "${tmpd}"/f/1 ] && echo "[ERROR] children f/1 not linked" && exit 1 +[ ! -h "${tmpd}"/f/2 ] && echo "[ERROR] children f/2 not linked" && exit 1 +[ ! -h "${tmpd}"/f/3 ] && echo "[ERROR] children f/3 not linked" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/toml.sh b/tests-ng/toml.sh index 4354cfb..8bc1d33 100755 --- a/tests-ng/toml.sh +++ b/tests-ng/toml.sh @@ -28,28 +28,31 @@ 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 -tmp=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmp=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) tmpf="${tmp}/dotfiles" -mkdir -p ${tmpf} +mkdir -p "${tmpf}" echo "dotfiles source (dotpath): ${tmpf}" # create the config file @@ -57,14 +60,14 @@ cfg="${tmp}/config.toml" echo "config file: ${cfg}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" clear_on_exit "${tmp}" clear_on_exit "${tmpd}" ## RELATIVE -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF [config] backup = true create = true @@ -81,23 +84,23 @@ _EOF #cat ${cfg} # create the dotfile -echo "{{@@ profile @@}}" > ${tmpf}/abc -echo "{{@@ profile @@}}" > ${tmpd}/def +echo "{{@@ profile @@}}" > "${tmpf}"/abc +echo "{{@@ profile @@}}" > "${tmpd}"/def # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -b -V -[ ! -e ${tmpd}/abc ] && echo "[ERROR] dotfile not installed" && exit 1 +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V +[ ! -e "${tmpd}"/abc ] && echo "[ERROR] dotfile not installed" && exit 1 # import -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -b -V ${tmpd}/def -[ ! -e ${tmpf}${tmpd}/def ] && echo "[ERROR] dotfile not imported" && exit 1 +cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 -b -V "${tmpd}"/def +[ ! -e "${tmpf}""${tmpd}"/def ] && echo "[ERROR] dotfile not imported" && exit 1 # checks -cnt=$(cd ${ddpath} | ${bin} files -G -c ${cfg} -p p1 -V | grep '^f_' | wc -l) +cnt=$(cd "${ddpath}" | ${bin} files -G -c "${cfg}" -p p1 -V | grep '^f_' | wc -l) [ "${cnt}" != "2" ] && echo "[ERROR]" && exit 1 ## CLEANING -rm -rf ${tmp} ${tmpd} +rm -rf "${tmp}" "${tmpd}" echo "OK" exit 0 diff --git a/tests-ng/transformations-template.sh b/tests-ng/transformations-template.sh index 04f9a78..28c4583 100755 --- a/tests-ng/transformations-template.sh +++ b/tests-ng/transformations-template.sh @@ -28,30 +28,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 +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmps}"/dotfiles echo "dotfiles source (dotpath): ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" clear_on_exit "${tmps}" @@ -60,7 +63,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF trans_read: r_echo_abs_src: echo "\$(cat {0}); {{@@ _dotfile_abs_src @@}}" > {1} r_echo_var: echo "\$(cat {0}); {{@@ r_var @@}}" > {1} @@ -104,48 +107,48 @@ _EOF #cat ${cfg} # create the dotfiles -echo 'abc' > ${tmps}/dotfiles/abc -echo 'marker' > ${tmps}/dotfiles/def -echo 'ghi' > ${tmps}/dotfiles/ghi -echo '{{@@ profile @@}}' | rev > ${tmps}/dotfiles/rev +echo 'abc' > "${tmps}"/dotfiles/abc +echo 'marker' > "${tmps}"/dotfiles/def +echo 'ghi' > "${tmps}"/dotfiles/ghi +echo '{{@@ profile @@}}' | rev > "${tmps}"/dotfiles/rev ########################### # test install and compare ########################### # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V # check dotfile -[ ! -e ${tmpd}/def ] && exit 1 -[ ! -e ${tmpd}/abc ] && exit 1 -[ ! -e ${tmpd}/ghi ] && exit 1 -[ ! -e ${tmpd}/rev ] && exit 1 -grep marker ${tmpd}/def -cat ${tmpd}/abc -grep "^abc; ${tmps}/dotfiles/abc$" ${tmpd}/abc -cat ${tmpd}/ghi -grep "^ghi; readvar$" ${tmpd}/ghi -cat ${tmpd}/rev -grep "^p1$" ${tmpd}/rev +[ ! -e "${tmpd}"/def ] && exit 1 +[ ! -e "${tmpd}"/abc ] && exit 1 +[ ! -e "${tmpd}"/ghi ] && exit 1 +[ ! -e "${tmpd}"/rev ] && exit 1 +grep marker "${tmpd}"/def +cat "${tmpd}"/abc +grep "^abc; ${tmps}/dotfiles/abc$" "${tmpd}"/abc +cat "${tmpd}"/ghi +grep "^ghi; readvar$" "${tmpd}"/ghi +cat "${tmpd}"/rev +grep "^p1$" "${tmpd}"/rev ########################### # test update ########################### # update single file -cd ${ddpath} | ${bin} update -f -k -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} update -f -k -c "${cfg}" -p p1 -b -V # checks -[ ! -e ${tmps}/dotfiles/def ] && exit 1 -[ ! -e ${tmps}/dotfiles/abc ] && exit 1 -[ ! -e ${tmps}/dotfiles/ghi ] && exit 1 -[ ! -e ${tmps}/dotfiles/rev ] && exit 1 -grep marker ${tmps}/dotfiles/def -cat ${tmps}/dotfiles/abc -grep "^abc; ${tmps}/dotfiles/abc; f_abc$" ${tmps}/dotfiles/abc -cat ${tmps}/dotfiles/ghi -grep "^ghi; readvar; writevar$" ${tmps}/dotfiles/ghi +[ ! -e "${tmps}"/dotfiles/def ] && exit 1 +[ ! -e "${tmps}"/dotfiles/abc ] && exit 1 +[ ! -e "${tmps}"/dotfiles/ghi ] && exit 1 +[ ! -e "${tmps}"/dotfiles/rev ] && exit 1 +grep marker "${tmps}"/dotfiles/def +cat "${tmps}"/dotfiles/abc +grep "^abc; ${tmps}/dotfiles/abc; f_abc$" "${tmps}"/dotfiles/abc +cat "${tmps}"/dotfiles/ghi +grep "^ghi; readvar; writevar$" "${tmps}"/dotfiles/ghi echo "OK" exit 0 diff --git a/tests-ng/transformations-with-args.sh b/tests-ng/transformations-with-args.sh index 20bda59..4834561 100755 --- a/tests-ng/transformations-with-args.sh +++ b/tests-ng/transformations-with-args.sh @@ -28,30 +28,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 +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmps}"/dotfiles echo "dotfiles source (dotpath): ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" clear_on_exit "${tmps}" @@ -60,7 +63,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF trans_read: r_echo_abs_src: echo "\$(cat {0}); {{@@ _dotfile_abs_src @@}}; {2}" > {1} r_echo_var: echo "\$(cat {0}); {{@@ r_var @@}}; {2}" > {1} @@ -98,43 +101,43 @@ _EOF #cat ${cfg} # create the dotfiles -echo 'abc' > ${tmps}/dotfiles/abc -echo 'marker' > ${tmps}/dotfiles/def -echo 'ghi' > ${tmps}/dotfiles/ghi +echo 'abc' > "${tmps}"/dotfiles/abc +echo 'marker' > "${tmps}"/dotfiles/def +echo 'ghi' > "${tmps}"/dotfiles/ghi ########################### # test install and compare ########################### # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V # check dotfile -[ ! -e ${tmpd}/def ] && exit 1 -[ ! -e ${tmpd}/abc ] && exit 1 -[ ! -e ${tmpd}/ghi ] && exit 1 -grep marker ${tmpd}/def -cat ${tmpd}/abc -grep "^abc; ${tmps}/dotfiles/abc; arg1$" ${tmpd}/abc -cat ${tmpd}/ghi -grep "^ghi; readvar; p1$" ${tmpd}/ghi +[ ! -e "${tmpd}"/def ] && exit 1 +[ ! -e "${tmpd}"/abc ] && exit 1 +[ ! -e "${tmpd}"/ghi ] && exit 1 +grep marker "${tmpd}"/def +cat "${tmpd}"/abc +grep "^abc; ${tmps}/dotfiles/abc; arg1$" "${tmpd}"/abc +cat "${tmpd}"/ghi +grep "^ghi; readvar; p1$" "${tmpd}"/ghi ########################### # test update ########################### # update single file -cd ${ddpath} | ${bin} update -f -k -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} update -f -k -c "${cfg}" -p p1 -b -V # checks -[ ! -e ${tmps}/dotfiles/def ] && exit 1 -[ ! -e ${tmps}/dotfiles/abc ] && exit 1 -[ ! -e ${tmps}/dotfiles/ghi ] && exit 1 -grep marker ${tmps}/dotfiles/def -cat ${tmps}/dotfiles/abc -grep "^abc; ${tmps}/dotfiles/abc; arg1; f_abc; arg2$" ${tmps}/dotfiles/abc -cat ${tmps}/dotfiles/ghi -grep "^ghi; readvar; p1; writevar; f_ghi$" ${tmps}/dotfiles/ghi +[ ! -e "${tmps}"/dotfiles/def ] && exit 1 +[ ! -e "${tmps}"/dotfiles/abc ] && exit 1 +[ ! -e "${tmps}"/dotfiles/ghi ] && exit 1 +grep marker "${tmps}"/dotfiles/def +cat "${tmps}"/dotfiles/abc +grep "^abc; ${tmps}/dotfiles/abc; arg1; f_abc; arg2$" "${tmps}"/dotfiles/abc +cat "${tmps}"/dotfiles/ghi +grep "^ghi; readvar; p1; writevar; f_ghi$" "${tmps}"/dotfiles/ghi echo "OK" exit 0 diff --git a/tests-ng/transformations.sh b/tests-ng/transformations.sh index 80f0d5e..4fb1371 100755 --- a/tests-ng/transformations.sh +++ b/tests-ng/transformations.sh @@ -30,30 +30,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 +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmps}"/dotfiles echo "dotfiles source (dotpath): ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" clear_on_exit "${tmps}" @@ -67,7 +70,7 @@ token="test-base64" tokend="compressed archive" touched="touched" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF trans_read: base64: cat {0} | base64 -d > {1} uncompress: mkdir -p {1} && tar -xf {0} -C {1} @@ -103,30 +106,30 @@ _EOF #cat ${cfg} # create the base64 dotfile -tmpf=`mktemp --suffix='-dotdrop-tests' || mktemp -d` -echo ${token} > ${tmpf} -cat ${tmpf} | base64 > ${tmps}/dotfiles/abc -rm -f ${tmpf} +tmpf=$(mktemp --suffix='-dotdrop-tests' || mktemp -d) +echo ${token} > "${tmpf}" +cat "${tmpf}" | base64 > "${tmps}"/dotfiles/abc +rm -f "${tmpf}" # create the canary dotfile -echo 'marker' > ${tmps}/dotfiles/def +echo 'marker' > "${tmps}"/dotfiles/def # create the compressed dotfile -tmpx=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpx=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${tmpx}" -mkdir -p ${tmpx}/{a,b,c} -mkdir -p ${tmpx}/a/{dir1,dir2} +mkdir -p "${tmpx}"/{a,b,c} +mkdir -p "${tmpx}"/a/{dir1,dir2} # ambiguous redirect ?? #echo ${tokend} > ${tmpd}/{a,b,c}/somefile -echo ${tokend} > ${tmpx}/a/somefile -echo ${tokend} > ${tmpx}/b/somefile -echo ${tokend} > ${tmpx}/c/somefile -echo ${tokend} > ${tmpx}/a/dir1/otherfile +echo "${tokend}" > "${tmpx}"/a/somefile +echo "${tokend}" > "${tmpx}"/b/somefile +echo "${tokend}" > "${tmpx}"/c/somefile +echo "${tokend}" > "${tmpx}"/a/dir1/otherfile # create a fake file to ensure dir is created -echo ${tokend} > ${tmpx}/a/dir2/token -tar -cf ${tmps}/dotfiles/ghi -C ${tmpx} . -rm -rf ${tmpx} -tar -tf ${tmps}/dotfiles/ghi +echo "${tokend}" > "${tmpx}"/a/dir2/token +tar -cf "${tmps}"/dotfiles/ghi -C "${tmpx}" . +rm -rf "${tmpx}" +tar -tf "${tmps}"/dotfiles/ghi ########################### # test install and compare @@ -134,40 +137,40 @@ tar -tf ${tmps}/dotfiles/ghi echo "[+] run install" # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V # check canary dotfile -[ ! -e ${tmpd}/def ] && echo "def does not exist" && exit 1 +[ ! -e "${tmpd}"/def ] && echo "def does not exist" && exit 1 # check base64 dotfile -[ ! -e ${tmpd}/abc ] && echo "abc does not exist" && exit 1 -content=`cat ${tmpd}/abc` +[ ! -e "${tmpd}"/abc ] && echo "abc does not exist" && exit 1 +content=$(cat "${tmpd}"/abc) [ "${content}" != "${token}" ] && echo "bad content for abc" && exit 1 # check directory dotfile -[ ! -e ${tmpd}/ghi/a/dir1/otherfile ] && echo "otherfile does not exist" && exit 1 -content=`cat ${tmpd}/ghi/a/somefile` +[ ! -e "${tmpd}"/ghi/a/dir1/otherfile ] && echo "otherfile does not exist" && exit 1 +content=$(cat "${tmpd}"/ghi/a/somefile) [ "${content}" != "${tokend}" ] && echo "bad content for somefile" && exit 1 -content=`cat ${tmpd}/ghi/a/dir1/otherfile` +content=$(cat "${tmpd}"/ghi/a/dir1/otherfile) [ "${content}" != "${tokend}" ] && echo "bad content for otherfile" && exit 1 # compare set +e -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 -b -V [ "$?" != "0" ] && echo "compare failed (0)" && exit 1 set -e # change base64 deployed file -echo ${touched} > ${tmpd}/abc +echo ${touched} > "${tmpd}"/abc set +e -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 -b -V [ "$?" != "1" ] && echo "compare failed (1)" && exit 1 set -e # change uncompressed deployed dotfile -echo ${touched} > ${tmpd}/ghi/a/somefile +echo ${touched} > "${tmpd}"/ghi/a/somefile set +e -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 -b -V [ "$?" != "1" ] && echo "compare failed (2)" && exit 1 set -e @@ -176,46 +179,46 @@ set -e ########################### # update single file -echo 'update' > ${tmpd}/def +echo 'update' > "${tmpd}"/def set +e -cd ${ddpath} | ${bin} update -f -k -c ${cfg} -p p1 -b -V f_def +cd "${ddpath}" | ${bin} update -f -k -c "${cfg}" -p p1 -b -V f_def [ "$?" != "0" ] && echo "update failed (1)" && exit 1 set -e -[ ! -e ${tmpd}/def ] && echo 'dotfile in FS removed' && exit 1 -[ ! -e ${tmps}/dotfiles/def ] && echo 'dotfile in dotpath removed' && exit 1 +[ ! -e "${tmpd}"/def ] && echo 'dotfile in FS removed' && exit 1 +[ ! -e "${tmps}"/dotfiles/def ] && echo 'dotfile in dotpath removed' && exit 1 # update single file set +e -cd ${ddpath} | ${bin} update -f -k -c ${cfg} -p p1 -b -V f_abc +cd "${ddpath}" | ${bin} update -f -k -c "${cfg}" -p p1 -b -V f_abc [ "$?" != "0" ] && echo "update failed (2)" && exit 1 set -e # test updated file -[ ! -e ${tmps}/dotfiles/abc ] && echo "abc does not exist" && exit 1 -content=`cat ${tmps}/dotfiles/abc` -bcontent=`echo ${touched} | base64` +[ ! -e "${tmps}"/dotfiles/abc ] && echo "abc does not exist" && exit 1 +content=$(cat "${tmps}"/dotfiles/abc) +bcontent=$(echo ${touched} | base64) [ "${content}" != "${bcontent}" ] && echo "bad content for abc" && exit 1 # update directory -echo ${touched} > ${tmpd}/ghi/b/newfile -rm -r ${tmpd}/ghi/c -cd ${ddpath} | ${bin} update -f -k -c ${cfg} -p p1 -b -V d_ghi +echo ${touched} > "${tmpd}"/ghi/b/newfile +rm -r "${tmpd}"/ghi/c +cd "${ddpath}" | ${bin} update -f -k -c "${cfg}" -p p1 -b -V d_ghi [ "$?" != "0" ] && echo "update failed" && exit 1 # test updated directory set +e -tar -tf ${tmps}/dotfiles/ghi | grep './b/newfile' || (echo "newfile not found in tar" && exit 1) -tar -tf ${tmps}/dotfiles/ghi | grep './a/dir1/otherfile' || (echo "otherfile not found in tar" && exit 1) +tar -tf "${tmps}"/dotfiles/ghi | grep './b/newfile' || (echo "newfile not found in tar" && exit 1) +tar -tf "${tmps}"/dotfiles/ghi | grep './a/dir1/otherfile' || (echo "otherfile not found in tar" && exit 1) set -e -tmpy=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpy=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${tmpy}" -tar -xf ${tmps}/dotfiles/ghi -C ${tmpy} -content=`cat ${tmpy}/a/somefile` +tar -xf "${tmps}"/dotfiles/ghi -C "${tmpy}" +content=$(cat "${tmpy}"/a/somefile) [ "${content}" != "${touched}" ] && echo "bad content" && exit 1 # check canary dotfile -[ ! -e ${tmps}/dotfiles/def ] && echo "def not found" && exit 1 +[ ! -e "${tmps}"/dotfiles/def ] && echo "def not found" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/update-ignore-missing.sh b/tests-ng/update-ignore-missing.sh index df1fbe9..a3432d0 100755 --- a/tests-ng/update-ignore-missing.sh +++ b/tests-ng/update-ignore-missing.sh @@ -23,19 +23,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 @@ -49,23 +52,23 @@ grep_or_fail() } # dotdrop directory -tmps=`mktemp -d --suffix='-dotdrop-tests-source' || mktemp -d` +tmps=$(mktemp -d --suffix='-dotdrop-tests-source' || mktemp -d) dt="${tmps}/dotfiles" -mkdir -p ${dt}/folder -touch ${dt}/folder/a +mkdir -p "${dt}"/folder +touch "${dt}"/folder/a # fs dotfiles -tmpd=`mktemp -d --suffix='-dotdrop-tests-dest' || mktemp -d` -cp -r ${dt}/folder ${tmpd}/ -touch ${tmpd}/folder/b -mkdir ${tmpd}/folder/c +tmpd=$(mktemp -d --suffix='-dotdrop-tests-dest' || mktemp -d) +cp -r "${dt}"/folder "${tmpd}"/ +touch "${tmpd}"/folder/b +mkdir "${tmpd}"/folder/c clear_on_exit "${tmps}" clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: false create: true @@ -89,14 +92,14 @@ _EOF # file b / folder c SHOULD be copied echo "[+] test with no ignore-missing setting" -cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=p1 --key thedotfile +cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=p1 --key thedotfile -[ ! -e ${dt}/folder/b ] && echo "should have been updated" && exit 1 -[ ! -e ${dt}/folder/c ] && echo "should have been updated" && exit 1 +[ ! -e "${dt}"/folder/b ] && echo "should have been updated" && exit 1 +[ ! -e "${dt}"/folder/c ] && echo "should have been updated" && exit 1 # Reset -rm ${dt}/folder/b -rmdir ${dt}/folder/c +rm "${dt}"/folder/b +rmdir "${dt}"/folder/c # # Test with command-line flag @@ -104,16 +107,16 @@ rmdir ${dt}/folder/c # file b / folder c should NOT be copied echo "[+] test with command-line flag" -cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=p1 --key thedotfile --ignore-missing +cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=p1 --key thedotfile --ignore-missing -[ -e ${dt}/folder/b ] && echo "should not have been updated" && exit 1 -[ -e ${dt}/folder/c ] && echo "should not have been updated" && exit 1 +[ -e "${dt}"/folder/b ] && echo "should not have been updated" && exit 1 +[ -e "${dt}"/folder/c ] && echo "should not have been updated" && exit 1 # # Test with global option # -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: false create: true @@ -131,16 +134,16 @@ _EOF # file b / folder c should NOT be copied echo "[+] test global option" -cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=p1 --key thedotfile +cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=p1 --key thedotfile -[ -e ${dt}/folder/b ] && echo "should not have been updated" && exit 1 -[ -e ${dt}/folder/c ] && echo "should not have been updated" && exit 1 +[ -e "${dt}"/folder/b ] && echo "should not have been updated" && exit 1 +[ -e "${dt}"/folder/c ] && echo "should not have been updated" && exit 1 # # Test with dotfile option # -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: false create: true @@ -157,10 +160,10 @@ profiles: _EOF # file b / folder c should NOT be copied echo "[+] test dotfile option" -cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=p1 --key thedotfile +cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=p1 --key thedotfile -[ -e ${dt}/folder/b ] && echo "should not have been updated" && exit 1 -[ -e ${dt}/folder/c ] && echo "should not have been updated" && exit 1 +[ -e "${dt}"/folder/b ] && echo "should not have been updated" && exit 1 +[ -e "${dt}"/folder/c ] && echo "should not have been updated" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/update-ignore-relative.sh b/tests-ng/update-ignore-relative.sh index 93db333..4dfaf86 100755 --- a/tests-ng/update-ignore-relative.sh +++ b/tests-ng/update-ignore-relative.sh @@ -28,43 +28,46 @@ 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 ################################################################ # dotdrop directory -tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) dt="${tmps}/dotfiles" -mkdir -p ${dt} -mkdir -p ${dt}/a/{b,c} -echo 'a' > ${dt}/a/b/abfile -echo 'a' > ${dt}/a/c/acfile +mkdir -p "${dt}" +mkdir -p "${dt}"/a/{b,c} +echo 'a' > "${dt}"/a/b/abfile +echo 'a' > "${dt}"/a/c/acfile # fs dotfiles -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" -cp -r ${dt}/a ${tmpd}/ +cp -r "${dt}"/a "${tmpd}"/ # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: false create: true @@ -88,22 +91,22 @@ _EOF # edit/add files echo "[+] edit/add files" -touch ${tmpd}/a/newfile -echo 'b' > ${tmpd}/a/c/acfile -mkdir -p ${tmpd}/a/newdir/b -touch ${tmpd}/a/newdir/b/c +touch "${tmpd}"/a/newfile +echo 'b' > "${tmpd}"/a/c/acfile +mkdir -p "${tmpd}"/a/newdir/b +touch "${tmpd}"/a/newdir/b/c #tree ${tmpd}/a # update echo "[+] update" -cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=p1 --key f_abc +cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=p1 --key f_abc #tree ${dt} # check files haven't been updated -grep 'b' ${dt}/a/c/acfile >/dev/null || (echo "b not found" && exit 1) -[ -e ${dt}/a/newfile ] && echo "new file does not exist" && exit 1 +grep 'b' "${dt}"/a/c/acfile >/dev/null || (echo "b not found" && exit 1) +[ -e "${dt}"/a/newfile ] && echo "new file does not exist" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/update-ignore.sh b/tests-ng/update-ignore.sh index 167c94b..bf180a5 100755 --- a/tests-ng/update-ignore.sh +++ b/tests-ng/update-ignore.sh @@ -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,24 +57,24 @@ grep_or_fail() } # dotdrop directory -tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) dt="${tmps}/dotfiles" -mkdir -p ${dt} -mkdir -p ${dt}/a/{b,c} -echo 'a' > ${dt}/a/b/abfile -echo 'a' > ${dt}/a/c/acfile +mkdir -p "${dt}" +mkdir -p "${dt}"/a/{b,c} +echo 'a' > "${dt}"/a/b/abfile +echo 'a' > "${dt}"/a/c/acfile # fs dotfiles -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${tmps}" clear_on_exit "${tmpd}" -cp -r ${dt}/a ${tmpd}/ +cp -r "${dt}"/a "${tmpd}"/ # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: false create: true @@ -95,18 +98,18 @@ _EOF # edit/add files echo "[+] edit/add files" -touch ${tmpd}/a/newfile -echo 'b' > ${tmpd}/a/c/acfile -mkdir -p ${tmpd}/a/newdir/b -touch ${tmpd}/a/newdir/b/c +touch "${tmpd}"/a/newfile +echo 'b' > "${tmpd}"/a/c/acfile +mkdir -p "${tmpd}"/a/newdir/b +touch "${tmpd}"/a/newdir/b/c # update echo "[+] update" -cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=p1 --key f_abc +cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=p1 --key f_abc # check files haven't been updated grep_or_fail 'b' "${dt}/a/c/acfile" -[ -e ${dt}/a/newfile ] && echo "should not have been updated" && exit 1 +[ -e "${dt}"/a/newfile ] && echo "should not have been updated" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/update-negative-ignore-relative.sh b/tests-ng/update-negative-ignore-relative.sh index cc67836..519bbbc 100755 --- a/tests-ng/update-negative-ignore-relative.sh +++ b/tests-ng/update-negative-ignore-relative.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # author: jtt9340 (https://github.com/jtt9340) -# +# # test ignore update negative relative pattern # returns 1 in case of error # @@ -9,41 +9,12 @@ set -e # all this crap to get current path -if [ $(uname) = Darwin ]; then - # Unfortunately, readlink works differently on macOS than it does on GNU/Linux - # (the -f option behaves differently) and the realpath command does not exist. - # Workarounds I find on the Internet suggest just using Homebrew to install coreutils - # so you can get the GNU coreutils on your Mac. But, I don't want this script to - # assume (a) users have Homebrew installed and (b) if they have Homebrew installed, that - # they then installed the GNU coreutils. - readlink() { - TARGET_FILE=$1 +rl="readlink -f" +if ! ${rl} "${0}" >/dev/null 2>&1; then + rl="realpath" - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - - # Iterate down a (possible) chain of symlinks - while [ -L "$TARGET_FILE" ]; do - TARGET_FILE=`readlink $TARGET_FILE` - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - done - - # Compute the canonicalized name by finding the physical path - # for the directory we're in and appending the target file. - PHYS_DIR=`pwd -P` - RESULT=$PHYS_DIR/$TARGET_FILE - echo $RESULT - } - rl="readlink" -else - rl="readlink -f" - if ! ${rl} "${0}" >/dev/null 2>&1; then - rl="realpath" - - if ! hash ${rl}; then - echo "\"${rl}\" not found !" && exit 1 - fi + if ! hash ${rl}; then + echo "\"${rl}\" not found !" && exit 1 fi fi cur=$(dirname "$(${rl} "${0}")") @@ -51,45 +22,48 @@ cur=$(dirname "$(${rl} "${0}")") # dotdrop path can be pass as argument ddpath="${cur}/../" [ -n "${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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" -mkdir -p ${basedir}/dotfiles/a/{b,c} -echo 'a' > ${basedir}/dotfiles/a/b/abfile1 -echo 'a' > ${basedir}/dotfiles/a/b/abfile2 -echo 'a' > ${basedir}/dotfiles/a/b/abfile3 -echo 'a' > ${basedir}/dotfiles/a/c/acfile +mkdir -p "${basedir}"/dotfiles/a/{b,c} +echo 'a' > "${basedir}"/dotfiles/a/b/abfile1 +echo 'a' > "${basedir}"/dotfiles/a/b/abfile2 +echo 'a' > "${basedir}"/dotfiles/a/b/abfile3 +echo 'a' > "${basedir}"/dotfiles/a/c/acfile # the dotfile to be updated -tmpd=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" -cp -r ${basedir}/dotfiles/a ${tmpd}/ +cp -r "${basedir}"/dotfiles/a "${tmpd}"/ # create the config file cfg="${basedir}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: false create: true @@ -111,26 +85,26 @@ _EOF # edit/add files echo "[+] edit/add files" -mkdir -p ${tmpd}/a/newdir/b -echo 'b' > ${tmpd}/a/b/abfile1 -echo 'b' > ${tmpd}/a/b/abfile2 -echo 'b' > ${tmpd}/a/b/abfile3 -echo 'b' > ${tmpd}/a/b/abfile4 -touch ${tmpd}/a/newdir/b/{c,d} +mkdir -p "${tmpd}"/a/newdir/b +echo 'b' > "${tmpd}"/a/b/abfile1 +echo 'b' > "${tmpd}"/a/b/abfile2 +echo 'b' > "${tmpd}"/a/b/abfile3 +echo 'b' > "${tmpd}"/a/b/abfile4 +touch "${tmpd}"/a/newdir/b/{c,d} # update echo "[+] update" -cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=p1 --key f_abc +cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=p1 --key f_abc # check files haven't been updated set +e -grep a ${basedir}/dotfiles/a/b/abfile1 >/dev/null 2>&1 || (echo "abfile1 should not have been updated" && exit 1) -grep a ${basedir}/dotfiles/a/b/abfile2 >/dev/null 2>&1 || (echo "abfile2 should not have been updated" && exit 1) -grep b ${basedir}/dotfiles/a/b/abfile3 >/dev/null 2>&1 || (echo "abfile3 should have been updated" && exit 1) +grep a "${basedir}"/dotfiles/a/b/abfile1 >/dev/null 2>&1 || (echo "abfile1 should not have been updated" && exit 1) +grep a "${basedir}"/dotfiles/a/b/abfile2 >/dev/null 2>&1 || (echo "abfile2 should not have been updated" && exit 1) +grep b "${basedir}"/dotfiles/a/b/abfile3 >/dev/null 2>&1 || (echo "abfile3 should have been updated" && exit 1) set -e -[ -e ${basedir}/dotfiles/a/b/abfile4 ] && echo "abfile4 should not have been updated" && exit 1 -[ -e ${basedir}/dotfiles/a/newdir/b/c ] && echo "newdir/b/c should not have been updated" && exit 1 -[ ! -e ${basedir}/dotfiles/a/newdir/b/d ] && echo "newdir/b/d should have been updated" && exit 1 +[ -e "${basedir}"/dotfiles/a/b/abfile4 ] && echo "abfile4 should not have been updated" && exit 1 +[ -e "${basedir}"/dotfiles/a/newdir/b/c ] && echo "newdir/b/c should not have been updated" && exit 1 +[ ! -e "${basedir}"/dotfiles/a/newdir/b/d ] && echo "newdir/b/d should have been updated" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/update-negative-ignore.sh b/tests-ng/update-negative-ignore.sh index efb18f4..c10a3ab 100755 --- a/tests-ng/update-negative-ignore.sh +++ b/tests-ng/update-negative-ignore.sh @@ -9,41 +9,12 @@ set -e # all this crap to get current path -if [ $(uname) = Darwin ]; then - # Unfortunately, readlink works differently on macOS than it does on GNU/Linux - # (the -f option behaves differently) and the realpath command does not exist. - # Workarounds I find on the Internet suggest just using Homebrew to install coreutils - # so you can get the GNU coreutils on your Mac. But, I don't want this script to - # assume (a) users have Homebrew installed and (b) if they have Homebrew installed, that - # they then installed the GNU coreutils. - readlink() { - TARGET_FILE=$1 +rl="readlink -f" +if ! ${rl} "${0}" >/dev/null 2>&1; then + rl="realpath" - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - - # Iterate down a (possible) chain of symlinks - while [ -L "$TARGET_FILE" ]; do - TARGET_FILE=`readlink $TARGET_FILE` - cd `dirname $TARGET_FILE` - TARGET_FILE=`basename $TARGET_FILE` - done - - # Compute the canonicalized name by finding the physical path - # for the directory we're in and appending the target file. - PHYS_DIR=`pwd -P` - RESULT=$PHYS_DIR/$TARGET_FILE - echo $RESULT - } - rl="readlink" -else - rl="readlink -f" - if ! ${rl} "${0}" >/dev/null 2>&1; then - rl="realpath" - - if ! hash ${rl}; then - echo "\"${rl}\" not found !" && exit 1 - fi + if ! hash ${rl}; then + echo "\"${rl}\" not found !" && exit 1 fi fi cur=$(dirname "$(${rl} "${0}")") @@ -56,19 +27,22 @@ cur=$(dirname "$(${rl} "${0}")") # dotdrop path can be pass as argument ddpath="${cur}/../" [ -n "${1}" ] && ddpath="${1}" -[ ! -d ${ddpath} ] && exho "ddpath \"${ddpath}\" is not a directory" && exit 1 +[ ! -d "${ddpath}" ] && exho "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 @@ -82,26 +56,26 @@ grep_or_fail() } # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" -mkdir -p ${basedir}/dotfiles/a/{b,c} -echo 'a' > ${basedir}/dotfiles/a/b/abfile1 -echo 'a' > ${basedir}/dotfiles/a/b/abfile2 -echo 'a' > ${basedir}/dotfiles/a/b/abfile3 -echo 'a' > ${basedir}/dotfiles/a/c/acfile +mkdir -p "${basedir}"/dotfiles/a/{b,c} +echo 'a' > "${basedir}"/dotfiles/a/b/abfile1 +echo 'a' > "${basedir}"/dotfiles/a/b/abfile2 +echo 'a' > "${basedir}"/dotfiles/a/b/abfile3 +echo 'a' > "${basedir}"/dotfiles/a/c/acfile # the dotfile to be updated -tmpd=`mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' 2>/dev/null || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" -cp -r ${basedir}/dotfiles/a ${tmpd}/ +cp -r "${basedir}"/dotfiles/a "${tmpd}"/ # create the config file cfg="${basedir}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: false create: true @@ -123,24 +97,24 @@ _EOF # edit/add files echo "[+] edit/add files" -mkdir -p ${tmpd}/a/newdir/b -echo 'b' > ${tmpd}/a/b/abfile1 -echo 'b' > ${tmpd}/a/b/abfile2 -echo 'b' > ${tmpd}/a/b/abfile3 -echo 'b' > ${tmpd}/a/b/abfile4 -touch ${tmpd}/a/newdir/b/{c,d} +mkdir -p "${tmpd}"/a/newdir/b +echo 'b' > "${tmpd}"/a/b/abfile1 +echo 'b' > "${tmpd}"/a/b/abfile2 +echo 'b' > "${tmpd}"/a/b/abfile3 +echo 'b' > "${tmpd}"/a/b/abfile4 +touch "${tmpd}"/a/newdir/b/{c,d} # update echo "[+] update" -cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=p1 --key f_abc +cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=p1 --key f_abc # check files haven't been updated -grep_or_fail a ${basedir}/dotfiles/a/b/abfile1 -grep_or_fail a ${basedir}/dotfiles/a/b/abfile2 -grep_or_fail b ${basedir}/dotfiles/a/b/abfile3 -[ -e ${basedir}/dotfiles/a/b/abfile4 ] && echo "abfile4 should not have been updated" && exit 1 -[ -e ${basedir}/dotfiles/a/newdir/b/c ] && echo "newdir/b/c should not have been updated" && exit 1 -[ ! -e ${basedir}/dotfiles/a/newdir/b/d ] && echo "newdir/b/d should have been updated" && exit 1 +grep_or_fail a "${basedir}"/dotfiles/a/b/abfile1 +grep_or_fail a "${basedir}"/dotfiles/a/b/abfile2 +grep_or_fail b "${basedir}"/dotfiles/a/b/abfile3 +[ -e "${basedir}"/dotfiles/a/b/abfile4 ] && echo "abfile4 should not have been updated" && exit 1 +[ -e "${basedir}"/dotfiles/a/newdir/b/c ] && echo "newdir/b/c should not have been updated" && exit 1 +[ ! -e "${basedir}"/dotfiles/a/newdir/b/d ] && echo "newdir/b/d should have been updated" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/update-profile-check.sh b/tests-ng/update-profile-check.sh index 02f1e11..8a9d859 100755 --- a/tests-ng/update-profile-check.sh +++ b/tests-ng/update-profile-check.sh @@ -23,19 +23,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 @@ -49,25 +52,25 @@ grep_or_fail() } # dotdrop directory -tmps=`mktemp -d --suffix='-dotdrop-tests-source' || mktemp -d` +tmps=$(mktemp -d --suffix='-dotdrop-tests-source' || mktemp -d) dt="${tmps}/dotfiles" -mkdir -p ${dt} +mkdir -p "${dt}" xori="profile x" -xori="profile y" -echo "${xori}" > ${dt}/file_x -echo "${yori}" > ${dt}/file_y +yori="profile y" +echo "${xori}" > "${dt}"/file_x +echo "${yori}" > "${dt}"/file_y # fs dotfiles -tmpd=`mktemp -d --suffix='-dotdrop-tests-dest' || mktemp -d` -touch ${tmpd}/file +tmpd=$(mktemp -d --suffix='-dotdrop-tests-dest' || mktemp -d) +touch "${tmpd}"/file clear_on_exit "${tmps}" clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: false create: true @@ -87,81 +90,81 @@ profiles: dotfiles: - f_file_y _EOF -cat ${cfg} +cat "${cfg}" # reset -echo "${xori}" > ${dt}/file_x -echo "${yori}" > ${dt}/file_y +echo "${xori}" > "${dt}"/file_x +echo "${yori}" > "${dt}"/file_y # test with key echo "test update x from key" n="patched content for X" -echo "${n}" > ${tmpd}/file -cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=x --key f_file_x +echo "${n}" > "${tmpd}"/file +cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=x --key f_file_x grep_or_fail "${n}" "${dt}/file_x" grep_or_fail "${yori}" "${dt}/file_y" # reset -echo "${xori}" > ${dt}/file_x -echo "${yori}" > ${dt}/file_y +echo "${xori}" > "${dt}"/file_x +echo "${yori}" > "${dt}"/file_y # test with key echo "test update y from key" n="patched content for Y" -echo "${n}" > ${tmpd}/file -cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=y --key f_file_y +echo "${n}" > "${tmpd}"/file +cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=y --key f_file_y grep_or_fail "${n}" "${dt}/file_y" grep_or_fail "${xori}" "${dt}/file_x" # reset -echo "${xori}" > ${dt}/file_x -echo "${yori}" > ${dt}/file_y +echo "${xori}" > "${dt}"/file_x +echo "${yori}" > "${dt}"/file_y # test with path echo "test update x from path" n="patched content for X" -echo "${n}" > ${tmpd}/file -cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=x "${tmpd}/file" +echo "${n}" > "${tmpd}"/file +cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=x "${tmpd}/file" grep_or_fail "${n}" "${dt}/file_x" grep_or_fail "${yori}" "${dt}/file_y" # reset -echo "${xori}" > ${dt}/file_x -echo "${yori}" > ${dt}/file_y +echo "${xori}" > "${dt}"/file_x +echo "${yori}" > "${dt}"/file_y # test with path echo "test update y from path" n="patched content for Y" -echo "${n}" > ${tmpd}/file -cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=y "${tmpd}/file" +echo "${n}" > "${tmpd}"/file +cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=y "${tmpd}/file" grep_or_fail "${n}" "${dt}/file_y" grep_or_fail "${xori}" "${dt}/file_x" ## make sure it fails when wrong dotfile # reset -echo "${xori}" > ${dt}/file_x -echo "${yori}" > ${dt}/file_y +echo "${xori}" > "${dt}"/file_x +echo "${yori}" > "${dt}"/file_y # test with key echo "test wrong key for x" n="patched content for X" -echo "${n}" > ${tmpd}/file +echo "${n}" > "${tmpd}"/file set +e -cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=x --key f_file_y +cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=x --key f_file_y set -e grep_or_fail "${xori}" "${dt}/file_x" grep_or_fail "${yori}" "${dt}/file_y" # reset -echo "${xori}" > ${dt}/file_x -echo "${yori}" > ${dt}/file_y +echo "${xori}" > "${dt}"/file_x +echo "${yori}" > "${dt}"/file_y # test with key echo "test wrong key for y" n="patched content for Y" -echo "${n}" > ${tmpd}/file +echo "${n}" > "${tmpd}"/file set +e -cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=y --key f_file_x +cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=y --key f_file_x set -e grep_or_fail "${xori}" "${dt}/file_x" grep_or_fail "${yori}" "${dt}/file_y" diff --git a/tests-ng/update-rights.sh b/tests-ng/update-rights.sh index c214982..0cee9e3 100755 --- a/tests-ng/update-rights.sh +++ b/tests-ng/update-rights.sh @@ -28,75 +28,78 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" # the dotfile directory to be imported -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) # the dotfile file to be imported -tmpf=`mktemp` +tmpf=$(mktemp) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # single file -echo 'file' > ${tmpf} +echo 'file' > "${tmpf}" -mkdir ${tmpd}/dir1 -echo 'dir1file1' > ${tmpd}/dir1/file1 -echo 'dir1file2' > ${tmpd}/dir1/file2 +mkdir "${tmpd}"/dir1 +echo 'dir1file1' > "${tmpd}"/dir1/file1 +echo 'dir1file2' > "${tmpd}"/dir1/file2 # create the config file cfg="${basedir}/config.yaml" -create_conf ${cfg} # sets token +create_conf "${cfg}" # sets token # import dir1 echo "[+] import" -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd} -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpf} +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}" +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpf}" # change file -chmod +x ${tmpf} +chmod +x "${tmpf}" # update echo "[+] updating" -cd ${ddpath} | ${bin} update -c ${cfg} -f --verbose ${tmpf} +cd "${ddpath}" | ${bin} update -c "${cfg}" -f --verbose "${tmpf}" # test change applied -[ "`stat -c '%a' ${tmpf}`" != "`stat -c '%a' ${basedir}/dotfiles/${tmpf}`" ] && exit 1 +[ "$(stat -c '%a' "${tmpf}")" != "$(stat -c '%a' "${basedir}"/dotfiles/"${tmpf}")" ] && exit 1 # change file -chmod +x ${tmpd}/dir1/file2 -echo 'test' > ${tmpd}/dir1/newfile -chmod +x ${tmpd}/dir1/newfile +chmod +x "${tmpd}"/dir1/file2 +echo 'test' > "${tmpd}"/dir1/newfile +chmod +x "${tmpd}"/dir1/newfile # update echo "[+] updating" -cd ${ddpath} | ${bin} update -c ${cfg} -f --verbose ${tmpd} +cd "${ddpath}" | ${bin} update -c "${cfg}" -f --verbose "${tmpd}" # test change applied -[ "`stat -c '%a' ${tmpd}/dir1/newfile`" != "`stat -c '%a' ${basedir}/dotfiles/${tmpd}/dir1/newfile`" ] && exit 1 -[ "`stat -c '%a' ${tmpd}/dir1/file2`" != "`stat -c '%a' ${basedir}/dotfiles/${tmpd}/dir1/file2`" ] && exit 1 +[ "$(stat -c '%a' "${tmpd}"/dir1/newfile)" != "$(stat -c '%a' "${basedir}"/dotfiles/"${tmpd}"/dir1/newfile)" ] && exit 1 +[ "$(stat -c '%a' "${tmpd}"/dir1/file2)" != "$(stat -c '%a' "${basedir}"/dotfiles/"${tmpd}"/dir1/file2)" ] && exit 1 echo "OK" exit 0 diff --git a/tests-ng/update-templates.sh b/tests-ng/update-templates.sh index aaec60e..c4c128d 100755 --- a/tests-ng/update-templates.sh +++ b/tests-ng/update-templates.sh @@ -28,33 +28,36 @@ 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 echo "dotfiles source (dotpath): ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" # the workdir -tmpw=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpw=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) export DOTDROP_WORKDIR="${tmpw}" echo "workdir: ${tmpw}" @@ -65,7 +68,7 @@ clear_on_exit "${tmpw}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -83,27 +86,27 @@ _EOF #cat ${cfg} # create the dotfile -echo "head" > ${tmps}/dotfiles/abc -echo '{%@@ if profile == "p1" @@%}' >> ${tmps}/dotfiles/abc -echo "is p1" >> ${tmps}/dotfiles/abc -echo '{%@@ else @@%}' >> ${tmps}/dotfiles/abc -echo "is not p1" >> ${tmps}/dotfiles/abc -echo '{%@@ endif @@%}' >> ${tmps}/dotfiles/abc -echo "tail" >> ${tmps}/dotfiles/abc +echo "head" > "${tmps}"/dotfiles/abc +echo '{%@@ if profile == "p1" @@%}' >> "${tmps}"/dotfiles/abc +echo "is p1" >> "${tmps}"/dotfiles/abc +echo '{%@@ else @@%}' >> "${tmps}"/dotfiles/abc +echo "is not p1" >> "${tmps}"/dotfiles/abc +echo '{%@@ endif @@%}' >> "${tmps}"/dotfiles/abc +echo "tail" >> "${tmps}"/dotfiles/abc # create the installed dotfile -echo "head" > ${tmpd}/abc -echo "is p1" >> ${tmpd}/abc -echo "tail" >> ${tmpd}/abc +echo "head" > "${tmpd}"/abc +echo "is p1" >> "${tmpd}"/abc +echo "tail" >> "${tmpd}"/abc # update #cat ${tmps}/dotfiles/abc set +e -patch=`cd ${ddpath} | ${bin} update -P -p p1 -k f_abc --cfg ${cfg} 2>&1 | grep 'try patching with' | sed 's/"//g'` +patch=$(cd "${ddpath}" | ${bin} update -P -p p1 -k f_abc --cfg "${cfg}" 2>&1 | grep 'try patching with' | sed 's/"//g') set -e -patch=`echo ${patch} | sed 's/^.*: //g'` +patch=$(echo "${patch}" | sed 's/^.*: //g') echo "patching with: ${patch}" -eval ${patch} +eval "${patch}" #cat ${tmps}/dotfiles/abc echo "OK" diff --git a/tests-ng/update-with-key.sh b/tests-ng/update-with-key.sh index 17363bc..98da335 100755 --- a/tests-ng/update-with-key.sh +++ b/tests-ng/update-with-key.sh @@ -28,78 +28,79 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" # the dotfile to be imported -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # originally imported directory -echo 'unique' > ${tmpd}/uniquefile +echo 'unique' > "${tmpd}"/uniquefile uniquefile_key="f_uniquefile" -echo 'unique2' > ${tmpd}/uniquefile2 -uniquefile2_key="f_uniquefile2" -mkdir ${tmpd}/dir1 -touch ${tmpd}/dir1/dir1f1 -mkdir ${tmpd}/dir1/dir1dir1 -dir1_key="d_dir1" +echo 'unique2' > "${tmpd}"/uniquefile2 +mkdir "${tmpd}"/dir1 +touch "${tmpd}"/dir1/dir1f1 +mkdir "${tmpd}"/dir1/dir1dir1 # create the config file cfg="${basedir}/config.yaml" -create_conf ${cfg} # sets token +create_conf "${cfg}" # sets token # import dir1 echo "[+] import" -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/dir1 -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/uniquefile -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/uniquefile2 +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/dir1 +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/uniquefile +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/uniquefile2 # make some modification echo "[+] modify" -echo 'changed' > ${tmpd}/uniquefile -echo 'changed' > ${tmpd}/uniquefile2 -echo 'new' > ${tmpd}/dir1/dir1dir1/new +echo 'changed' > "${tmpd}"/uniquefile +echo 'changed' > "${tmpd}"/uniquefile2 +echo 'new' > "${tmpd}"/dir1/dir1dir1/new # update by key echo "[+] updating single key" -cd ${ddpath} | ${bin} update -c ${cfg} -k -f --verbose ${uniquefile_key} +cd "${ddpath}" | ${bin} update -c "${cfg}" -k -f --verbose ${uniquefile_key} # ensure changes applied correctly (only to uniquefile) -diff ${tmpd}/uniquefile ${basedir}/dotfiles/${tmpd}/uniquefile # should be same +diff "${tmpd}"/uniquefile "${basedir}"/dotfiles/"${tmpd}"/uniquefile # should be same set +e -diff ${tmpd}/uniquefile2 ${basedir}/dotfiles/${tmpd}/uniquefile2 # should be different +diff "${tmpd}"/uniquefile2 "${basedir}"/dotfiles/"${tmpd}"/uniquefile2 # should be different [ "${?}" != "1" ] && exit 1 set -e # update all keys echo "[+] updating all keys" -cd ${ddpath} | ${bin} update -c ${cfg} -k -f --verbose +cd "${ddpath}" | ${bin} update -c "${cfg}" -k -f --verbose # ensure all changes applied -diff ${tmpd} ${basedir}/dotfiles/${tmpd} +diff "${tmpd}" "${basedir}"/dotfiles/"${tmpd}" echo "OK" exit 0 diff --git a/tests-ng/update.sh b/tests-ng/update.sh index 3a6a1b1..92edd59 100755 --- a/tests-ng/update.sh +++ b/tests-ng/update.sh @@ -28,89 +28,92 @@ 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 ################################################################ # dotdrop directory -basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "[+] dotdrop dir: ${basedir}" echo "[+] dotpath dir: ${basedir}/dotfiles" # the dotfile to be imported -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) clear_on_exit "${basedir}" clear_on_exit "${tmpd}" # single file -echo 'unique' > ${tmpd}/uniquefile +echo 'unique' > "${tmpd}"/uniquefile # hierarchy from https://pymotw.com/2/filecmp/ # create the hierarchy # for dir1 (originally imported directory)))) -mkdir ${tmpd}/dir1 -touch ${tmpd}/dir1/file_only_in_dir1 -mkdir -p ${tmpd}/dir1/dir_only_in_dir1 -mkdir -p ${tmpd}/dir1/common_dir -echo 'this file is the same' > ${tmpd}/dir1/common_file -echo 'in dir1' > ${tmpd}/dir1/not_the_same -echo 'This is a file in dir1' > ${tmpd}/dir1/file_in_dir1 -mkdir -p ${tmpd}/dir1/sub/sub2 -mkdir -p ${tmpd}/dir1/notindir2/notindir2 -echo 'first' > ${tmpd}/dir1/sub/sub2/different +mkdir "${tmpd}"/dir1 +touch "${tmpd}"/dir1/file_only_in_dir1 +mkdir -p "${tmpd}"/dir1/dir_only_in_dir1 +mkdir -p "${tmpd}"/dir1/common_dir +echo 'this file is the same' > "${tmpd}"/dir1/common_file +echo 'in dir1' > "${tmpd}"/dir1/not_the_same +echo 'This is a file in dir1' > "${tmpd}"/dir1/file_in_dir1 +mkdir -p "${tmpd}"/dir1/sub/sub2 +mkdir -p "${tmpd}"/dir1/notindir2/notindir2 +echo 'first' > "${tmpd}"/dir1/sub/sub2/different #tree ${tmpd}/dir1 # create the hierarchy # for dir2 (modified original for update) -mkdir ${tmpd}/dir2 -touch ${tmpd}/dir2/file_only_in_dir2 -mkdir -p ${tmpd}/dir2/dir_only_in_dir2 -mkdir -p ${tmpd}/dir2/common_dir -echo 'this file is the same' > ${tmpd}/dir2/common_file -echo 'in dir2' > ${tmpd}/dir2/not_the_same -mkdir -p ${tmpd}/dir2/file_in_dir1 -mkdir -p ${tmpd}/dir2/sub/sub2 -echo 'modified' > ${tmpd}/dir2/sub/sub2/different -mkdir -p ${tmpd}/dir2/new/new2 -mkdir -p ${tmpd}/dir2/sub1/sub2/sub3/ -touch ${tmpd}/dir2/sub1/sub2/sub3/file +mkdir "${tmpd}"/dir2 +touch "${tmpd}"/dir2/file_only_in_dir2 +mkdir -p "${tmpd}"/dir2/dir_only_in_dir2 +mkdir -p "${tmpd}"/dir2/common_dir +echo 'this file is the same' > "${tmpd}"/dir2/common_file +echo 'in dir2' > "${tmpd}"/dir2/not_the_same +mkdir -p "${tmpd}"/dir2/file_in_dir1 +mkdir -p "${tmpd}"/dir2/sub/sub2 +echo 'modified' > "${tmpd}"/dir2/sub/sub2/different +mkdir -p "${tmpd}"/dir2/new/new2 +mkdir -p "${tmpd}"/dir2/sub1/sub2/sub3/ +touch "${tmpd}"/dir2/sub1/sub2/sub3/file #tree ${tmpd}/dir2 # create the config file cfg="${basedir}/config.yaml" -create_conf ${cfg} # sets token +create_conf "${cfg}" # sets token # import dir1 echo "[+] import" -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/dir1 -cd ${ddpath} | ${bin} import -f -c ${cfg} ${tmpd}/uniquefile +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/dir1 +cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/uniquefile # let's see the dotpath #tree ${basedir}/dotfiles # change dir1 to dir2 in deployed echo "[+] change dir" -rm -rf ${tmpd}/dir1 -mv ${tmpd}/dir2 ${tmpd}/dir1 +rm -rf "${tmpd}"/dir1 +mv "${tmpd}"/dir2 "${tmpd}"/dir1 #tree ${tmpd}/dir1 # change unique file -echo 'changed' > ${tmpd}/uniquefile +echo 'changed' > "${tmpd}"/uniquefile # compare #echo "[+] comparing" @@ -118,16 +121,16 @@ echo 'changed' > ${tmpd}/uniquefile # update echo "[+] updating" -cd ${ddpath} | ${bin} update -c ${cfg} -f --verbose ${tmpd}/uniquefile ${tmpd}/dir1 +cd "${ddpath}" | ${bin} update -c "${cfg}" -f --verbose "${tmpd}"/uniquefile "${tmpd}"/dir1 # manually update -rm ${basedir}/dotfiles/${tmpd}/dir1/file_in_dir1 -mkdir -p ${basedir}/dotfiles/${tmpd}/dir1/file_in_dir1 +rm "${basedir}"/dotfiles/"${tmpd}"/dir1/file_in_dir1 +mkdir -p "${basedir}"/dotfiles/"${tmpd}"/dir1/file_in_dir1 # ensure changes applied correctly -diff ${tmpd}/dir1 ${basedir}/dotfiles/${tmpd}/dir1 -diff ${tmpd}/uniquefile ${basedir}/dotfiles/${tmpd}/uniquefile -[ ! -e ${basedir}/dotfiles/${tmpd}/dir1/sub1/sub2/sub3/file ] && echo "sub does not exist" && exit 1 +diff "${tmpd}"/dir1 "${basedir}"/dotfiles/"${tmpd}"/dir1 +diff "${tmpd}"/uniquefile "${basedir}"/dotfiles/"${tmpd}"/uniquefile +[ ! -e "${basedir}"/dotfiles/"${tmpd}"/dir1/sub1/sub2/sub3/file ] && echo "sub does not exist" && exit 1 echo "OK" exit 0 diff --git a/tests-ng/uservariables.sh b/tests-ng/uservariables.sh index 7f4e6d2..37eb0e2 100755 --- a/tests-ng/uservariables.sh +++ b/tests-ng/uservariables.sh @@ -28,29 +28,32 @@ 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}" clear_on_exit "${tmps}" @@ -59,7 +62,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -87,27 +90,27 @@ _EOF #cat ${cfg} # create the dotfile -echo "var1: {{@@ var1 @@}}" > ${tmps}/dotfiles/abc -echo "var2: {{@@ var2 @@}}" >> ${tmps}/dotfiles/abc -echo "var3: {{@@ var3 @@}}" >> ${tmps}/dotfiles/abc -echo "var4: {{@@ var4 @@}}" >> ${tmps}/dotfiles/abc +echo "var1: {{@@ var1 @@}}" > "${tmps}"/dotfiles/abc +echo "var2: {{@@ var2 @@}}" >> "${tmps}"/dotfiles/abc +echo "var3: {{@@ var3 @@}}" >> "${tmps}"/dotfiles/abc +echo "var4: {{@@ var4 @@}}" >> "${tmps}"/dotfiles/abc # install echo "step 1" -cd ${ddpath} | echo -e 'var1contentxxx\nvar2contentyyy\nvar3\nvar4\n' | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | echo -e 'var1contentxxx\nvar2contentyyy\nvar3\nvar4\n' | ${bin} install -f -c "${cfg}" -p p1 -V -cat ${tmpd}/abc +cat "${tmpd}"/abc -grep '^var1: var1contentxxx$' ${tmpd}/abc >/dev/null -grep '^var2: var2contentyyy$' ${tmpd}/abc >/dev/null -grep '^var3: dynvariables_var3$' ${tmpd}/abc >/dev/null -grep '^var4: variables_var4$' ${tmpd}/abc >/dev/null +grep '^var1: var1contentxxx$' "${tmpd}"/abc >/dev/null +grep '^var2: var2contentyyy$' "${tmpd}"/abc >/dev/null +grep '^var3: dynvariables_var3$' "${tmpd}"/abc >/dev/null +grep '^var4: variables_var4$' "${tmpd}"/abc >/dev/null [ ! -e "${tmps}/uservariables.yaml" ] && exit 1 -grep '^variables:' ${tmps}/uservariables.yaml >/dev/null -grep '^ var1: var1contentxxx$' ${tmps}/uservariables.yaml >/dev/null -grep '^ var2: var2contentyyy$' ${tmps}/uservariables.yaml >/dev/null +grep '^variables:' "${tmps}"/uservariables.yaml >/dev/null +grep '^ var1: var1contentxxx$' "${tmps}"/uservariables.yaml >/dev/null +grep '^ var2: var2contentyyy$' "${tmps}"/uservariables.yaml >/dev/null cat > "${tmps}/uservariables.yaml" << _EOF variables: @@ -116,12 +119,12 @@ variables: _EOF echo "step 2" -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V -grep '^var1: editedvar1$' ${tmpd}/abc >/dev/null -grep '^var2: editedvar2$' ${tmpd}/abc >/dev/null -grep '^var3: dynvariables_var3$' ${tmpd}/abc >/dev/null -grep '^var4: variables_var4$' ${tmpd}/abc >/dev/null +grep '^var1: editedvar1$' "${tmpd}"/abc >/dev/null +grep '^var2: editedvar2$' "${tmpd}"/abc >/dev/null +grep '^var3: dynvariables_var3$' "${tmpd}"/abc >/dev/null +grep '^var4: variables_var4$' "${tmpd}"/abc >/dev/null echo "OK" exit 0 diff --git a/tests-ng/variables-enrich.sh b/tests-ng/variables-enrich.sh index 3a45ed9..d93e12f 100755 --- a/tests-ng/variables-enrich.sh +++ b/tests-ng/variables-enrich.sh @@ -28,30 +28,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 +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}" @@ -60,7 +63,7 @@ clear_on_exit "${tmpd}" cfg="${tmps}/config.yaml" export dotdrop_test_dst="${tmpd}/def" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -77,14 +80,14 @@ _EOF #cat ${cfg} # create the dotfile -echo "os={{@@ os @@}}" > ${tmps}/dotfiles/abc -echo "release={{@@ release @@}}" >> ${tmps}/dotfiles/abc -echo "distro_id={{@@ distro_id @@}}" >> ${tmps}/dotfiles/abc -echo "distro_like={{@@ distro_like @@}}" >> ${tmps}/dotfiles/abc -echo "distro_version={{@@ distro_version @@}}" >> ${tmps}/dotfiles/abc +echo "os={{@@ os @@}}" > "${tmps}"/dotfiles/abc +echo "release={{@@ release @@}}" >> "${tmps}"/dotfiles/abc +echo "distro_id={{@@ distro_id @@}}" >> "${tmps}"/dotfiles/abc +echo "distro_like={{@@ distro_like @@}}" >> "${tmps}"/dotfiles/abc +echo "distro_version={{@@ distro_version @@}}" >> "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 --verbose +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 --verbose pybin="python3" real_os=$(${pybin} -c 'import platform; print(platform.system().lower())') @@ -94,17 +97,17 @@ real_distro_like=$(${pybin} -c 'import distro; print(distro.like().lower())') real_distro_version=$(${pybin} -c 'import distro; print(distro.version().lower())') # tests -[ ! -e ${tmpd}/abc ] && echo "abc not installed" && exit 1 +[ ! -e "${tmpd}"/abc ] && echo "abc not installed" && exit 1 cat "${tmpd}/abc" ## only test this on CI/CD -grep "^os=${real_os}" ${tmpd}/abc >/dev/null -grep "^release=${real_release}" ${tmpd}/abc >/dev/null -grep "^distro_id=${real_distro_id}" ${tmpd}/abc >/dev/null -grep "^distro_like=${real_distro_like}" ${tmpd}/abc >/dev/null -grep "^distro_version=${real_distro_version}" ${tmpd}/abc >/dev/null +grep "^os=${real_os}" "${tmpd}"/abc >/dev/null +grep "^release=${real_release}" "${tmpd}"/abc >/dev/null +grep "^distro_id=${real_distro_id}" "${tmpd}"/abc >/dev/null +grep "^distro_like=${real_distro_like}" "${tmpd}"/abc >/dev/null +grep "^distro_version=${real_distro_version}" "${tmpd}"/abc >/dev/null # already defined variables -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -127,16 +130,16 @@ _EOF rm -f "${tmpd}/abc" # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 --verbose +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 --verbose # tests -[ ! -e ${tmpd}/abc ] && echo "abc not installed" && exit 1 +[ ! -e "${tmpd}"/abc ] && echo "abc not installed" && exit 1 cat "${tmpd}/abc" -grep '^os=abc$' ${tmpd}/abc >/dev/null -grep '^release=def$' ${tmpd}/abc >/dev/null -grep '^distro_id=ghi$' ${tmpd}/abc >/dev/null -grep '^distro_like=jkl$' ${tmpd}/abc >/dev/null -grep '^distro_version=mno$' ${tmpd}/abc >/dev/null +grep '^os=abc$' "${tmpd}"/abc >/dev/null +grep '^release=def$' "${tmpd}"/abc >/dev/null +grep '^distro_id=ghi$' "${tmpd}"/abc >/dev/null +grep '^distro_like=jkl$' "${tmpd}"/abc >/dev/null +grep '^distro_version=mno$' "${tmpd}"/abc >/dev/null echo "OK" exit 0 diff --git a/tests-ng/variables-include.sh b/tests-ng/variables-include.sh index ac11738..4ab7406 100755 --- a/tests-ng/variables-include.sh +++ b/tests-ng/variables-include.sh @@ -28,30 +28,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 +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmps}"/dotfiles #echo "dotfile source: ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) #echo "dotfile destination: ${tmpd}" clear_on_exit "${tmps}" @@ -60,7 +63,7 @@ clear_on_exit "${tmpd}" # create the config file cfg="${tmps}/config.yaml" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -88,26 +91,26 @@ _EOF #cat ${cfg} # create the dotfile -echo "{{@@ var1 @@}}" > ${tmps}/dotfiles/abc -echo "{{@@ var2 @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ var3 @@}}" >> ${tmps}/dotfiles/abc -echo "test" >> ${tmps}/dotfiles/abc +echo "{{@@ var1 @@}}" > "${tmps}"/dotfiles/abc +echo "{{@@ var2 @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ var3 @@}}" >> "${tmps}"/dotfiles/abc +echo "test" >> "${tmps}"/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -cat ${tmpd}/abc -grep '^this is some sub-test' ${tmpd}/abc >/dev/null -grep '^12' ${tmpd}/abc >/dev/null -grep '^another test' ${tmpd}/abc >/dev/null +cat "${tmpd}"/abc +grep '^this is some sub-test' "${tmpd}"/abc >/dev/null +grep '^12' "${tmpd}"/abc >/dev/null +grep '^another test' "${tmpd}"/abc >/dev/null # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p2 +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p2 -cat ${tmpd}/abc -grep '^this is some sub-test' ${tmpd}/abc >/dev/null -grep '^42' ${tmpd}/abc >/dev/null -grep '^another test' ${tmpd}/abc >/dev/null +cat "${tmpd}"/abc +grep '^this is some sub-test' "${tmpd}"/abc >/dev/null +grep '^42' "${tmpd}"/abc >/dev/null +grep '^another test' "${tmpd}"/abc >/dev/null #cat ${tmpd}/abc diff --git a/tests-ng/variables.sh b/tests-ng/variables.sh index 94f6e60..39b0140 100755 --- a/tests-ng/variables.sh +++ b/tests-ng/variables.sh @@ -28,30 +28,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 +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmps}"/dotfiles #echo "dotfile source: ${tmps}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) #echo "dotfile destination: ${tmpd}" clear_on_exit "${tmps}" @@ -61,7 +64,7 @@ clear_on_exit "${tmpd}" cfg="${tmps}/config.yaml" export dotdrop_test_dst="${tmpd}/def" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -87,23 +90,23 @@ _EOF #cat ${cfg} # create the dotfile -echo "{{@@ var1 @@}}" > ${tmps}/dotfiles/abc -echo "{{@@ var2 @@}}" >> ${tmps}/dotfiles/abc -echo "{{@@ var3 @@}}" >> ${tmps}/dotfiles/abc -echo "test" >> ${tmps}/dotfiles/abc +echo "{{@@ var1 @@}}" > "${tmps}"/dotfiles/abc +echo "{{@@ var2 @@}}" >> "${tmps}"/dotfiles/abc +echo "{{@@ var3 @@}}" >> "${tmps}"/dotfiles/abc +echo "test" >> "${tmps}"/dotfiles/abc -echo "test_def" > ${tmps}/dotfiles/def +echo "test_def" > "${tmps}"/dotfiles/def # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 --verbose +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 --verbose -[ ! -e ${tmpd}/abc ] && echo "abc not installed" && exit 1 -grep '^this is some test' ${tmpd}/abc >/dev/null -grep '^12' ${tmpd}/abc >/dev/null -grep '^another test' ${tmpd}/abc >/dev/null +[ ! -e "${tmpd}"/abc ] && echo "abc not installed" && exit 1 +grep '^this is some test' "${tmpd}"/abc >/dev/null +grep '^12' "${tmpd}"/abc >/dev/null +grep '^another test' "${tmpd}"/abc >/dev/null -[ ! -e ${tmpd}/def ] && echo "def not installed" && exit 1 -grep '^test_def' ${tmpd}/def >/dev/null +[ ! -e "${tmpd}"/def ] && echo "def not installed" && exit 1 +grep '^test_def' "${tmpd}"/def >/dev/null #cat ${tmpd}/abc diff --git a/tests-ng/workdir-compare.sh b/tests-ng/workdir-compare.sh index 5251268..41249e6 100755 --- a/tests-ng/workdir-compare.sh +++ b/tests-ng/workdir-compare.sh @@ -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 @@ -49,15 +52,15 @@ unset DOTDROP_WORKDIR string="blabla" # the dotfile source -tmp=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmp=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) tmpf="${tmp}/dotfiles" tmpw="${tmp}/workdir" export DOTDROP_WORKDIR="${tmpw}" -mkdir -p ${tmpf} +mkdir -p "${tmpf}" echo "dotfiles source (dotpath): ${tmpf}" -mkdir -p ${tmpw} +mkdir -p "${tmpw}" echo "workdir: ${tmpw}" # create the config file @@ -65,13 +68,13 @@ cfg="${tmp}/config.yaml" echo "config file: ${cfg}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" clear_on_exit "${tmp}" clear_on_exit "${tmpd}" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -101,67 +104,67 @@ _EOF #cat ${cfg} # create the dotfile -echo "{{@@ profile @@}}" > ${tmpf}/a -echo "{{@@ profile @@}}" > ${tmpf}/b -mkdir -p ${tmpf}/c -echo "{{@@ profile @@}}" > ${tmpf}/c/a -echo "{{@@ profile @@}}" > ${tmpf}/c/b -mkdir ${tmpf}/c/x -echo "{{@@ profile @@}}" > ${tmpf}/c/x/a -echo "{{@@ profile @@}}" > ${tmpf}/c/x/b +echo "{{@@ profile @@}}" > "${tmpf}"/a +echo "{{@@ profile @@}}" > "${tmpf}"/b +mkdir -p "${tmpf}"/c +echo "{{@@ profile @@}}" > "${tmpf}"/c/a +echo "{{@@ profile @@}}" > "${tmpf}"/c/b +mkdir "${tmpf}"/c/x +echo "{{@@ profile @@}}" > "${tmpf}"/c/x/a +echo "{{@@ profile @@}}" > "${tmpf}"/c/x/b # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -b +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b # compare (no diff) -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 -b -V # add file -touch ${tmpw}/untrack +touch "${tmpw}"/untrack # compare (one diff) set +e -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 -b -V [ "$?" != "1" ] && echo "not found untracked file in workdir (1)" && exit 1 set -e # clean -rm ${tmpw}/untrack +rm "${tmpw}"/untrack # add sub file -touch ${tmpw}/${tmpd}/c/x/untrack +touch "${tmpw}"/"${tmpd}"/c/x/untrack # compare (two diff) set +e -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 -b -V [ "$?" != "1" ] && echo "not found untracked file in workdir (2)" && exit 1 set -e # clean -rm ${tmpw}/${tmpd}/c/x/untrack +rm "${tmpw}"/"${tmpd}"/c/x/untrack # add dir -mkdir ${tmpw}/d_untrack -touch ${tmpw}/d_untrack/untrack +mkdir "${tmpw}"/d_untrack +touch "${tmpw}"/d_untrack/untrack # compare (three diffs) set +e -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 -b -V [ "$?" != "1" ] && echo "not found untracked file in workdir (3)" && exit 1 set -e # clean -rm -r ${tmpw}/d_untrack +rm -r "${tmpw}"/d_untrack # add sub dir -mkdir ${tmpw}/${tmpd}/c/x/d_untrack -touch ${tmpw}/${tmpd}/c/x/d_untrack/untrack +mkdir "${tmpw}"/"${tmpd}"/c/x/d_untrack +touch "${tmpw}"/"${tmpd}"/c/x/d_untrack/untrack # compare set +e -cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 -b -V [ "$?" != "1" ] && echo "not found untracked file in workdir (4)" && exit 1 set -e ## CLEANING -rm -rf ${tmp} ${tmpd} +rm -rf "${tmp}" "${tmpd}" echo "OK" exit 0 diff --git a/tests-ng/workdir.sh b/tests-ng/workdir.sh index 763bc04..bd91d4f 100755 --- a/tests-ng/workdir.sh +++ b/tests-ng/workdir.sh @@ -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 @@ -49,15 +52,15 @@ unset DOTDROP_WORKDIR string="blabla" # the dotfile source -tmp=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmp=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) tmpf="${tmp}/dotfiles" tmpw="${tmp}/workdir" export DOTDROP_WORKDIR="${tmpw}" -mkdir -p ${tmpf} +mkdir -p "${tmpf}" echo "dotfiles source (dotpath): ${tmpf}" -mkdir -p ${tmpw} +mkdir -p "${tmpw}" echo "workdir: ${tmpw}" # create the config file @@ -65,7 +68,7 @@ cfg="${tmp}/config.yaml" echo "config file: ${cfg}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" clear_on_exit "${tmp}" @@ -73,12 +76,12 @@ clear_on_exit "${tmpd}" ## RELATIVE echo "RUNNING RELATIVE" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true dotpath: dotfiles - workdir: `echo ${tmpw} | sed 's/^.*\///g'` + workdir: $(echo "${tmpw}" | sed 's/^.*\///g') dotfiles: f_abc: dst: ${tmpd}/abc @@ -92,33 +95,33 @@ _EOF #cat ${cfg} # create the dotfile -echo "{{@@ profile @@}}" > ${tmpf}/abc -echo "${string}" >> ${tmpf}/abc +echo "{{@@ profile @@}}" > "${tmpf}"/abc +echo "${string}" >> "${tmpf}"/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V # checks -grep -r p1 ${tmpw} >/dev/null -grep -r ${string} ${tmpw} >/dev/null -[ ! -e ${tmpd}/abc ] && echo "[ERROR] dotfile not installed" && exit 1 -[ ! -h ${tmpd}/abc ] && echo "[ERROR] dotfile is not a symlink" && exit 1 +grep -r p1 "${tmpw}" >/dev/null +grep -r ${string} "${tmpw}" >/dev/null +[ ! -e "${tmpd}"/abc ] && echo "[ERROR] dotfile not installed" && exit 1 +[ ! -h "${tmpd}"/abc ] && echo "[ERROR] dotfile is not a symlink" && exit 1 ## CLEANING -rm -rf ${tmp} ${tmpd} +rm -rf "${tmp}" "${tmpd}" ## ABSOLUTE echo "RUNNING ABSOLUTE" # the dotfile source -tmp=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmp=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) tmpf="${tmp}/dotfiles" tmpw="${tmp}/workdir" export DOTDROP_WORKDIR="${tmpw}" -mkdir -p ${tmpf} +mkdir -p "${tmpf}" echo "dotfiles source (dotpath): ${tmpf}" -mkdir -p ${tmpw} +mkdir -p "${tmpw}" echo "workdir: ${tmpw}" # create the config file @@ -126,13 +129,13 @@ cfg="${tmp}/config.yaml" echo "config file: ${cfg}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" clear_on_exit "${tmp}" clear_on_exit "${tmpd}" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -151,29 +154,29 @@ _EOF #cat ${cfg} # create the dotfile -echo "{{@@ profile @@}}" > ${tmpf}/abc -echo "${string}" >> ${tmpf}/abc +echo "{{@@ profile @@}}" > "${tmpf}"/abc +echo "${string}" >> "${tmpf}"/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V # checks -grep -r p1 ${tmpw} >/dev/null -grep -r ${string} ${tmpw} >/dev/null -[ ! -e ${tmpd}/abc ] && echo "[ERROR] dotfile not installed" && exit 1 -[ ! -h ${tmpd}/abc ] && echo "[ERROR] dotfile is not a symlink" && exit 1 +grep -r p1 "${tmpw}" >/dev/null +grep -r ${string} "${tmpw}" >/dev/null +[ ! -e "${tmpd}"/abc ] && echo "[ERROR] dotfile not installed" && exit 1 +[ ! -h "${tmpd}"/abc ] && echo "[ERROR] dotfile is not a symlink" && exit 1 ## CLEANING -rm -rf ${tmp} ${tmpd} +rm -rf "${tmp}" "${tmpd}" ## NONE echo "RUNNING UNDEFINED WORKDIR" # the dotfile source -tmp=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmp=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) tmpf="${tmp}/dotfiles" -mkdir -p ${tmpf} +mkdir -p "${tmpf}" echo "dotfiles source (dotpath): ${tmpf}" # create the config file @@ -181,13 +184,13 @@ cfg="${tmp}/config.yaml" echo "config file: ${cfg}" # the dotfile destination -tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) echo "dotfiles destination: ${tmpd}" clear_on_exit "${tmp}" clear_on_exit "${tmpd}" -cat > ${cfg} << _EOF +cat > "${cfg}" << _EOF config: backup: true create: true @@ -205,17 +208,17 @@ _EOF #cat ${cfg} # create the dotfile -echo "{{@@ profile @@}}" > ${tmpf}/abc -echo "${string}" >> ${tmpf}/abc +echo "{{@@ profile @@}}" > "${tmpf}"/abc +echo "${string}" >> "${tmpf}"/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -b -V +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -b -V # checks #grep -r p1 ${tmpw} >/dev/null #grep -r ${string} ${tmpw} >/dev/null -[ ! -e ${tmpd}/abc ] && echo "[ERROR] dotfile not installed" && exit 1 -[ ! -h ${tmpd}/abc ] && echo "[ERROR] dotfile is not a symlink" && exit 1 +[ ! -e "${tmpd}"/abc ] && echo "[ERROR] dotfile not installed" && exit 1 +[ ! -h "${tmpd}"/abc ] && echo "[ERROR] dotfile is not a symlink" && exit 1 echo "OK" exit 0 diff --git a/tests.sh b/tests.sh index dfaba10..1009e18 100755 --- a/tests.sh +++ b/tests.sh @@ -14,7 +14,7 @@ if ! ${rl} "${0}" >/dev/null 2>&1; then echo "\"${rl}\" not found!" && exit 1 fi fi -cur=`dirname $(${rl} "${0}")` +cur=$(dirname "$(${rl} "${0}")") # make sure both version.py and manpage dotdrop.1 are in sync dotdrop_version=$(grep version dotdrop/version.py | sed 's/^.*= .\(.*\).$/\1/g') @@ -27,19 +27,19 @@ echo "current version ${dotdrop_version}" # test syntax echo "checking syntax..." -${cur}/test-syntax.sh +"${cur}"/test-syntax.sh # test doc echo "checking documentation..." -${cur}/test-doc.sh +"${cur}"/test-doc.sh # unittest echo "unittest..." -${cur}/test-unittest.sh +"${cur}"/test-unittest.sh # tests-ng echo "tests-ng..." -${cur}/test-ng.sh +"${cur}"/test-ng.sh ## done echo "All tests finished successfully"