diff --git a/tests-ng/compare-ignore.sh b/tests-ng/compare-ignore.sh new file mode 100755 index 0000000..1141c82 --- /dev/null +++ b/tests-ng/compare-ignore.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env bash +# author: deadc0de6 (https://github.com/deadc0de6) +# Copyright (c) 2017, deadc0de6 +# +# test updates +# returns 1 in case of error +# + +# exit on first error +#set -e + +# all this crap to get current path +rl="readlink -f" +if ! ${rl} "${0}" >/dev/null 2>&1; then + rl="realpath" + + if ! hash ${rl}; then + echo "\"${rl}\" not found !" && exit 1 + fi +fi +cur=$(dirname "$(${rl} "${0}")") + +#hash dotdrop >/dev/null 2>&1 +#[ "$?" != "0" ] && echo "install dotdrop to run tests" && exit 1 + +#echo "called with ${1}" + +# dotdrop path can be pass as argument +ddpath="${cur}/../" +[ "${1}" != "" ] && ddpath="${1}" +[ ! -d ${ddpath} ] && echo "ddpath \"${ddpath}\" is not a directory" && exit 1 + +export PYTHONPATH="${ddpath}:${PYTHONPATH}" +bin="python3 -m dotdrop.dotdrop" + +echo "dotdrop path: ${ddpath}" +echo "pythonpath: ${PYTHONPATH}" + +# get the helpers +source ${cur}/helpers + +echo "RUNNING $(basename $BASH_SOURCE)" + +################################################################ +# this is the test +################################################################ + +# dotdrop directory +basedir=`mktemp -d` +echo "[+] dotdrop dir: ${basedir}" +echo "[+] dotpath dir: ${basedir}/dotfiles" + +# the dotfile to be imported +tmpd=`mktemp -d` + +# some files +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 + +# import +echo "[+] import" +cd ${ddpath} | ${bin} import -c ${cfg} ${tmpd}/program +cd ${ddpath} | ${bin} import -c ${cfg} ${tmpd}/config + +# add files +echo "[+] add files" +touch ${tmpd}/program/b +touch ${tmpd}/config/b + +# expects diff +echo "[+] comparing normal" +set +e +cd ${ddpath} | ${bin} compare -c ${cfg} --verbose +[ "$?" = "0" ] && exit 1 +set -e + +# expects one diff +echo "[+] comparing with ignore" +set +e +cd ${ddpath} | ${bin} compare -c ${cfg} --verbose --ignore=${tmpd}/config/b +[ "$?" = "0" ] && exit 1 +set -e + +# expects no diff +echo "[+] comparing with ignore pattern" +set +e +cd ${ddpath} | ${bin} compare -c ${cfg} --verbose --ignore=b +[ "$?" != "0" ] && exit 1 +set -e + +## CLEANING +rm -rf ${basedir} ${tmpd} + +echo "OK" +exit 0 diff --git a/tests-ng/compare.sh b/tests-ng/compare.sh index dd6cd73..86b4a85 100755 --- a/tests-ng/compare.sh +++ b/tests-ng/compare.sh @@ -108,7 +108,10 @@ echo 'changed' > ${tmpd}/uniquefile # compare echo "[+] comparing" +set +e cd ${ddpath} | ${bin} compare -c ${cfg} --verbose +[ "$?" = "0" ] && exit 1 +set -e ## CLEANING rm -rf ${basedir} ${tmpd} diff --git a/tests/test_compare.py b/tests/test_compare.py index efa2f99..41ae303 100644 --- a/tests/test_compare.py +++ b/tests/test_compare.py @@ -14,6 +14,7 @@ from dotdrop.dotdrop import importer from dotdrop.dotdrop import compare from dotdrop.dotfile import Dotfile from dotdrop.installer import Installer +from dotdrop.comparator import Comparator from dotdrop.templategen import Templategen from tests.helpers import * @@ -32,12 +33,20 @@ class TestCompare(unittest.TestCase): t = Templategen(base=opts['dotpath'], debug=True) inst = Installer(create=opts['create'], backup=opts['backup'], dry=opts['dry'], base=opts['dotpath'], debug=True) + comp = Comparator() results = {} for dotfile in dotfiles: - same, _ = inst.compare(t, tmp, opts['profile'], - dotfile.src, dotfile.dst) + ret, insttmp = inst.install_to_temp(t, tmp, opts['profile'], + dotfile.src, dotfile.dst) + if not ret: + results[path] = False + continue + diff = comp.compare(insttmp, dotfile.dst) + print('XXXX diff for {} and {}:\n{}'.format(dotfile.src, + dotfile.dst, + diff)) path = os.path.expanduser(dotfile.dst) - results[path] = same + results[path] = diff == '' return results def edit_content(self, path, newcontent, binary=False):