Skip to content

Commit 108a367

Browse files
committed
more tests
1 parent 1cb5a03 commit 108a367

File tree

2 files changed

+245
-0
lines changed

2 files changed

+245
-0
lines changed

tests-ng/compare-diff-types.sh

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/env bash
2+
# author: deadc0de6 (https://github.com/deadc0de6)
3+
# Copyright (c) 2023, deadc0de6
4+
#
5+
# test updates
6+
# returns 1 in case of error
7+
#
8+
9+
# exit on first error
10+
set -e
11+
12+
# all this crap to get current path
13+
rl="readlink -f"
14+
if ! ${rl} "${0}" >/dev/null 2>&1; then
15+
rl="realpath"
16+
17+
if ! hash ${rl}; then
18+
echo "\"${rl}\" not found !" && exit 1
19+
fi
20+
fi
21+
cur=$(dirname "$(${rl} "${0}")")
22+
23+
#hash dotdrop >/dev/null 2>&1
24+
#[ "$?" != "0" ] && echo "install dotdrop to run tests" && exit 1
25+
26+
#echo "called with ${1}"
27+
28+
# dotdrop path can be pass as argument
29+
ddpath="${cur}/../"
30+
[ "${1}" != "" ] && ddpath="${1}"
31+
[ ! -d "${ddpath}" ] && echo "ddpath \"${ddpath}\" is not a directory" && exit 1
32+
33+
export PYTHONPATH="${ddpath}:${PYTHONPATH}"
34+
bin="python3 -m dotdrop.dotdrop"
35+
if hash coverage 2>/dev/null; then
36+
bin="coverage run -p --source=dotdrop -m dotdrop.dotdrop"
37+
fi
38+
39+
echo "dotdrop path: ${ddpath}"
40+
echo "pythonpath: ${PYTHONPATH}"
41+
42+
# get the helpers
43+
# shellcheck source=tests-ng/helpers
44+
source "${cur}"/helpers
45+
46+
echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)"
47+
48+
################################################################
49+
# this is the test
50+
################################################################
51+
52+
# dotdrop directory
53+
basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
54+
echo "[+] dotdrop dir: ${basedir}"
55+
echo "[+] dotpath dir: ${basedir}/dotfiles"
56+
mkdir -p "${basedir}/dotfiles"
57+
58+
# the dotfile to be imported
59+
tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
60+
61+
clear_on_exit "${basedir}"
62+
clear_on_exit "${tmpd}"
63+
64+
# create the config file
65+
cfg="${basedir}/config.yaml"
66+
cat > "${cfg}" << _EOF
67+
config:
68+
backup: true
69+
create: true
70+
dotpath: dotfiles
71+
dotfiles:
72+
f_file:
73+
src: file
74+
dst: ${tmpd}/file
75+
d_file:
76+
src: dir
77+
dst: ${tmpd}/dir
78+
profiles:
79+
p1:
80+
dotfiles:
81+
- f_file
82+
p2:
83+
dotfiles:
84+
- d_file
85+
_EOF
86+
87+
# file and dir
88+
echo "test" > "${basedir}"/dotfiles/file
89+
mkdir "${tmpd}"/file
90+
91+
# dir and file
92+
mkdir "${basedir}"/dotfiles/dir
93+
echo "test" > "${tmpd}"/dir
94+
95+
# compare
96+
echo "[+] comparing p1"
97+
set +e
98+
cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 --verbose
99+
[ "$?" = "0" ] && exit 1
100+
set -e
101+
102+
echo "[+] comparing p2"
103+
set +e
104+
cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p2 --verbose
105+
[ "$?" = "0" ] && exit 1
106+
set -e
107+
108+
echo "OK"
109+
exit 0

