From 34a8947fc173254ac644f8a78f92e3f9b385ab42 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sat, 4 May 2019 17:52:40 +0200 Subject: [PATCH] add more tests and add jhelper methods --- dotdrop/templategen.py | 2 ++ tests-ng/dotfile-variables.sh | 5 +++++ tests-ng/jhelpers.sh | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/dotdrop/templategen.py b/dotdrop/templategen.py index 2ae2aad..3b22d80 100644 --- a/dotdrop/templategen.py +++ b/dotdrop/templategen.py @@ -50,6 +50,8 @@ class Templategen: # adding helper methods self.env.globals['exists'] = jhelpers.exists self.env.globals['exists_in_path'] = jhelpers.exists_in_path + self.env.globals['basename'] = jhelpers.basename + self.env.globals['dirname'] = jhelpers.dirname def generate(self, src): """render template from path""" diff --git a/tests-ng/dotfile-variables.sh b/tests-ng/dotfile-variables.sh index 0d48d64..e23b0aa 100755 --- a/tests-ng/dotfile-variables.sh +++ b/tests-ng/dotfile-variables.sh @@ -73,14 +73,19 @@ _EOF # 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 # install 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 ## CLEANING rm -rf ${tmps} ${tmpd} diff --git a/tests-ng/jhelpers.sh b/tests-ng/jhelpers.sh index 2816236..64e5597 100755 --- a/tests-ng/jhelpers.sh +++ b/tests-ng/jhelpers.sh @@ -64,10 +64,14 @@ dotfiles: f_abc: dst: ${tmpd}/abc src: abc + f_def: + dst: ${tmpd}/def + src: def profiles: p1: dotfiles: - f_abc + - f_def _EOF #cat ${cfg} @@ -98,6 +102,22 @@ _EOF #cat ${tmps}/dotfiles/abc +echo "this is def" > ${tmps}/dotfiles/def + +# test basename +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 +{%@@ set dotfile_dirname= dirname( _dotfile_abs_dst ) @@%} +dotfile dst dirname: {{@@ dotfile_dirname @@}} +_EOF + +#cat ${tmps}/dotfiles/def + # install cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V @@ -112,6 +132,10 @@ 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 + ## CLEANING rm -rf ${tmps} ${tmpd} ${scr}