From 1b7bc656b207685ce8cb04363fdca660d9595593 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Thu, 19 Nov 2015 13:45:16 +0100 Subject: tests-api: new 'dtf_prereq pkg' method * share/dtf/lib/tests (dtf_debug): New function to simplify debugging. (__dtf_debug): Internal wrapper for debugging. (dtf_pkg_install): Be more verbose if the method is used wrongly. (dtf_prereq): Accept 'pkg installed' subaction. --- share/dtf/lib/tests | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'share/dtf/lib') diff --git a/share/dtf/lib/tests b/share/dtf/lib/tests index b4a1a4c..1aa376a 100644 --- a/share/dtf/lib/tests +++ b/share/dtf/lib/tests @@ -10,6 +10,7 @@ dtf_skip () exit 77 } + dtf_fail () { test -n "$1" && echo >&2 "$1" @@ -17,6 +18,26 @@ dtf_fail () } +dtf_debug () +{ + for _d_i in $1 + do + case " $DTF_DBG_KEYWORDS " in + *\ $_d_i\ *) + shift + echo >&4 " ~ $*" + return 0 + ;; + esac + done +} + + +__dtf_debug () +{ + dtf_debug dtf_lib "$*" +} + __dtf_method_not_implemented () { dtf_fail "'$1' method is not implemented" @@ -27,6 +48,7 @@ __dtf_method_not_implemented () # ------------------------- dtf_pkg_installed () { + __dtf_debug "checking whether '$1' is installed" # {% if config.os.id in ["fedora", "rhel", "centos"] %} rpm -q "$1" &>/dev/null # {% else %} @@ -42,10 +64,11 @@ __dtf_assert_nargs () test $# -ge "$_d_nargs" && return + _d_tr="$# given ($*)" if test "$_d_nargs" -eq 1; then - dtf_fail "method '$_d_method' requires at least 1 argument" + dtf_fail "method '$_d_method' requires at least 1 argument, $_d_tr" else - dtf_fail "method '$_d_method' requires at least $_d_nargs arguments" + dtf_fail "method '$_d_method' requires at least $_d_nargs arguments, $_d_tr" fi } @@ -90,11 +113,18 @@ __dtf_prereq_pkg () { __dtf_assert_nargs 2 'dtf_prereq pkg' ${1+"$@"} + _d_subaction=$1 ; shift _d_pkg=$1 ; shift - dtf_pkg_installed "$_d_pkg" && return 0 - - dtf_pkg_install "$_d_pkg" + case $_d_subaction in + installed) + dtf_pkg_installed "$_d_pkg" && return 0 + dtf_pkg_install "$_d_pkg" + ;; + *) + dtf_fail "dtf_prereq pkg: not implemented action $_d_subaction" + ;; + esac } -- cgit