1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 18:34:48 +00:00

shellcheck fixes

This commit is contained in:
deadc0de6
2023-01-27 16:44:19 +01:00
committed by deadc0de
parent fd26eb89b3
commit 2f1bbeacee
135 changed files with 4083 additions and 3950 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

65
tests-ng/actions.sh vendored
View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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"

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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

75
tests-ng/compare.sh vendored
View File

@@ -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

View File

@@ -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}"

View File

@@ -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

43
tests-ng/diff-cmd.sh vendored
View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

203
tests-ng/dry.sh vendored
View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

65
tests-ng/env.sh vendored
View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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

81
tests-ng/func_file.sh vendored
View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

43
tests-ng/globs.sh vendored
View File

@@ -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

35
tests-ng/header.sh vendored
View File

@@ -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

View File

@@ -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

83
tests-ng/import-as.sh vendored
View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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}

View File

@@ -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

77
tests-ng/import.sh vendored
View File

@@ -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

View File

@@ -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

View File

@@ -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" ] || {

View File

@@ -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"

View File

@@ -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"

View File

@@ -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

51
tests-ng/include.sh vendored
View File

@@ -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"

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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"

36
tests-ng/install.sh vendored
View File

@@ -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"

57
tests-ng/jhelpers.sh vendored
View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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"

167
tests-ng/notemplate.sh vendored
View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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

91
tests-ng/re-import.sh vendored
View File

@@ -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"

Some files were not shown because too many files have changed in this diff Show More