tests-ng/misc.sh

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#!/usr/bin/env bash
2+
# author: deadc0de6 (https://github.com/deadc0de6)
3+
# Copyright (c) 2023, deadc0de6
4+
#
5+
# test misc stuff
6+
# returns 1 in case of error
7+
#
8+
9+
# exit on first error
10+
set -e
11+
12+
# all this crap to get current path
13+
rl="readlink -f"
14+
if ! ${rl} "${0}" >/dev/null 2>&1; then
15+
rl="realpath"
16+
17+
if ! hash ${rl}; then
18+
echo "\"${rl}\" not found !" && exit 1
19+
fi
20+
fi
21+
cur=$(dirname "$(${rl} "${0}")")
22+
23+
#hash dotdrop >/dev/null 2>&1
24+
#[ "$?" != "0" ] && echo "install dotdrop to run tests" && exit 1
25+
26+
#echo "called with ${1}"
27+
28+
# dotdrop path can be pass as argument
29+
ddpath="${cur}/../"
30+
[ "${1}" != "" ] && ddpath="${1}"
31+
[ ! -d "${ddpath}" ] && echo "ddpath \"${ddpath}\" is not a directory" && exit 1
32+
33+
export PYTHONPATH="${ddpath}:${PYTHONPATH}"
34+
bin="python3 -m dotdrop.dotdrop"
35+
if hash coverage 2>/dev/null; then
36+
bin="coverage run -p --source=dotdrop -m dotdrop.dotdrop"
37+
fi
38+
39+
echo "dotdrop path: ${ddpath}"
40+
echo "pythonpath: ${PYTHONPATH}"
41+
42+
# get the helpers
43+
# shellcheck source=tests-ng/helpers
44+
source "${cur}"/helpers
45+
46+
echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)"
47+
48+
################################################################
49+
# this is the test
50+
################################################################
51+
52+
# dotdrop directory
53+
basedir=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
54+
mkdir -p "${basedir}"/dotfiles
55+
echo "[+] dotdrop dir: ${basedir}"
56+
echo "[+] dotpath dir: ${basedir}/dotfiles"
57+
tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
58+
59+
clear_on_exit "${basedir}"
60+
clear_on_exit "${tmpd}"
61+
62+
echo "content" > "${basedir}"/dotfiles/x
63+
64+
# create the config file
65+
cfg="${basedir}/config.yaml"
66+
cat > "${cfg}" << _EOF
67+
config:
68+
backup: true
69+
create: true
70+
dotpath: dotfiles
71+
dotfiles:
72+
f_x:
73+
src: x
74+
dst: ${tmpd}/x
75+
f_fake:
76+
src:
77+
dst:
78+
profiles:
79+
p1:
80+
dotfiles:
81+
- f_x
82+
p2:
83+
dotfiles:
84+
p3:
85+
dotfiles:
86+
- f_fake
87+
_EOF
88+
89+
echo "[+] compare - does not exist on dst"
90+
set +e
91+
cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p1 --verbose
92+
[ "$?" = "0" ] && exit 1
93+
set -e
94+
95+
echo "[+] install - no dotfiles"
96+
set +e
97+
cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p2 --verbose
98+
[ "$?" = "0" ] && exit 1
99+
set -e
100+
101+
echo "[+] compare - no dotfiles"
102+
cd "${ddpath}" | ${bin} compare -c "${cfg}" -p p2 --verbose
103+
[ "$?" != "0" ] && exit 1
104+
105+
echo "[+] compare - fake dotfile"
106+
cd "${ddpath}" | ${bin} compare -w1 -c "${cfg}" -p p3 --verbose
107+
[ "$?" != "0" ] && exit 1
108+
109+
echo "[+] compare - fake dotfile"
110+
cd "${ddpath}" | ${bin} compare -w3 -c "${cfg}" -p p3 --verbose
111+
[ "$?" != "0" ] && exit 1
112+
113+
set +e
114+
echo "[+] update - bad profile"
115+
cd "${ddpath}" | ${bin} update -c "${cfg}" -p p4 --verbose
116+
[ "$?" = "0" ] && exit 1
117+
set -e
118+
119+
echo "[+] grepable profiles"
120+
cd "${ddpath}" | ${bin} profiles -c "${cfg}" --grepable --verbose
121+
[ "$?" != "0" ] && exit 1
122+
123+
echo "[+] files - bad profile but return 0"
124+
cd "${ddpath}" | ${bin} files -c "${cfg}" -p p10 --verbose
125+
[ "$?" != "0" ] && exit 1
126+
127+
echo "[+] detail - bad profile but return 0"
128+
cd "${ddpath}" | ${bin} detail -c "${cfg}" -p p10 --verbose
129+
[ "$?" != "0" ] && exit 1
130+
131+
echo "[+] remove - no dotfiles"
132+
cd "${ddpath}" | ${bin} remove -c "${cfg}" -p p2 --verbose
133+
[ "$?" != "0" ] && exit 1
134+
135+
echo "OK"
136+
exit 0

0 commit comments

Comments
 (0)