summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Raiskup <praiskup@redhat.com>2015-11-20 14:04:53 +0100
committerPavel Raiskup <praiskup@redhat.com>2015-11-20 14:04:53 +0100
commit16a583930d2bf7fedb72a3a5044dc336a96c306b (patch)
tree93c28ea5aafe01d8347dad5b6eea86bee4956ff3
parentaa0c1726b80eee693b092d4d2151eddc3a1bed36 (diff)
downloaddtf-16a583930d2bf7fedb72a3a5044dc336a96c306b.zip
dtf-16a583930d2bf7fedb72a3a5044dc336a96c306b.tar.gz
dtf-16a583930d2bf7fedb72a3a5044dc336a96c306b.tar.xz
tests-api: new 'dtf_assert cmd'
* share/dtf/lib/tests (dtf_assert): Handle new action 'cmd'. (__dtf_cmd): New internal wrapper around shell eval. (__dtf_assert_cmd): New internal function - checks that that __dtf_cmd ends with proper exit status.
-rw-r--r--share/dtf/lib/tests33
1 files changed, 32 insertions, 1 deletions
diff --git a/share/dtf/lib/tests b/share/dtf/lib/tests
index 3f6c752..e927307 100644
--- a/share/dtf/lib/tests
+++ b/share/dtf/lib/tests
@@ -88,6 +88,10 @@ dtf_assert ()
root|ROOT)
dtf_is_root || dtf_fail "root accout required"
;;
+ cmd)
+ shift
+ __dtf_assert_cmd "$@"
+ ;;
*)
dtf_fail "dtf_assert '$1' not implemented"
;;
@@ -158,6 +162,34 @@ __dtf_prereq_pkg ()
}
+__dtf_cmd ()
+{
+ __dtf_debug "running $1"
+
+ _d_cmd=$1 ; shift
+ eval "$_d_cmd"
+ __dtf_cmd_result_status=$?
+}
+
+
+__dtf_assert_cmd ()
+{
+ _d_a_cmd=$1 ; shift
+ _d_ok_statuses=$1 ; shift
+ __dtf_cmd "$_d_a_cmd"
+
+ case " $_d_ok_statuses " in
+ *"$__dtf_cmd_result_status "*)
+ ;;
+ *)
+ _d_f_msg="cmd '$_d_a_cmd' ended with '$__dtf_cmd_result_status' while "
+ _d_f_msg="$_d_f_msg it should end with one of { $_d_ok_statuses }"
+ dtf_fail "$_d_f_msg"
+ ;;
+ esac
+}
+
+
# dtf_prereq REQUIREMENT [ARGS..]
# -------------------------------
# Make sure the requirement is met or fail.
@@ -171,7 +203,6 @@ dtf_prereq ()
pkg)
__dtf_prereq_pkg "$@"
;;
-
*)
dtf_fail "dtf_prereq: action '$_d_requirement' not implemented"
;;