From 0d6d3b48b175a3702d4e7072f4a4b4726696301d Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Fri, 1 Jun 2018 15:06:22 +0200 Subject: [PATCH] adding bash script tests for convenience --- tests-ng/README.md | 8 ++++ tests-ng/dir-import-update.sh | 69 +++++++++++++++++++++++++++++++++++ tests-ng/helpers | 40 ++++++++++++++++++++ tests.sh | 5 +++ 4 files changed, 122 insertions(+) create mode 100644 tests-ng/README.md create mode 100755 tests-ng/dir-import-update.sh create mode 100644 tests-ng/helpers diff --git a/tests-ng/README.md b/tests-ng/README.md new file mode 100644 index 0000000..ac7cad4 --- /dev/null +++ b/tests-ng/README.md @@ -0,0 +1,8 @@ +These are tests for testing entire behavior through shell scripts more easily than +the overly complicated python tests. + +For adding your own test, create a new script, copy the beginning of an +existing test script (before the *this is the test*) and complete it +with your test. + +Helper functions are available in `helpers`. diff --git a/tests-ng/dir-import-update.sh b/tests-ng/dir-import-update.sh new file mode 100755 index 0000000..99ed614 --- /dev/null +++ b/tests-ng/dir-import-update.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# author: deadc0de6 (https://github.com/deadc0de6) +# Copyright (c) 2017, deadc0de6 +# +# test importing and updating entire directories +# 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 + +################################################################ +# this is the test +################################################################ + +# dotdrop directory +basedir=`mktemp -d` +echo "dotdrop dir: ${basedir}" +# the dotfile +tmpd=`mktemp -d` +create_dir ${tmpd} + +# create the config file +cfg="${basedir}/config.yaml" +create_conf ${cfg} # sets token + +# import the dir +cd ${ddpath} | ${bin} import -c ${cfg} ${tmpd} + +# change token +echo "changed" > ${token} + +# update +cd ${ddpath} | ${bin} update -f -c ${cfg} ${tmpd} + +## CLEANING +rm -rf ${basedir} ${tmpd} + +exit 0 diff --git a/tests-ng/helpers b/tests-ng/helpers new file mode 100644 index 0000000..2d8581b --- /dev/null +++ b/tests-ng/helpers @@ -0,0 +1,40 @@ +# author: deadc0de6 (https://github.com/deadc0de6) +# Copyright (c) 2017, deadc0de6 +# +# file to be sourced from test scripts +# + +# create a directory with sub-dirs and file +# for tests +# +# $1: path of the parent directory to create +# ret: set the variable token that allows to check +create_dir() +{ + dirs="a/aa a/ab a/ac b/ba c" + mkdir -p ${1} + for d in ${dirs}; do + # create some dirs + mkdir -p ${1}/${d} + # create some files + fn=`echo ${d} | sed 's#/#-#g'` + f="${1}/${d}/${fn}" + echo "${d}" > ${f} + token=${f} + done +} + +# create a clean config file +# +# $1: path to save to +create_conf() +{ + cat > ${1} << _EOF +config: + backup: true + create: true + dotpath: dotfiles +dotfiles: +profiles: +_EOF +} diff --git a/tests.sh b/tests.sh index 7842523..ffd4563 100755 --- a/tests.sh +++ b/tests.sh @@ -10,3 +10,8 @@ pycodestyle tests/ PYTHONPATH=dotdrop nosetests --with-coverage --cover-package=dotdrop #PYTHONPATH=dotdrop nosetests -s --with-coverage --cover-package=dotdrop #PYTHONPATH=dotdrop python3 -m nose --with-coverage --cover-package=dotdrop + +# execute bash script tests +for scr in tests-ng/*.sh; do + ${scr} +done