aboutsummaryrefslogtreecommitdiff
path: root/testcases/lib
diff options
context:
space:
mode:
authorPetr Vorel <pvorel@suse.cz>2018-07-24 16:45:39 +0200
committerPetr Vorel <pvorel@suse.cz>2018-07-24 17:00:37 +0200
commitdba1d50cb3e2ba7a85f1398c044e08fdd931bf27 (patch)
treee2b1b3a376fe497f228c0e469a38008a21cb50c0 /testcases/lib
parent0567a8958a44e666736753486c6c0258c5d8b731 (diff)
tst_test.sh: Add test cmd helper tst_check_cmds()
+ tst_cmd_available() tst_check_cmds() is meant to be a check just for a particular test. Works like tst_test_cmd(), but instead of tst_brk() calls tst_res(). tst_test_cmds() helper can handle cases when command shell builtin is not available (e.g. Busybox). Signed-off-by: Petr Vorel <pvorel@suse.cz> Acked-by: Cyril Hrubis <chrubis@suse.cz>
Diffstat (limited to 'testcases/lib')
-rw-r--r--testcases/lib/tst_test.sh30
1 files changed, 28 insertions, 2 deletions
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 6214fd851..a6787ccdb 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -246,14 +246,40 @@ tst_mkfs()
ROD_SILENT mkfs.$fs_type $fs_opts $device
}
+tst_cmd_available()
+{
+ if type command > /dev/null 2>&1; then
+ command -v $1 > /dev/null 2>&1 || return 1
+ else
+ which $1 > /dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ return 0
+ elif [ $? -eq 127 ]; then
+ tst_brk TCONF "missing which command"
+ else
+ return 1
+ fi
+ fi
+}
+
tst_test_cmds()
{
local cmd
for cmd in $*; do
- if ! command -v $cmd > /dev/null 2>&1; then
- tst_brk TCONF "'$cmd' not found"
+ tst_cmd_available $cmd || tst_brk TCONF "'$cmd' not found"
+ done
+}
+
+tst_check_cmds()
+{
+ local cmd
+ for cmd; do
+ if ! tst_cmd_available $cmd; then
+ tst_res TCONF "'$cmd' not found"
+ return 1
fi
done
+ return 0
}
tst_is_int()