[[ ${TESTS_COMMON_SOURCED:-} -eq 1 ]] && return || readonly TESTS_COMMON_SOURCED=1 declare -a cnt cnt=(0 0) function inc_testno { cnt[0]=$((cnt[0] + 1)); } function inc_errors { cnt[1]=$((cnt[1] + 1)); } function test_name { echo "test_${cnt[0]}"; } ts=$(date +%s%N) function print_info { tt=$((($(date +%s%N) - $ts)/1000000)) echo "----------------------------------------------------------------------" echo -n "Ran ${cnt[0]} tests in " echo -n $tt | awk '{ printf("%d.%03d", int($1/1000), int($1%1000)); }' echo -e "s\n" if (( cnt[1] == 0 )); then echo OK exit 0 else echo "FAILED (failures=${cnt[1]})" exit ${cnt[1]} fi } function test_result { inc_testno echo -n "$(test_name): " if [[ $1 = "0" ]]; then echo -n "OK " else echo -n "FAIL" inc_errors fi echo " ${@:2}" }