1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-09 23:59:16 +00:00

shell linting

This commit is contained in:
deadc0de6
2023-01-28 11:22:19 +01:00
committed by deadc0de
parent 0c3fe55d47
commit 2d603f7e83
18 changed files with 249 additions and 242 deletions

View File

@@ -54,6 +54,7 @@ echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sg
chmod_to_umask() chmod_to_umask()
{ {
u=$(umask) u=$(umask)
# shellcheck disable=SC2001
u=$(echo "${u}" | sed 's/^0*//') u=$(echo "${u}" | sed 's/^0*//')
if [ -d "${1}" ]; then if [ -d "${1}" ]; then
v=$((777 - u)) v=$((777 - u))

View File

@@ -29,7 +29,7 @@ cur=$(dirname "$(${rl} "${0}")")
# dotdrop path can be pass as argument # dotdrop path can be pass as argument
ddpath="${cur}/../" ddpath="${cur}/../"
[ "${1}" != "" ] && ddpath="${1}" [ "${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}" export PYTHONPATH="${ddpath}:${PYTHONPATH}"
bin="python3 -m dotdrop.dotdrop" bin="python3 -m dotdrop.dotdrop"
@@ -41,9 +41,10 @@ echo "dotdrop path: ${ddpath}"
echo "pythonpath: ${PYTHONPATH}" echo "pythonpath: ${PYTHONPATH}"
# get the helpers # get the helpers
source ${cur}/helpers # shellcheck source=tests-ng/helpers
source "${cur}"/helpers
echo -e "$(tput setaf 6)==> RUNNING $(basename ${BASH_SOURCE[0]}) <==$(tput sgr0)" echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)"
################################################################ ################################################################
# this is the test # this is the test
@@ -54,28 +55,22 @@ echo -e "$(tput setaf 6)==> RUNNING $(basename ${BASH_SOURCE[0]}) <==$(tput sgr0
has_rights() has_rights()
{ {
echo "testing ${1} is ${2}" echo "testing ${1} is ${2}"
[ ! -e "$1" ] && echo "`basename $1` does not exist" && exit 1 [ ! -e "$1" ] && echo "$(basename "$1") does not exist" && exit 1
local mode=`stat -L -c '%a' "$1"` local mode
[ "${mode}" != "$2" ] && echo "bad mode for `basename "$1"` (${mode} VS expected ${2})" && exit 1 mode=$(stat -L -c '%a' "$1")
[ "${mode}" != "$2" ] && echo "bad mode for $(basename "$1") (${mode} VS expected ${2})" && exit 1
true true
} }
get_file_mode() get_file_mode()
{ {
u=$(umask) u=$(umask)
# shellcheck disable=2001
u=$(echo "${u}" | sed 's/^0*//') u=$(echo "${u}" | sed 's/^0*//')
v=$((666 - u)) v=$((666 - u))
echo "${v}" echo "${v}"
} }
get_dir_mode()
{
u=$(umask)
u=$(echo "${u}" | sed 's/^0*//')
v=$((777 - u))
echo "${v}"
}
# the dotfile source # the dotfile source
tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
mkdir -p "${tmps}"/dotfiles mkdir -p "${tmps}"/dotfiles
@@ -271,7 +266,11 @@ echo "nomode" > "${tmps}"/dotfiles/nomode
chmod 600 "${tmps}"/dotfiles/nomode chmod 600 "${tmps}"/dotfiles/nomode
echo "nomode" > "${tmpd}"/nomode echo "nomode" > "${tmpd}"/nomode
chmod 700 "${tmpd}"/nomode chmod 700 "${tmpd}"/nomode
cd "${ddpath}" | printf 'y\ny\n' | ${bin} install -f -c "${cfg}" -p p2 -V f_nomode (
d "${ddpath}"
printf 'y\ny\n' | ${bin} install -f -c "${cfg}" -p p2 -V f_nomode
exit $?
)
echo "different mode (2)" echo "different mode (2)"
has_rights "${tmpd}/nomode" "600" has_rights "${tmpd}/nomode" "600"

View File

@@ -29,7 +29,7 @@ cur=$(dirname "$(${rl} "${0}")")
# dotdrop path can be pass as argument # dotdrop path can be pass as argument
ddpath="${cur}/../" ddpath="${cur}/../"
[ "${1}" != "" ] && ddpath="${1}" [ "${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}" export PYTHONPATH="${ddpath}:${PYTHONPATH}"
bin="python3 -m dotdrop.dotdrop" bin="python3 -m dotdrop.dotdrop"
@@ -41,9 +41,10 @@ echo "dotdrop path: ${ddpath}"
echo "pythonpath: ${PYTHONPATH}" echo "pythonpath: ${PYTHONPATH}"
# get the helpers # get the helpers
source ${cur}/helpers # shellcheck source=tests-ng/helpers
source "${cur}"/helpers
echo -e "$(tput setaf 6)==> RUNNING $(basename ${BASH_SOURCE[0]}) <==$(tput sgr0)" echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)"
################################################################ ################################################################
# this is the test # this is the test
@@ -54,25 +55,13 @@ echo -e "$(tput setaf 6)==> RUNNING $(basename ${BASH_SOURCE[0]}) <==$(tput sgr0
has_rights() has_rights()
{ {
echo "testing ${1} is ${2}" echo "testing ${1} is ${2}"
[ ! -e "$1" ] && echo "`basename $1` does not exist" && exit 1 [ ! -e "$1" ] && echo "$(basename "$1") does not exist" && exit 1
local mode=`stat -L -c '%a' "$1"` local mode
[ "${mode}" != "$2" ] && echo "bad mode for `basename "$1"` (${mode} instead of ${2})" && exit 1 mode=$(stat -L -c '%a' "$1")
[ "${mode}" != "$2" ] && echo "bad mode for $(basename "$1") (${mode} instead of ${2})" && exit 1
true true
} }
# $1 file
chmod_to_umask()
{
u=$(umask)
u=$(echo "${u}" | sed 's/^0*//')
if [ -d "${1}" ]; then
v=$((777 - u))
else
v=$((666 - u))
fi
chmod ${v} "${1}"
}
# the dotfile source # the dotfile source
tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
mkdir -p "${tmps}"/dotfiles mkdir -p "${tmps}"/dotfiles

View File

@@ -27,7 +27,7 @@ cur=$(dirname "$(${rl} "${0}")")
# dotdrop path can be pass as argument # dotdrop path can be pass as argument
ddpath="${cur}/../" ddpath="${cur}/../"
[ "${1}" != "" ] && ddpath="${1}" [ "${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}" export PYTHONPATH="${ddpath}:${PYTHONPATH}"
bin="python3 -m dotdrop.dotdrop" bin="python3 -m dotdrop.dotdrop"
@@ -39,9 +39,10 @@ echo "dotdrop path: ${ddpath}"
echo "pythonpath: ${PYTHONPATH}" echo "pythonpath: ${PYTHONPATH}"
# get the helpers # get the helpers
source ${cur}/helpers # shellcheck source=tests-ng/helpers
source "${cur}"/helpers
echo -e "$(tput setaf 6)==> RUNNING $(basename ${BASH_SOURCE[0]}) <==$(tput sgr0)" echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)"
################################################################ ################################################################
# this is the test # this is the test
@@ -52,9 +53,10 @@ echo -e "$(tput setaf 6)==> RUNNING $(basename ${BASH_SOURCE[0]}) <==$(tput sgr0
has_rights() has_rights()
{ {
echo "testing ${1} is ${2}" echo "testing ${1} is ${2}"
[ ! -e "$1" ] && echo "`basename $1` does not exist" && exit 1 [ ! -e "$1" ] && echo "$(basename "$1") does not exist" && exit 1
local mode=`stat -L -c '%a' "$1"` local mode
[ "${mode}" != "$2" ] && echo "bad mode for `basename $1` (${mode} VS expected ${2})" && exit 1 mode=$(stat -L -c '%a' "$1")
[ "${mode}" != "$2" ] && echo "bad mode for $(basename "$1") (${mode} VS expected ${2})" && exit 1
true true
} }
@@ -62,21 +64,24 @@ has_rights()
is_same_as() is_same_as()
{ {
echo "testing ${1} has same rights than ${2}" echo "testing ${1} has same rights than ${2}"
[ ! -e "$1" ] && echo "`basename $1` does not exist" && exit 1 [ ! -e "$1" ] && echo "$(basename "$1") does not exist" && exit 1
[ ! -e "$2" ] && echo "`basename $2` does not exist" && exit 1 [ ! -e "$2" ] && echo "$(basename "$2") does not exist" && exit 1
local mode1=`stat -L -c '%a' "$1"` local mode1
mode1=$(stat -L -c '%a' "$1")
echo "$1: ${mode1}" echo "$1: ${mode1}"
local mode2=`stat -L -c '%a' "$2"` local mode2
mode2=$(stat -L -c '%a' "$2")
echo "$2: ${mode2}" 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 true
} }
get_default_file_mode() get_default_file_mode()
{ {
u=$(umask) u=$(umask)
# shellcheck disable=SC2001
u=$(echo "${u}" | sed 's/^0*//') u=$(echo "${u}" | sed 's/^0*//')
v=$((666 - u)) v=$((666 - u))
echo "${v}" echo "${v}"
@@ -85,6 +90,7 @@ get_default_file_mode()
get_default_dir_mode() get_default_dir_mode()
{ {
u=$(umask) u=$(umask)
# shellcheck disable=SC2001
u=$(echo "${u}" | sed 's/^0*//') u=$(echo "${u}" | sed 's/^0*//')
v=$((777 - u)) v=$((777 - u))
echo "${v}" echo "${v}"

View File

@@ -111,7 +111,8 @@ chmod 777 "${dnormal}"
cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 -V "${dnormal}" cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 -V "${dnormal}"
# check rights updated # check rights updated
[ "$(stat -c '%a' "${tmps}"/dotfiles/"${tmpd}"/$(basename "${dnormal}"))" != "777" ] && echo "rights not updated (1)" && exit 1 bname=$(basename "${dnormal}")
[ "$(stat -c '%a' "${tmps}"/dotfiles/"${tmpd}"/"${bname}")" != "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 [ "${cnt}" != "1" ] && echo "chmod not updated (1)" && exit 1
@@ -122,7 +123,8 @@ chmod 777 "${dlink}"
cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 -V "${dlink}" cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 -V "${dlink}"
# check rights updated # check rights updated
[ "$(stat -c '%a' "${tmps}"/dotfiles/"${tmpd}"/$(basename "${dlink}"))" != "777" ] && echo "rights not updated (2)" && exit 1 bname=$(basename "${dlink}")
[ "$(stat -c '%a' "${tmps}"/dotfiles/"${tmpd}"/"${bname}")" != "777" ] && echo "rights not updated (2)" && exit 1
cnt=$(cat "${cfg}" | grep "chmod: '777'" | wc -l) cnt=$(cat "${cfg}" | grep "chmod: '777'" | wc -l)
[ "${cnt}" != "2" ] && echo "chmod not updated (2)" && exit 1 [ "${cnt}" != "2" ] && echo "chmod not updated (2)" && exit 1
@@ -132,7 +134,8 @@ chmod 777 "${dlinkchildren}"
cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 -V "${dlinkchildren}" cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 -V "${dlinkchildren}"
# check rights updated # check rights updated
[ "$(stat -c '%a' "${tmps}"/dotfiles/"${tmpd}"/$(basename "${dlinkchildren}"))" != "777" ] && echo "rights not updated (3)" && exit 1 bname=$(basename "${dlinkchildren}")
[ "$(stat -c '%a' "${tmps}"/dotfiles/"${tmpd}"/"${bname}")" != "777" ] && echo "rights not updated (3)" && exit 1
cnt=$(cat "${cfg}" | grep "chmod: '777'" | wc -l) cnt=$(cat "${cfg}" | grep "chmod: '777'" | wc -l)
[ "${cnt}" != "3" ] && echo "chmod not updated (3)" && exit 1 [ "${cnt}" != "3" ] && echo "chmod not updated (3)" && exit 1
@@ -142,7 +145,8 @@ chmod 777 "${fnormal}"
cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 -V "${fnormal}" cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 -V "${fnormal}"
# check rights updated # check rights updated
[ "$(stat -c '%a' "${tmps}"/dotfiles/"${tmpd}"/$(basename "${fnormal}"))" != "777" ] && echo "rights not updated (4)" && exit 1 bname=$(basename "${fnormal}")
[ "$(stat -c '%a' "${tmps}"/dotfiles/"${tmpd}"/"${bname}")" != "777" ] && echo "rights not updated (4)" && exit 1
cnt=$(cat "${cfg}" | grep "chmod: '777'" | wc -l) cnt=$(cat "${cfg}" | grep "chmod: '777'" | wc -l)
[ "${cnt}" != "4" ] && echo "chmod not updated (4)" && exit 1 [ "${cnt}" != "4" ] && echo "chmod not updated (4)" && exit 1
@@ -152,7 +156,8 @@ chmod 777 "${flink}"
cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 -V "${flink}" cd "${ddpath}" | ${bin} update -c "${cfg}" -f -p p1 -V "${flink}"
# check rights updated # check rights updated
[ "$(stat -c '%a' "${tmps}"/dotfiles/"${tmpd}"/$(basename "${flink}"))" != "777" ] && echo "rights not updated (5)" && exit 1 bname=$(basename "${flink}")
[ "$(stat -c '%a' "${tmps}"/dotfiles/"${tmpd}"/"${bname}")" != "777" ] && echo "rights not updated (5)" && exit 1
cnt=$(cat "${cfg}" | grep "chmod: '777'" | wc -l) cnt=$(cat "${cfg}" | grep "chmod: '777'" | wc -l)
[ "${cnt}" != "5" ] && echo "chmod not updated (5)" && exit 1 [ "${cnt}" != "5" ] && echo "chmod not updated (5)" && exit 1

View File

@@ -96,8 +96,11 @@ cd "${ddpath}" | ${bin} install -c "${cfg}" -f -p p1 --verbose | grep '^1 dotfil
touch "${DOTDROP_WORKDIR}"/new touch "${DOTDROP_WORKDIR}"/new
echo "[+] re-install with clear-workdir in cli" echo "[+] re-install with clear-workdir in cli"
cd "${ddpath}" | printf "y\n" | ${bin} install -W -c "${cfg}" -p p1 --verbose (
[ "$?" != "0" ] && exit 1 cd "${ddpath}"
printf "y\n" | ${bin} install -W -c "${cfg}" -p p1 --verbose
exit $?
)
[ ! -e "${tmpd}"/x ] && echo "f_x not installed" && exit 1 [ ! -e "${tmpd}"/x ] && echo "f_x not installed" && exit 1
[ ! -h "${tmpd}"/x ] && echo "f_x not symlink" && exit 1 [ ! -h "${tmpd}"/x ] && echo "f_x not symlink" && exit 1
@@ -124,8 +127,11 @@ profiles:
dotfiles: dotfiles:
- f_x - f_x
_EOF _EOF
cd "${ddpath}" | printf "y\n" | ${bin} install -W -c "${cfg}" -p p1 --verbose (
[ "$?" != "0" ] && exit 1 cd "${ddpath}"
printf "y\n" | ${bin} install -W -c "${cfg}" -p p1 --verbose
exit $?
)
[ ! -e "${tmpd}"/x ] && echo "f_x not installed" && exit 1 [ ! -e "${tmpd}"/x ] && echo "f_x not installed" && exit 1
[ ! -h "${tmpd}"/x ] && echo "f_x not symlink" && exit 1 [ ! -h "${tmpd}"/x ] && echo "f_x not symlink" && exit 1

View File

@@ -51,7 +51,7 @@ dt="${tmps}/dotfiles"
mkdir -p "${dt}" mkdir -p "${dt}"
xori="profile x" xori="profile x"
xori="profile y" yori="profile y"
echo "${xori}" > "${dt}"/file_x echo "${xori}" > "${dt}"/file_x
echo "${yori}" > "${dt}"/file_y echo "${yori}" > "${dt}"/file_y

View File

@@ -124,10 +124,10 @@ _EOF
echo "this is the test dotfile" > "${tmps}"/dotfiles/abc echo "this is the test dotfile" > "${tmps}"/dotfiles/abc
# test imported function # test imported function
echo "{{@@ "abc" | filter1 @@}}" >> "${tmps}"/dotfiles/abc echo "{{@@ \"abc\" | filter1 @@}}" >> "${tmps}"/dotfiles/abc
echo "{{@@ "arg1" | filter2('arg2') @@}}" >> "${tmps}"/dotfiles/abc echo "{{@@ \"arg1\" | filter2('arg2') @@}}" >> "${tmps}"/dotfiles/abc
echo "{{@@ "13" | filter3() @@}}" >> "${tmps}"/dotfiles/abc echo "{{@@ \"13\" | filter3() @@}}" >> "${tmps}"/dotfiles/abc
echo "{{@@ "something" | filter_ext() @@}}" >> "${tmps}"/dotfiles/abc echo "{{@@ \"something\" | filter_ext() @@}}" >> "${tmps}"/dotfiles/abc
echo "{{@@ filt @@}}variable" >> "${tmps}"/dotfiles/abc echo "{{@@ filt @@}}variable" >> "${tmps}"/dotfiles/abc
# install # install

View File

@@ -104,7 +104,6 @@ sed '/dotpath: dotfiles/a \ \ cmpignore:\n\ \ \ \ - "*b"' "${cfg}" > "${cfg2}"
cat "${cfg2}" cat "${cfg2}"
# expects no diff # expects no diff
patt="*b"
echo "[+] comparing with ignore in dotfile - 0 diff" echo "[+] comparing with ignore in dotfile - 0 diff"
set +e set +e
cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose cd "${ddpath}" | ${bin} compare -c "${cfg2}" --verbose

View File

@@ -158,7 +158,7 @@ cd "${ddpath}" | ${bin} compare -c "${cfg1}" -p p2 -V
# test with non-existing dotpath this time # test with non-existing dotpath this time
rm -rf "${tmps}"/dotfiles rm -rf "${tmps}"/dotfiles
rm -rf "${tmpd}"/* rm -rf "${tmpd:?}"/*
cat > "${cfg1}" << _EOF cat > "${cfg1}" << _EOF
config: config:
@@ -190,7 +190,7 @@ cd "${ddpath}" | ${bin} compare -c "${cfg1}" -p p2 -V
# test with same profile defined in both # test with same profile defined in both
rm -rf "${tmps}"/dotfiles rm -rf "${tmps}"/dotfiles
rm -rf "${tmpd}"/* rm -rf "${tmpd:?}"/*
cat > "${cfg1}" << _EOF cat > "${cfg1}" << _EOF
config: config:

View File

@@ -49,13 +49,6 @@ echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sg
# this is the test # this is the test
################################################################ ################################################################
# $1 pattern
# $2 path
grep_or_fail()
{
grep "${1}" "${2}" >/dev/null 2>&1 || (echo "pattern not found in ${2}" && exit 1)
}
# the dotfile source # the dotfile source
tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
mkdir -p "${tmps}"/dotfiles mkdir -p "${tmps}"/dotfiles

View File

@@ -125,8 +125,11 @@ echo "(3) found ${nb} README.md file(s)"
## reinstall to trigger showdiff ## reinstall to trigger showdiff
echo "showdiff" > "${tmpd}"/program/a echo "showdiff" > "${tmpd}"/program/a
cd "${ddpath}" | echo "y" | ${bin} install --showdiff -c "${cfg}" --verbose -f (
[ "$?" != "0" ] && exit 1 cd "${ddpath}"
printf "y\n" | ${bin} install --showdiff -c "${cfg}" --verbose -f
exit $?
)
# test templated subdir # test templated subdir
cat > "${cfg}" << _EOF cat > "${cfg}" << _EOF

33
tests-ng/install.sh vendored
View File

@@ -28,7 +28,7 @@ cur=$(dirname "$(${rl} "${0}")")
# dotdrop path can be pass as argument # dotdrop path can be pass as argument
ddpath="${cur}/../" ddpath="${cur}/../"
[ "${1}" != "" ] && ddpath="${1}" [ "${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}" export PYTHONPATH="${ddpath}:${PYTHONPATH}"
bin="python3 -m dotdrop.dotdrop" bin="python3 -m dotdrop.dotdrop"
@@ -40,9 +40,10 @@ echo "dotdrop path: ${ddpath}"
echo "pythonpath: ${PYTHONPATH}" echo "pythonpath: ${PYTHONPATH}"
# get the helpers # get the helpers
source ${cur}/helpers # shellcheck source=tests-ng/helpers
source "${cur}"/helpers
echo -e "$(tput setaf 6)==> RUNNING $(basename ${BASH_SOURCE[0]}) <==$(tput sgr0)" echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)"
################################################################ ################################################################
# this is the test # this is the test
@@ -50,8 +51,9 @@ echo -e "$(tput setaf 6)==> RUNNING $(basename ${BASH_SOURCE[0]}) <==$(tput sgr0
get_file_mode() get_file_mode()
{ {
u=`umask` u=$(umask)
u=`echo ${u} | sed 's/^0*//'` # shellcheck disable=SC2001
u=$(echo "${u}" | sed 's/^0*//')
v=$((666 - u)) v=$((666 - u))
echo "${v}" echo "${v}"
} }
@@ -61,9 +63,10 @@ get_file_mode()
has_rights() has_rights()
{ {
echo "testing ${1} is ${2}" echo "testing ${1} is ${2}"
[ ! -e "$1" ] && echo "`basename $1` does not exist" && exit 1 [ ! -e "$1" ] && echo "$(basename "$1") does not exist" && exit 1
local mode=`stat -L -c '%a' "$1"` local mode
[ "${mode}" != "$2" ] && echo "bad mode for `basename "$1"` (${mode} VS expected ${2})" && exit 1 mode=$(stat -L -c '%a' "$1")
[ "${mode}" != "$2" ] && echo "bad mode for $(basename "$1") (${mode} VS expected ${2})" && exit 1
true true
} }
@@ -113,15 +116,21 @@ chmod 644 "${tmpd}"/x
mode=$(get_file_mode "${tmpd}"/x) mode=$(get_file_mode "${tmpd}"/x)
echo "[+] re-install with no" echo "[+] re-install with no"
cd "${ddpath}" | printf "N\n" | ${bin} install -c "${cfg}" -p p1 --verbose (
[ "$?" != "0" ] && exit 1 cd "${ddpath}"
printf "N\n" | ${bin} install -c "${cfg}" -p p1 --verbose
exit ${?}
)
# if user answers N, chmod should not be done # if user answers N, chmod should not be done
has_rights "${tmpd}/x" "${mode}" has_rights "${tmpd}/x" "${mode}"
echo "[+] re-install with yes" echo "[+] re-install with yes"
cd "${ddpath}" | printf "y\n" | ${bin} install -c "${cfg}" -p p1 --verbose (
[ "$?" != "0" ] && exit 1 cd "${ddpath}"
printf "y\n" | ${bin} install -c "${cfg}" -p p1 --verbose
exit ${?}
)
has_rights "${tmpd}/x" "666" has_rights "${tmpd}/x" "666"

View File

@@ -29,7 +29,7 @@ cur=$(dirname "$(${rl} "${0}")")
# dotdrop path can be pass as argument # dotdrop path can be pass as argument
ddpath="${cur}/../" ddpath="${cur}/../"
[ "${1}" != "" ] && ddpath="${1}" [ "${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}" export PYTHONPATH="${ddpath}:${PYTHONPATH}"
bin="python3 -m dotdrop.dotdrop" bin="python3 -m dotdrop.dotdrop"
@@ -41,19 +41,20 @@ echo "dotdrop path: ${ddpath}"
echo "pythonpath: ${PYTHONPATH}" echo "pythonpath: ${PYTHONPATH}"
# get the helpers # get the helpers
source ${cur}/helpers # shellcheck source=tests-ng/helpers
source "${cur}"/helpers
echo -e "$(tput setaf 6)==> RUNNING $(basename ${BASH_SOURCE[0]}) <==$(tput sgr0)" echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)"
################################################################ ################################################################
# this is the test # this is the test
################################################################ ################################################################
# the dotfile source # the dotfile source
tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
mkdir -p ${tmps}/dotfiles mkdir -p "${tmps}"/dotfiles
# the dotfile destination # 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 "${tmps}"
clear_on_exit "${tmpd}" clear_on_exit "${tmpd}"
@@ -64,13 +65,13 @@ cfg="${tmps}/config.yaml"
# ---------------------------------------------------------- # ----------------------------------------------------------
echo -e "\n======> import with all default" echo -e "\n======> import with all default"
# create the source # create the source
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
echo "test" > ${tmpd}/qwert echo "test" > "${tmpd}"/qwert
# clean # clean
rm -rf ${tmps}/dotfiles rm -rf "${tmps}"/dotfiles
mkdir -p ${tmps}/dotfiles mkdir -p "${tmps}"/dotfiles
# config file # config file
cat > ${cfg} << _EOF cat > "${cfg}" << _EOF
config: config:
backup: true backup: true
create: true create: true
@@ -81,28 +82,28 @@ _EOF
# import # import
df="${tmpd}/qwert" df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 ${df} -V cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 "${df}" -V
# checks # checks
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:nolink,' cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V -G | grep "f_$(basename "${df}")" | head -1 | grep ',link:nolink,'
# try to install # try to install
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1 [ ! -e "${df}" ] && echo "does not exist" && exit 1
[ -h ${df} ] && echo "is symlink" && exit 1 [ -h "${df}" ] && echo "is symlink" && exit 1
# ---------------------------------------------------------- # ----------------------------------------------------------
echo -e "\n======> import with link_on_import=nolink and link_dotfile_default=nolink" echo -e "\n======> import with link_on_import=nolink and link_dotfile_default=nolink"
# create the source # create the source
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
echo "test" > ${tmpd}/qwert echo "test" > "${tmpd}"/qwert
# clean # clean
rm -rf ${tmps}/dotfiles rm -rf "${tmps}"/dotfiles
mkdir -p ${tmps}/dotfiles mkdir -p "${tmps}"/dotfiles
# config file # config file
cat > ${cfg} << _EOF cat > "${cfg}" << _EOF
config: config:
backup: true backup: true
create: true create: true
@@ -115,28 +116,28 @@ _EOF
# import # import
df="${tmpd}/qwert" df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 ${df} -V cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 "${df}" -V
# checks # checks
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:nolink,' cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V -G | grep "f_$(basename "${df}")" | head -1 | grep ',link:nolink,'
# try to install # try to install
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1 [ ! -e "${df}" ] && echo "does not exist" && exit 1
[ -h ${df} ] && echo "is symlink" && exit 1 [ -h "${df}" ] && echo "is symlink" && exit 1
# ---------------------------------------------------------- # ----------------------------------------------------------
echo -e "\n======> import with link_on_import=nolink and link_dotfile_default=nolink and --link=nolink" echo -e "\n======> import with link_on_import=nolink and link_dotfile_default=nolink and --link=nolink"
# create the source # create the source
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
echo "test" > ${tmpd}/qwert echo "test" > "${tmpd}"/qwert
# clean # clean
rm -rf ${tmps}/dotfiles rm -rf "${tmps}"/dotfiles
mkdir -p ${tmps}/dotfiles mkdir -p "${tmps}"/dotfiles
# config file # config file
cat > ${cfg} << _EOF cat > "${cfg}" << _EOF
config: config:
backup: true backup: true
create: true create: true
@@ -149,28 +150,28 @@ _EOF
# import # import
df="${tmpd}/qwert" df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 ${df} -V --link=nolink cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 "${df}" -V --link=nolink
# checks # checks
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:nolink,' cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V -G | grep "f_$(basename "${df}")" | head -1 | grep ',link:nolink,'
# try to install # try to install
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1 [ ! -e "${df}" ] && echo "does not exist" && exit 1
[ -h ${df} ] && echo "is symlink" && exit 1 [ -h "${df}" ] && echo "is symlink" && exit 1
# ---------------------------------------------------------- # ----------------------------------------------------------
echo -e "\n======> import with link_on_import=nolink and link_dotfile_default=nolink and --link=link" echo -e "\n======> import with link_on_import=nolink and link_dotfile_default=nolink and --link=link"
# create the source # create the source
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
echo "test" > ${tmpd}/qwert echo "test" > "${tmpd}"/qwert
# clean # clean
rm -rf ${tmps}/dotfiles rm -rf "${tmps}"/dotfiles
mkdir -p ${tmps}/dotfiles mkdir -p "${tmps}"/dotfiles
# config file # config file
cat > ${cfg} << _EOF cat > "${cfg}" << _EOF
config: config:
backup: true backup: true
create: true create: true
@@ -183,28 +184,28 @@ _EOF
# import # import
df="${tmpd}/qwert" df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 ${df} -V --link=absolute cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 "${df}" -V --link=absolute
# checks # checks
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:absolute,' cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V -G | grep "f_$(basename "${df}")" | head -1 | grep ',link:absolute,'
# try to install # try to install
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1 [ ! -e "${df}" ] && echo "does not exist" && exit 1
[ ! -h ${df} ] && echo "not symlink" && exit 1 [ ! -h "${df}" ] && echo "not symlink" && exit 1
# ---------------------------------------------------------- # ----------------------------------------------------------
echo -e "\n======> import with link_on_import=link and link_dotfile_default=nolink" echo -e "\n======> import with link_on_import=link and link_dotfile_default=nolink"
# create the source # create the source
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
echo "test" > ${tmpd}/qwert echo "test" > "${tmpd}"/qwert
# clean # clean
rm -rf ${tmps}/dotfiles rm -rf "${tmps}"/dotfiles
mkdir -p ${tmps}/dotfiles mkdir -p "${tmps}"/dotfiles
# config file # config file
cat > ${cfg} << _EOF cat > "${cfg}" << _EOF
config: config:
backup: true backup: true
create: true create: true
@@ -217,28 +218,28 @@ _EOF
# import # import
df="${tmpd}/qwert" df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 ${df} -V cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 "${df}" -V
# checks # checks
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:absolute,' cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V -G | grep "f_$(basename "${df}")" | head -1 | grep ',link:absolute,'
# try to install # try to install
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1 [ ! -e "${df}" ] && echo "does not exist" && exit 1
[ ! -h ${df} ] && echo "not symlink" && exit 1 [ ! -h "${df}" ] && echo "not symlink" && exit 1
# ---------------------------------------------------------- # ----------------------------------------------------------
echo -e "\n======> import with link_on_import=link and link_dotfile_default=nolink and --link=nolink" echo -e "\n======> import with link_on_import=link and link_dotfile_default=nolink and --link=nolink"
# create the source # create the source
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
echo "test" > ${tmpd}/qwert echo "test" > "${tmpd}"/qwert
# clean # clean
rm -rf ${tmps}/dotfiles rm -rf "${tmps}"/dotfiles
mkdir -p ${tmps}/dotfiles mkdir -p "${tmps}"/dotfiles
# config file # config file
cat > ${cfg} << _EOF cat > "${cfg}" << _EOF
config: config:
backup: true backup: true
create: true create: true
@@ -251,28 +252,28 @@ _EOF
# import # import
df="${tmpd}/qwert" df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 ${df} -V --link=nolink cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 "${df}" -V --link=nolink
# checks # checks
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:nolink,' cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V -G | grep "f_$(basename "${df}")" | head -1 | grep ',link:nolink,'
# try to install # try to install
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1 [ ! -e "${df}" ] && echo "does not exist" && exit 1
[ -h ${df} ] && echo "is symlink" && exit 1 [ -h "${df}" ] && echo "is symlink" && exit 1
# ---------------------------------------------------------- # ----------------------------------------------------------
echo -e "\n======> import with link_on_import=nolink and link_dotfile_default=link" echo -e "\n======> import with link_on_import=nolink and link_dotfile_default=link"
# create the source # create the source
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
echo "test" > ${tmpd}/qwert echo "test" > "${tmpd}"/qwert
# clean # clean
rm -rf ${tmps}/dotfiles rm -rf "${tmps}"/dotfiles
mkdir -p ${tmps}/dotfiles mkdir -p "${tmps}"/dotfiles
# config file # config file
cat > ${cfg} << _EOF cat > "${cfg}" << _EOF
config: config:
backup: true backup: true
create: true create: true
@@ -285,28 +286,28 @@ _EOF
# import # import
df="${tmpd}/qwert" df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 ${df} -V --link=nolink cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 "${df}" -V --link=nolink
# checks # checks
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:nolink,' cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V -G | grep "f_$(basename "${df}")" | head -1 | grep ',link:nolink,'
# try to install # try to install
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1 [ ! -e "${df}" ] && echo "does not exist" && exit 1
[ -h ${df} ] && echo "is symlink" && exit 1 [ -h "${df}" ] && echo "is symlink" && exit 1
# ---------------------------------------------------------- # ----------------------------------------------------------
echo -e "\n======> import with link_on_import=link and link_dotfile_default=nolink and --link=nolink" echo -e "\n======> import with link_on_import=link and link_dotfile_default=nolink and --link=nolink"
# create the source # create the source
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
echo "test" > ${tmpd}/qwert echo "test" > "${tmpd}"/qwert
# clean # clean
rm -rf ${tmps}/dotfiles rm -rf "${tmps}"/dotfiles
mkdir -p ${tmps}/dotfiles mkdir -p "${tmps}"/dotfiles
# config file # config file
cat > ${cfg} << _EOF cat > "${cfg}" << _EOF
config: config:
backup: true backup: true
create: true create: true
@@ -319,28 +320,28 @@ _EOF
# import # import
df="${tmpd}/qwert" df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 ${df} -V --link=nolink cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 "${df}" -V --link=nolink
# checks # checks
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:nolink,' cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V -G | grep "f_$(basename "${df}")" | head -1 | grep ',link:nolink,'
# try to install # try to install
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1 [ ! -e "${df}" ] && echo "does not exist" && exit 1
[ -h ${df} ] && echo "is symlink" && exit 1 [ -h "${df}" ] && echo "is symlink" && exit 1
# ---------------------------------------------------------- # ----------------------------------------------------------
echo -e "\n======> import with all default and --link=link" echo -e "\n======> import with all default and --link=link"
# create the source # create the source
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
echo "test" > ${tmpd}/qwert echo "test" > "${tmpd}"/qwert
# clean # clean
rm -rf ${tmps}/dotfiles rm -rf "${tmps}"/dotfiles
mkdir -p ${tmps}/dotfiles mkdir -p "${tmps}"/dotfiles
# config file # config file
cat > ${cfg} << _EOF cat > "${cfg}" << _EOF
config: config:
backup: true backup: true
create: true create: true
@@ -351,28 +352,28 @@ _EOF
# import # import
df="${tmpd}/qwert" df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -f -c ${cfg} --link=absolute -p p1 ${df} -V cd "${ddpath}" | ${bin} import -f -c "${cfg}" --link=absolute -p p1 "${df}" -V
# checks # checks
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:absolute,' cd "${ddpath}" | ${bin} files -c "${cfg}" -p p1 -V -G | grep "f_$(basename "${df}")" | head -1 | grep ',link:absolute,'
# try to install # try to install
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1 [ ! -e "${df}" ] && echo "does not exist" && exit 1
[ ! -h ${df} ] && echo "not a symlink" && exit 1 [ ! -h "${df}" ] && echo "not a symlink" && exit 1
# ---------------------------------------------------------- # ----------------------------------------------------------
echo -e "\n======> import with all default and --link=link_children" echo -e "\n======> import with all default and --link=link_children"
# create the source # create the source
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
echo "test" > ${tmpd}/qwert echo "test" > "${tmpd}"/qwert
# clean # clean
rm -rf ${tmps}/dotfiles rm -rf "${tmps}"/dotfiles
mkdir -p ${tmps}/dotfiles mkdir -p "${tmps}"/dotfiles
# config file # config file
cat > ${cfg} << _EOF cat > "${cfg}" << _EOF
config: config:
backup: true backup: true
create: true create: true
@@ -384,24 +385,24 @@ _EOF
# import # import
df="${tmpd}/qwert" df="${tmpd}/qwert"
set +e set +e
cd ${ddpath} | ${bin} import -f -c ${cfg} --link=link_children -p p1 ${df} -V cd "${ddpath}" | ${bin} import -f -c "${cfg}" --link=link_children -p p1 "${df}" -V
[ "$?" = "0" ] && echo "link_children with file should fail" && exit 1 [ "$?" = "0" ] && echo "link_children with file should fail" && exit 1
set -e set -e
# ---------------------------------------------------------- # ----------------------------------------------------------
echo -e "\n======> import with all default and --link=link_children" echo -e "\n======> import with all default and --link=link_children"
# create the source # create the source
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
mkdir -p ${tmpd}/qwert mkdir -p "${tmpd}"/qwert
echo "test" > ${tmpd}/qwert/file echo "test" > "${tmpd}"/qwert/file
mkdir -p ${tmpd}/qwert/directory mkdir -p "${tmpd}"/qwert/directory
echo "test" > ${tmpd}/qwert/directory/file echo "test" > "${tmpd}"/qwert/directory/file
# clean # clean
rm -rf ${tmps}/dotfiles rm -rf "${tmps}"/dotfiles
mkdir -p ${tmps}/dotfiles mkdir -p "${tmps}"/dotfiles
# config file # config file
cat > ${cfg} << _EOF cat > "${cfg}" << _EOF
config: config:
backup: true backup: true
create: true create: true
@@ -412,34 +413,34 @@ _EOF
# import # import
df="${tmpd}/qwert" df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -f -c ${cfg} --link=link_children -p p1 ${df} -V cd "${ddpath}" | ${bin} import -f -c "${cfg}" --link=link_children -p p1 "${df}" -V
# checks # checks
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V 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 # try to install
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 -V
[ ! -e ${df} ] && echo "does not exist" && exit 1 [ ! -e "${df}" ] && echo "does not exist" && exit 1
[ -h ${df} ] && echo "is a symlink" && exit 1 [ -h "${df}" ] && echo "is a symlink" && exit 1
[ ! -h ${df}/file ] && echo "file is not 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 ] && echo "directory is not a symlink" && exit 1
[ -h ${df}/directory/file ] && echo "directory/file is a symlink" && exit 1 [ -h "${df}"/directory/file ] && echo "directory/file is a symlink" && exit 1
echo -e "\n======> import with link_on_import=link_children and link_dotfile_default=nolink" echo -e "\n======> import with link_on_import=link_children and link_dotfile_default=nolink"
# create the source # create the source
rm -rf ${tmpd}/qwert rm -rf "${tmpd}"/qwert
mkdir -p ${tmpd}/qwert mkdir -p "${tmpd}"/qwert
echo "test" > ${tmpd}/qwert/file echo "test" > "${tmpd}"/qwert/file
mkdir -p ${tmpd}/qwert/directory mkdir -p "${tmpd}"/qwert/directory
echo "test" > ${tmpd}/qwert/directory/file echo "test" > "${tmpd}"/qwert/directory/file
# clean # clean
rm -rf ${tmps}/dotfiles rm -rf "${tmps}"/dotfiles
mkdir -p ${tmps}/dotfiles mkdir -p "${tmps}"/dotfiles
# config file # config file
cat > ${cfg} << _EOF cat > "${cfg}" << _EOF
config: config:
backup: true backup: true
create: true create: true
@@ -452,11 +453,11 @@ _EOF
# import # import
df="${tmpd}/qwert" df="${tmpd}/qwert"
cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 ${df} -V cd "${ddpath}" | ${bin} import -f -c "${cfg}" -p p1 "${df}" -V
# checks # checks
cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V 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 # try to install
rm -rf "${tmpd}"/qwert rm -rf "${tmpd}"/qwert

View File

@@ -238,7 +238,7 @@ _EOF
#cat ${cfg} #cat ${cfg}
# clean destination # clean destination
rm -rf "${tmpd}"/* rm -rf "${tmpd:?}"/*
# install # install
cd "${ddpath}" | ${bin} install -f --showdiff -c "${cfg}" -p p1 -V cd "${ddpath}" | ${bin} install -f --showdiff -c "${cfg}" -p p1 -V

View File

@@ -44,13 +44,6 @@ echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sg
# this is the test # this is the test
################################################################ ################################################################
# $1 pattern
# $2 path
grep_or_fail()
{
grep "${1}" "${2}" >/dev/null 2>&1 || (echo "pattern not found in ${2}" && exit 1)
}
# dotdrop directory # dotdrop directory
tmps=$(mktemp -d --suffix='-dotdrop-tests-source' || mktemp -d) tmps=$(mktemp -d --suffix='-dotdrop-tests-source' || mktemp -d)
dt="${tmps}/dotfiles" dt="${tmps}/dotfiles"

View File

@@ -97,7 +97,11 @@ echo "var4: {{@@ var4 @@}}" >> "${tmps}"/dotfiles/abc
# install # install
echo "step 1" echo "step 1"
cd "${ddpath}" | echo -e 'var1contentxxx\nvar2contentyyy\nvar3\nvar4\n' | ${bin} install -f -c "${cfg}" -p p1 -V (
cd "${ddpath}"
printf 'var1contentxxx\nvar2contentyyy\nvar3\nvar4\n' | ${bin} install -f -c "${cfg}" -p p1 -V
exit ${?}
)
cat "${tmpd}"/abc cat "${tmpd}"/abc

View File

@@ -49,7 +49,6 @@ echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sg
# this is the test # this is the test
################################################################ ################################################################
unset DOTDROP_WORKDIR unset DOTDROP_WORKDIR
string="blabla"
# the dotfile source # the dotfile source
tmp=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) tmp=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)