From c2e2f698aa666e3ead64aecfa4d12d965798a6f3 Mon Sep 17 00:00:00 2001 From: Chase Qi Date: Thu, 27 Oct 2016 10:27:43 +0800 Subject: v2: sh-test-lib: add run_test_case function When shell argument "-e" set and "$?" is non-zero, test script will exit immediately. check_return and exit_on_fail would not work. run_test_case should be used instead. run_test_case runs test command within if block and able to give pass/fail respectively. "skip_list" is supported as an optional parameter. It skip the following tests and exit when skip_list isn't empty. Change-Id: I0f4040f37b6d9daa0558bac0d6bf87ba1c3bd904 Signed-off-by: Chase Qi --- automated/lib/sh-test-lib | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'automated/lib') diff --git a/automated/lib/sh-test-lib b/automated/lib/sh-test-lib index 11873cd..4894875 100755 --- a/automated/lib/sh-test-lib +++ b/automated/lib/sh-test-lib @@ -70,6 +70,30 @@ check_return() { fi } +# When shell argument "-e" set in test script, check_return and exit_on_fail +# would NOT work. run_test_case should be used instead. +run_test_case() { + [ "$#" -lt 2 ] && error_msg "Usage: run_test_case [skip_list]" + local test_command="$1" + local test_case_id="$2" + local skip_list="$3" + + if eval "${test_command}"; then + echo "${test_case_id} pass" | tee -a "${RESULT_FILE}" + else + echo "${test_case_id} fail" | tee -a "${RESULT_FILE}" + # When skip_list isn't empty, skip the tests and exit. + if [ -n "${skip_list}" ]; then + for i in ${skip_list}; do + echo "$i skip" | tee -a "${RESULT_FILE}" + done + exit 0 + fi + fi + + return 0 +} + report_pass() { [ "$#" -ne 1 ] && error_msg "Usage: report_pass test" local test="$1" -- cgit v1.2.3