_tap.sh (1119B)
1 # TAP helpers, source with `. test/_tap.sh` 2 # Mirrors test/_tap.c: tap_begin, tap, tap_check, tap_plan. 3 4 TAP_NO=0 5 TAP_FAIL=0 6 7 tap_begin() { 8 TAP_NO=0 9 TAP_FAIL=0 10 printf 'TAP version 13\n' 11 printf '# %s\n' "$1" 12 } 13 14 tap() { 15 # tap <ok> <desc> <diag> 16 TAP_NO=$((TAP_NO + 1)) 17 if [ "$1" = 1 ]; then 18 printf 'ok %s - %s\n' "${TAP_NO}" "$2" 19 return 0 20 fi 21 TAP_FAIL=$((TAP_FAIL + 1)) 22 printf 'not ok %s - %s\n' "${TAP_NO}" "$2" 23 if [ -n "${3:-}" ]; then 24 printf '# %s\n' "$3" 25 fi 26 return 0 27 } 28 29 tap_check() { 30 # tap_check <rc> <desc> <diag> 31 if [ "$1" = 0 ]; then 32 tap 1 "$2" "" 33 else 34 tap 0 "$2" "$3" 35 fi 36 } 37 38 tap_plan() { 39 printf '1..%s\n' "${TAP_NO}" 40 if [ "${TAP_FAIL}" -gt 0 ]; then 41 printf '# %s of %s assertions failed\n' "${TAP_FAIL}" "${TAP_NO}" 42 return 1 43 fi 44 return 0 45 } 46 47 # Path to the built sfinx binary, building it once on demand 48 ensure_bin() { 49 _root=$1 50 _target=$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m) 51 _bin="${_root}/build/${_target}/sfinx" 52 if [ ! -x "${_bin}" ]; then 53 (cd "${_root}" && make) >/dev/null 2>&1 || true 54 fi 55 printf '%s\n' "${_bin}" 56 }