1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 21:58:02 +00:00

More comprehensive test for action-args-template

This commit is contained in:
Davide Laezza
2019-06-17 12:46:25 +02:00
parent 185404ffd7
commit 497b85d673

View File

@@ -45,6 +45,20 @@ echo -e "\e[96m\e[1m==> RUNNING $(basename $BASH_SOURCE) <==\e[0m"
# this is the test
################################################################
# Convenience function to grep into a file and exit with an erro message if the
# content is not found
should_grep() {
SHOULD_GREP_STR="$1"
SHOULD_GREP_FILE="$2"
grep "$SHOULD_GREP_STR" "$SHOULD_GREP_FILE" > /dev/null || {
echo >&2 "$SHOULD_GREP_STR not found in $SHOULD_GREP_FILE"
exit 1
}
unset SHOULD_GREP_FILE SHOULD_GREP_STR
}
# the action temp
tmpa=`mktemp -d --suffix='-dotdrop-tests'`
# the dotfile source
@@ -63,7 +77,7 @@ actions:
post:
postaction: "echo {0} > ${tmpa}/post"
nakedaction: "echo {0} > ${tmpa}/naked"
profileaction: "echo {0} > ${tmpa}/profile"
profileaction: "echo {0} >> ${tmpa}/profile"
dynaction: "echo {0} > ${tmpa}/dyn"
config:
backup: true
@@ -84,11 +98,20 @@ profiles:
actions:
- profileaction '{{@@ var_profile @@}}'
- dynaction '{{@@ user_name @@}}'
include:
- p2
p2:
dotfiles:
- f_abc
actions:
- profileaction '{{@@ var_profile_2 @@}}'
variables:
var_profile_2: profile_var_2
variables:
var_pre: abc
var_post: def
var_naked: ghi
var_profile: jkl
var_pre: pre_var
var_post: post_var
var_naked: naked_var
var_profile: profile_var
dynvariables:
user_name: 'echo $USER'
_EOF
@@ -106,16 +129,12 @@ cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
[ ! -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
cat ${tmpa}/pre
grep abc ${tmpa}/pre >/dev/null
cat ${tmpa}/post
grep def ${tmpa}/post >/dev/null
cat ${tmpa}/naked
grep ghi ${tmpa}/naked >/dev/null
cat ${tmpa}/profile
grep jkl ${tmpa}/profile >/dev/null
cat ${tmpa}/dyn
grep "$USER" ${tmpa}/dyn >/dev/null
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
## CLEANING
rm -rf ${tmps} ${tmpd} ${tmpa}