You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.6 KiB
69 lines
1.6 KiB
#!/usr/bin/env bash
|
|
|
|
# CONSTANTS
|
|
|
|
TEST_COUNT=0
|
|
SUCCESS_COUNT=0
|
|
# functions
|
|
|
|
function assert {
|
|
((TEST_COUNT++))
|
|
if ./test/stub/scenario.bash "$1" >/dev/null; then
|
|
((SUCCESS_COUNT++))
|
|
else
|
|
(echo "error in: $1" && exit 1)
|
|
fi
|
|
|
|
}
|
|
|
|
function strip_ansi {
|
|
echo "$1" | sed -E 's/\x1b\[[0-9;]*[a-zA-Z]//g'
|
|
}
|
|
|
|
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[@]}"
|
|
error_start_above=false
|
|
regex="║[[:blank:]]+([A-Z|_]+)"
|
|
for i in "${stderr[@]}"; do
|
|
line=$(strip_ansi "$i")
|
|
first="${line:1:1}"
|
|
[[ $first == ╔ ]] && error_start_above=true && continue
|
|
if [[ "$error_start_above" == true ]]; then
|
|
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 -uo pipefail
|
|
|
|
assert success
|
|
fail_type subshell_term SUBSHELL_TERM
|
|
fail_type unbound_variable UNBOUND_VARIABLE
|
|
fail_type false FALSE
|
|
fail_type return RETURN
|
|
fail_type command_not_found COMMAND_NOT_FOUND
|
|
fail_type exit EXIT
|
|
fail_type source_not_found SOURCE_NOT_FOUND
|
|
fail_type file_not_found FILE_NOT_FOUND
|
|
fail_type subshell_source_not_found SUBSHELL_SOURCE_NOT_FOUND
|
|
fail_type subshell_error SUBSHELL_ERROR
|
|
|
|
failed=$((TEST_COUNT - SUCCESS_COUNT))
|
|
|
|
if [[ $failed -gt 0 ]]; then
|
|
ratio=$((100 * SUCCESS_COUNT / TEST_COUNT))
|
|
echo "${ratio}% passed, $SUCCESS_COUNT succeeded, $failed failed!"
|
|
exit 1
|
|
else
|
|
echo 100% passed!
|
|
fi
|