1# Compares two strings and prints out an error message if they are not equal 2StrEq() { 3 if [ "$1" != "$2" ]; then 4 echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} Mismatched strings" >&2 5 echo " Expected: $2" >&2 6 echo " Got: $1" >&2 7 exit 1 8 fi 9} 10 11TESTS=() 12 13# Runs tests and emits output specified by the Test Anything Protocol 14# https://testanything.org/ 15TestAnythingMain() { 16 set -o nounset 17 set -o errexit 18 set -o pipefail 19 20 echo "TAP version 13" 21 echo "1..${#TESTS[@]}" 22 23 local i 24 for ((i=0; i <${#TESTS[@]}; ++i)); do 25 local t="${TESTS[i]}" 26 local tap_i=$((i + 1)) 27 if ! "$t"; then 28 printf "not " 29 fi 30 printf "ok %d - %s\n" "$tap_i" "$t" 31 done 32} 33