diff --git a/test/miaou-bash.test.bash b/test/miaou-bash.test.bash index 8581df7..c0cad8b 100755 --- a/test/miaou-bash.test.bash +++ b/test/miaou-bash.test.bash @@ -1,9 +1,19 @@ #!/usr/bin/env bash +# CONSTANTS + +TEST_COUNT=0 +SUCCESS_COUNT=0 # functions function assert { - ./test/stub/scenario.bash "$1" >/dev/null || (echo "error in: $1" && exit 1) + ((TEST_COUNT++)) + if ./test/stub/scenario.bash "$1" >/dev/null; then + ((SUCCESS_COUNT++)) + else + (echo "error in: $1" && exit 1) + fi + } function strip_ansi { @@ -11,6 +21,7 @@ function strip_ansi { } function fail_type { + ((TEST_COUNT++)) local i line first error_start_above regex mapfile -t stderr <<<"$(./test/stub/scenario.bash "$1" 2>&1 >/dev/null)" # echo "stderr countains ${#stderr[@]}" @@ -21,16 +32,31 @@ function fail_type { first="${line:1:1}" [[ $first == ╔ ]] && error_start_above=true && continue if [[ "$error_start_above" == true ]]; then - [[ $line =~ $regex ]] && [[ ${BASH_REMATCH[1]} == "$2" ]] && return 0 - echo "error in: $1" && return 1 + if [[ $line =~ $regex ]] && [[ ${BASH_REMATCH[1]} == "$2" ]]; then + ((SUCCESS_COUNT++)) + return 0 + else + break + fi fi done + echo "error in: $1" && return 1 } # main -set -euo pipefail +set -uo pipefail + assert success fail_type subshell_term SUBSHELL_TERM fail_type unbound_variable UNBOUND_VARIABLE fail_type false FALSE -echo 100% passed! +fail_type return RETURN + +failed=$((TEST_COUNT - SUCCESS_COUNT)) +if [[ $failed -gt 0 ]]; then + ratio=$((100 * SUCCESS_COUNT / TEST_COUNT)) + echo "${ratio}% passed, $failed test have failed!" + exit 1 +else + echo 100% passed! +fi