mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 17:24:46 +00:00
adding bash script tests for convenience
This commit is contained in:
8
tests-ng/README.md
Normal file
8
tests-ng/README.md
Normal file
@@ -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`.
|
||||
69
tests-ng/dir-import-update.sh
Executable file
69
tests-ng/dir-import-update.sh
Executable file
@@ -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
|
||||
40
tests-ng/helpers
Normal file
40
tests-ng/helpers
Normal file
@@ -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
|
||||
}
|
||||
5
tests.sh
5
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
|
||||
|
||||
Reference in New Issue
Block a user