1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 12:46:44 +00:00
This commit is contained in:
deadc0de6
2024-01-28 22:26:46 +01:00
committed by deadc0de
parent 9cf210e194
commit 0ac692b2f8
5 changed files with 254 additions and 9 deletions

156
tests-ng/ignore-dir-when-sub-ignored.sh vendored Executable file
View File

@@ -0,0 +1,156 @@
#!/usr/bin/env bash
# author: deadc0de6 (https://github.com/deadc0de6)
# Copyright (c) 2024, deadc0de6
#
# test ignore patterns and especially that if
# the directory content is ignored, so is the directory itself
# returns 1 in case of error
#
## start-cookie
set -eu -o errtrace -o pipefail
cur=$(cd "$(dirname "${0}")" && pwd)
ddpath="${cur}/../"
PPATH="{PYTHONPATH:-}"
export PYTHONPATH="${ddpath}:${PPATH}"
altbin="python3 -m dotdrop.dotdrop"
if hash coverage 2>/dev/null; then
mkdir -p coverages/
altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop"
fi
bin="${DT_BIN:-${altbin}}"
# shellcheck source=tests-ng/helpers
source "${cur}"/helpers
echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)"
## end-cookie
################################################################
# this is the test
################################################################
# the dotfile source
tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
dotpath="${tmps}"/dotfiles
mkdir -p "${dotpath}"
#echo "dotfile source: ${tmps}"
# the dotfile destination
tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
#echo "dotfile destination: ${tmpd}"
clear_on_exit "${tmps}"
clear_on_exit "${tmpd}"
# create the config file
cfg1="${tmps}/config1.yaml"
cfg2="${tmps}/config2.yaml"
cat > "${cfg1}" << _EOF
config:
backup: true
create: true
dotpath: dotfiles
ignoreempty: true
dotfiles:
d_mpv:
src: mpv
dst: ${tmpd}/mpv
cmpignore:
- '*/watch_later/x'
upignore:
- '*/watch_later/x'
instignore:
- '*/watch_later/x'
profiles:
p1:
dotfiles:
- d_mpv
_EOF
cat > "${cfg2}" << _EOF
config:
backup: true
create: true
dotpath: dotfiles
ignoreempty: true
impignore:
- '*/watch_later/x'
dotfiles:
profiles:
_EOF
clean_both()
{
rm -rf "${dotpath}/mpv"
rm -rf "${tmpd}/mpv"
}
# $1 parent
create_hierarchy()
{
mkdir -p "${1}"/mpv
echo "file" > "${1}"/mpv/file
mkdir -p "${1}"/mpv/dir1
echo "file2" > "${1}"/mpv/dir1/file
mkdir -p "${1}"/mpv/watch_later
echo "watch_later" > "${1}"/mpv/watch_later/x
}
create_in_dotpath()
{
create_hierarchy "${dotpath}"
}
create_in_dst()
{
create_hierarchy "${tmpd}"
}
###################################################
# test install
###################################################
clean_both
create_in_dotpath
cd "${ddpath}" | ${bin} install -f -c "${cfg1}" -p p1 -V
[ -d "${tmpd}/mpv/watch_later" ] && echo "install failed" && exit 1
###################################################
# test update
###################################################
clean_both
create_in_dotpath
create_in_dst
# modify
echo newfile > "${tmpd}/mpv/new"
rm -rf "${dotpath}/mpv/watch_later"
cd "${ddpath}" | ${bin} update -f -c "${cfg1}" -p p1 -V
[ -d "${dotpath}/mpv/watch_later" ] && echo "update failed - watch_later created" && exit 1
[ -e "${dotpath}/mpv/watch_later/x" ] && echo "update failed - x added" && exit 1
[ ! -e "${dotpath}/mpv/new" ] && echo "update failed - no new file" && exit 1
###################################################
# test import
###################################################
exit 0 # TODO
clean_both
create_in_dst
cd "${ddpath}" | ${bin} import -f -c "${cfg2}" -p p1 -V "${tmpd}/mpv"
[ -d "${dotpath}/${tmpd}/mpv/watch_later" ] && echo "import failed" && exit 1
[ ! -e "${dotpath}/${tmpd}/mpv/file" ] && echo "import failed - file" && exit 1
###################################################
# test compare
###################################################
clean_both
create_in_dst
create_in_dotpath
rm -r "${dotpath}/mpv/watch_later"
cd "${ddpath}" | ${bin} compare -c "${cfg1}" -p p1 -V
###################################################
echo "OK"
exit 0

View File

@@ -74,7 +74,7 @@ echo "c" > "${tmpd}"/a/x/yfile
# update "dir" filesystem
echo "new" > "${tmpd}"/dir/a/a
mkdir -p "${dt}"/dir/a/be-gone
touch "${dt}"/dir/a/be-gone
touch "${tmpd}"/dir/newfile
mkdir -p "${tmpd}"/dir/ignore
echo "ignore-me" > "${tmpd}"/dir/ignore/ignore-me
@@ -117,12 +117,12 @@ cd "${ddpath}" | ${bin} update -f --verbose -c "${cfg}" --profile=p1
grep_or_fail 'b' "${dt}/a/c/acfile"
grep_or_fail 'a' "${dt}/a/x/xfile"
[ -e "${dt}"/a/newfile ] && echo "'a' newfile should have been removed" && exit 1
[ -d "${dt}"/a/be-gone ] && echo "'a' be-gone should have been removed" && exit 1
[ -e "${dt}"/a/be-gone ] && echo "'file' be-gone should have been removed" && exit 1
[ -e "${dt}"/x/yfile ] && echo "'a' yfile should not have been added" && exit 1
# check "dir" files are correct
grep_or_fail 'new' "${dt}"/dir/a/a
[ -d "${dt}"/dir/a/be-gone ] && echo "'dir' be-gone should have been removed" && exit 1
[ -e "${dt}"/dir/a/be-gone ] && echo "'file' be-gone should have been removed" && exit 1
[ ! -e "${tmpd}"/dir/newfile ] && echo "'dir' newfile should have been removed" && exit 1
[ -d "${dt}"/dir/ignore ] && echo "'dir' ignore dir not ignored" && exit 1
[ -f "${dt}"/dir/ignore/ignore-me ] && echo "'dir' ignore-me not ignored" && exit 1