From 28f39ad0abfbe135b37f17b4a3a22c45d4f15722 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Wed, 27 Nov 2019 20:10:13 +0100 Subject: [PATCH] fix tests --- dotdrop/dotdrop.py | 23 +++++++++++++++------- dotdrop/options.py | 8 ++++++-- tests-ng/deprecated-link.sh | 13 ++++++------- tests-ng/import-link-children.sh | 3 +-- tests-ng/link-value-tests.sh | 33 +++++++++++--------------------- tests/helpers.py | 1 + 6 files changed, 41 insertions(+), 40 deletions(-) diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 09ba096..7601e48 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -410,9 +410,12 @@ def cmd_list_profiles(o): """list all profiles""" LOG.emph('Available profile(s):\n') for p in o.profiles: - LOG.sub(p.key, end='') - LOG.log(' ({} dotfiles)'.format(len(p.dotfiles))) - #LOG.sub('{} ({} dotfile(s))'.format(p.key, len(p.dotfiles))) + if o.profiles_grepable: + fmt = '{}'.format(p.key) + LOG.raw(fmt) + else: + LOG.sub(p.key, end='') + LOG.log(' ({} dotfiles)'.format(len(p.dotfiles))) LOG.log('') @@ -430,10 +433,16 @@ def cmd_list_files(o): src = os.path.join(o.dotpath, dotfile.src) if not Templategen.is_template(src): continue - LOG.log('{}'.format(dotfile.key), bold=True) - LOG.sub('dst: {}'.format(dotfile.dst)) - LOG.sub('src: {}'.format(dotfile.src)) - LOG.sub('link: {}'.format(dotfile.link.name.lower())) + if o.files_grepable: + fmt = '{},dst:{},src:{},link:{}' + fmt = fmt.format(dotfile.key, dotfile.dst, + dotfile.src, dotfile.link.name.lower()) + LOG.raw(fmt) + else: + LOG.log('{}'.format(dotfile.key), bold=True) + LOG.sub('dst: {}'.format(dotfile.dst)) + LOG.sub('src: {}'.format(dotfile.src)) + LOG.sub('link: {}'.format(dotfile.link.name.lower())) LOG.log('') diff --git a/dotdrop/options.py b/dotdrop/options.py index 9457717..8489ca9 100644 --- a/dotdrop/options.py +++ b/dotdrop/options.py @@ -59,9 +59,9 @@ Usage: dotdrop update [-VbfdkP] [-c ] [-p ] [-i ...] [...] dotdrop remove [-Vbfdk] [-c ] [-p ] [...] - dotdrop files [-VbT] [-c ] [-p ] + dotdrop files [-VbTG] [-c ] [-p ] dotdrop detail [-Vb] [-c ] [-p ] [...] - dotdrop profiles [-Vb] [-c ] + dotdrop profiles [-VbG] [-c ] dotdrop --help dotdrop --version @@ -83,6 +83,7 @@ Options: -V --verbose Be verbose. -d --dry Dry run. -b --no-banner Do not display the banner. + -G --grepable Grepable output. -v --version Show version. -h --help Show this screen. """.format(BANNER, PROFILE) @@ -214,6 +215,9 @@ class Options(AttrMonitor): # "files" specifics self.files_templateonly = self.args['--template'] + self.files_grepable = self.args['--grepable'] + # "profiles" specifics + self.profiles_grepable = self.args['--grepable'] # "install" specifics self.install_force_action = self.args['--force-actions'] self.install_temporary = self.args['--temp'] diff --git a/tests-ng/deprecated-link.sh b/tests-ng/deprecated-link.sh index fcda341..262c2b5 100755 --- a/tests-ng/deprecated-link.sh +++ b/tests-ng/deprecated-link.sh @@ -125,13 +125,12 @@ set -e # test values have been correctly updated echo "========> test for updated entries" -dotfiles=`cd ${ddpath} | ${bin} files -c ${cfg} -p p1 | grep -v '^ '` -echo "${dotfiles}" | grep '^f_link ' | grep ', link: link)' -echo "${dotfiles}" | grep '^f_nolink ' | grep ', link: nolink)' -echo "${dotfiles}" | grep '^f_nolink1 ' | grep ', link: nolink)' -echo "${dotfiles}" | grep '^f_children ' | grep ', link: link_children)' -echo "${dotfiles}" | grep '^f_children2 ' | grep ', link: link_children)' -echo "${dotfiles}" | grep '^f_children3 ' | grep ', link: nolink)' +cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_link' | head -1 | grep ',link:link$' +cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_nolink' | head -1 | grep ',link:nolink$' +cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_nolink1' | head -1 | grep ',link:nolink$' +cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_children' | head -1 | grep ',link:link_children$' +cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_children2' | head -1 | grep ',link:link_children$' +cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_children3' | head -1 | grep ',link:nolink$' ## CLEANING rm -rf ${tmps} ${tmpd} diff --git a/tests-ng/import-link-children.sh b/tests-ng/import-link-children.sh index c685f6f..8fae7c2 100755 --- a/tests-ng/import-link-children.sh +++ b/tests-ng/import-link-children.sh @@ -88,8 +88,7 @@ _EOF cd ${ddpath} | ${bin} import -c ${cfg} -p p1 -V --link=link_children ${dt} # check is set to link_children -line=$(cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V | grep "d_`basename ${dt}`") -echo ${line} | grep 'link: link_children' +cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "d_`basename ${dt}`" | grep ',link:link_children$' # checks file exists in dotpath [ ! -e ${dotpath}/${dt} ] && echo "dotfile not imported" && exit 1 diff --git a/tests-ng/link-value-tests.sh b/tests-ng/link-value-tests.sh index 1e77de3..f1b7b01 100755 --- a/tests-ng/link-value-tests.sh +++ b/tests-ng/link-value-tests.sh @@ -79,8 +79,7 @@ cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V # checks cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -line=$(cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V | grep "f_`basename ${df}`") -echo ${line} | 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 rm -rf ${tmpd}/qwert @@ -114,8 +113,7 @@ cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V # checks cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -line=$(cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V | grep "f_`basename ${df}`") -echo ${line} | 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 rm -rf ${tmpd}/qwert @@ -149,8 +147,7 @@ cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V --link=nolink # checks cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -line=$(cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V | grep "f_`basename ${df}`") -echo ${line} | 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 rm -rf ${tmpd}/qwert @@ -184,8 +181,7 @@ cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V --link=link # checks cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -line=$(cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V | grep "f_`basename ${df}`") -echo ${line} | grep 'link: link' +cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:link$' # try to install rm -rf ${tmpd}/qwert @@ -219,8 +215,7 @@ cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V # checks cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -line=$(cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V | grep "f_`basename ${df}`") -echo ${line} | grep 'link: link' +cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:link$' # try to install rm -rf ${tmpd}/qwert @@ -254,8 +249,7 @@ cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V --link=nolink # checks cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -line=$(cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V | grep "f_`basename ${df}`") -echo ${line} | 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 rm -rf ${tmpd}/qwert @@ -289,8 +283,7 @@ cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V --link=nolink # checks cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -line=$(cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V | grep "f_`basename ${df}`") -echo ${line} | 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 rm -rf ${tmpd}/qwert @@ -324,8 +317,7 @@ cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V --link=nolink # checks cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -line=$(cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V | grep "f_`basename ${df}`") -echo ${line} | 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 rm -rf ${tmpd}/qwert @@ -357,8 +349,7 @@ cd ${ddpath} | ${bin} import -c ${cfg} --link=link -p p1 ${df} -V # checks cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -line=$(cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V | grep "f_`basename ${df}`") -echo ${line} | grep 'link: link' +cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:link$' # try to install rm -rf ${tmpd}/qwert @@ -419,8 +410,7 @@ cd ${ddpath} | ${bin} import -c ${cfg} --link=link_children -p p1 ${df} -V # checks cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -line=$(cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V | grep "d_`basename ${df}`") -echo ${line} | 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 rm -rf ${tmpd}/qwert @@ -460,8 +450,7 @@ cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V # checks cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -line=$(cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V | grep "d_`basename ${df}`") -echo ${line} | 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 rm -rf ${tmpd}/qwert diff --git a/tests/helpers.py b/tests/helpers.py index 8b35ed0..997a487 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -128,6 +128,7 @@ def _fake_args(): args['--ignore'] = [] args['--show-patch'] = False args['--force-actions'] = False + args['--grepable'] = False # cmds args['profiles'] = False args['files'] = False